diff options
author | KEINOS <github@keinos.com> | 2022-05-17 14:09:50 +0900 |
---|---|---|
committer | mattn <mattn.jp@gmail.com> | 2022-05-18 11:53:00 +0900 |
commit | c1223028624d0ce67e5da5ed5a48d68cdc8d72ee (patch) | |
tree | a889c8b75df9c0d8991138f99b965d7e6c67346b /_example | |
parent | Update amalgamation code (diff) | |
download | golite-c1223028624d0ce67e5da5ed5a48d68cdc8d72ee.tar.gz golite-c1223028624d0ce67e5da5ed5a48d68cdc8d72ee.tar.xz |
feat: simple example of Dockerfile w/ multi-stage build
Diffstat (limited to '_example')
-rw-r--r-- | _example/simple/Dockerfile | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/_example/simple/Dockerfile b/_example/simple/Dockerfile new file mode 100644 index 0000000..2a5b472 --- /dev/null +++ b/_example/simple/Dockerfile @@ -0,0 +1,45 @@ +# ============================================================================= +# 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 +# ----------------------------------------------------------------------------- +FROM golang:alpine AS build + +# 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 \ + go mod init github.com/mattn/sample && \ + go mod tidy && \ + go install -ldflags="-s -w -extldflags \"-static\"" ./simple.go + +RUN \ + # Smoke test + set -o pipefail; \ + /go/bin/simple | grep 99\ こんにちわ世界099 + +# ----------------------------------------------------------------------------- +# Main Stage +# ----------------------------------------------------------------------------- +FROM scratch + +COPY --from=build /go/bin/simple /usr/local/bin/simple + +ENTRYPOINT [ "/usr/local/bin/simple" ] |