2022-05-17 08:09:50 +03:00
|
|
|
# =============================================================================
|
|
|
|
# Multi-stage Dockerfile Example
|
|
|
|
# =============================================================================
|
|
|
|
# This is a simple Dockerfile that will build an image of scratch-base image.
|
|
|
|
# Usage:
|
|
|
|
# docker build -t simple:local . && docker run --rm simple:local
|
|
|
|
# =============================================================================
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# Build Stage
|
|
|
|
# -----------------------------------------------------------------------------
|
2023-12-13 23:41:33 +03:00
|
|
|
FROM golang:alpine3.18 AS build
|
2022-05-17 08:09:50 +03:00
|
|
|
|
|
|
|
# Important:
|
|
|
|
# Because this is a CGO enabled package, you are required to set it as 1.
|
|
|
|
ENV CGO_ENABLED=1
|
|
|
|
|
|
|
|
RUN apk add --no-cache \
|
|
|
|
# Important: required for go-sqlite3
|
|
|
|
gcc \
|
|
|
|
# Required for Alpine
|
|
|
|
musl-dev
|
|
|
|
|
|
|
|
WORKDIR /workspace
|
|
|
|
|
|
|
|
COPY . /workspace/
|
|
|
|
|
|
|
|
RUN \
|
2023-12-13 23:40:44 +03:00
|
|
|
cd _example/simple && \
|
2022-05-17 08:09:50 +03:00
|
|
|
go mod init github.com/mattn/sample && \
|
2023-12-13 23:40:44 +03:00
|
|
|
go mod edit -replace=github.com/mattn/go-sqlite3=../.. && \
|
2022-05-17 08:09:50 +03:00
|
|
|
go mod tidy && \
|
2022-05-18 05:21:26 +03:00
|
|
|
go install -ldflags='-s -w -extldflags "-static"' ./simple.go
|
2022-05-17 08:09:50 +03:00
|
|
|
|
|
|
|
RUN \
|
|
|
|
# Smoke test
|
|
|
|
set -o pipefail; \
|
2022-09-04 11:28:49 +03:00
|
|
|
/go/bin/simple | grep 99\ こんにちは世界099
|
2022-05-17 08:09:50 +03:00
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# Main Stage
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
FROM scratch
|
|
|
|
|
|
|
|
COPY --from=build /go/bin/simple /usr/local/bin/simple
|
|
|
|
|
|
|
|
ENTRYPOINT [ "/usr/local/bin/simple" ]
|