Last active
July 20, 2020 07:13
-
-
Save utamori/ef4cc71090b608d3c93433c47f1b9642 to your computer and use it in GitHub Desktop.
CloudRunのサンプル
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ビルドアーティファクトを作成するために、公式のGolangイメージを使用する | |
| # これは Debian をベースにしており、GOPATH を/goに設定します。 | |
| # https://hub.docker.com/_/golang | |
| FROM golang:1.13 as builder | |
| # appディレクトリを作成して移動します。 | |
| WORKDIR /app | |
| # go modulesを使用してアプリケーションの依存関係を取得します。 | |
| # コンテナのビルドでダウンロードした依存関係を再利用できるようにします。 | |
| COPY go.* ./ | |
| RUN go mod download | |
| # ローカルコードをコンテナイメージにコピーします。 | |
| COPY . ./ | |
| # バイナリをビルドします | |
| # -mod=readonlyはコンテナビルドでの go.mod と go.sum の不変性を保証します。 | |
| RUN CGO_ENABLED=0 GOOS=linux go build -mod=readonly -v -o server | |
| # 無駄のないプロダクション用コンテナには、alpineの公式画像を使用してください。 | |
| # https://hub.docker.com/_/alpine | |
| # https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds | |
| FROM alpine:3 | |
| RUN apk add --no-cache ca-certificates | |
| # builder段階からproductionイメージにバイナリをコピーします。 | |
| COPY --from=builder /app/server /server | |
| # コンテナ起動時にWebサービスを実行します。 | |
| CMD ["/server"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment