Created
March 1, 2024 05:32
-
-
Save s-aska/c09091ad2150c8404098cd7b8ff5bb27 to your computer and use it in GitHub Desktop.
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
steps: | |
# | |
# Tools cache | |
# | |
# Pull the cloud-sdk image cache | |
- name: "asia.gcr.io/google.com/cloudsdktool/cloud-sdk" | |
entrypoint: gcloud | |
args: | |
- "version" | |
id: "cloud-sdk:cache" | |
waitFor: ["-"] | |
# | |
# Backend | |
# | |
# Pull the container image for worker | |
- name: "gcr.io/cloud-builders/docker" | |
entrypoint: "bash" | |
args: | |
- "-c" | |
- "docker pull asia-northeast1-docker.pkg.dev/$PROJECT_ID/backend/worker-builder:latest || exit 0" | |
id: "worker:pull" | |
waitFor: ["-"] | |
# Build the container image for id/api builder | |
- name: "gcr.io/cloud-builders/docker" | |
args: | |
- "build" | |
- "--cache-from" | |
- "asia-northeast1-docker.pkg.dev/$PROJECT_ID/backend/worker-builder:latest" | |
- "-t" | |
- "asia-northeast1-docker.pkg.dev/$PROJECT_ID/backend/worker-builder:latest" | |
- "-f" | |
- "run/worker/Dockerfile" | |
- "--target" | |
- "builder" | |
- "." | |
id: "worker:build-builder" | |
waitFor: ["worker:pull"] | |
# Build the container image for id/api | |
- name: "gcr.io/cloud-builders/docker" | |
args: | |
- "build" | |
- "--cache-from" | |
- "asia-northeast1-docker.pkg.dev/$PROJECT_ID/backend/worker-builder:latest" | |
- "-t" | |
- "asia-northeast1-docker.pkg.dev/$PROJECT_ID/backend/worker:$SHORT_SHA" | |
- "-f" | |
- "run/worker/Dockerfile" | |
- "." | |
id: "worker:build" | |
waitFor: ["worker:build-builder"] | |
# Push the container image to Artifact Registry for id/api | |
- name: "gcr.io/cloud-builders/docker" | |
args: | |
- "push" | |
- "asia-northeast1-docker.pkg.dev/$PROJECT_ID/backend/worker:$SHORT_SHA" | |
id: "worker:push" | |
waitFor: ["worker:build"] | |
# Deploy backend/id/api | |
- name: "asia.gcr.io/google.com/cloudsdktool/cloud-sdk" | |
entrypoint: gcloud | |
args: | |
- "run" | |
- "deploy" | |
- "mogily-worker" | |
- "--image" | |
- "$_ARTIFACT_REGISTRY_BACKEND/worker:$SHORT_SHA" | |
- "--region" | |
- "asia-northeast1" | |
- "--memory" | |
- "650M" | |
- "--allow-unauthenticated" | |
- "--min-instances" | |
- "1" | |
- "--max-instances" | |
- "1" | |
- "--no-cpu-throttling" | |
- "--set-env-vars" | |
- "GCP_PROJECT=$PROJECT_ID" | |
- "--set-env-vars" | |
- "CMS_HOST=${_CMS_HOST}" | |
id: "worker:deploy" | |
waitFor: ["cloud-sdk:cache", "worker:push"] | |
images: | |
- "$_ARTIFACT_REGISTRY_BACKEND/worker-builder:latest" | |
- "$_ARTIFACT_REGISTRY_BACKEND/worker:$SHORT_SHA" | |
substitutions: | |
_ARTIFACT_REGISTRY_BACKEND: "asia-northeast1-docker.pkg.dev/${PROJECT_ID}/backend" | |
options: | |
dynamic_substitutions: true | |
machineType: E2_HIGHCPU_8 | |
timeout: 3600s |
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
FROM golang:1.20-alpine as builder | |
RUN apk update && apk add --repository http://dl-cdn.alpinelinux.org/alpine/v3.4/main --no-cache ca-certificates gcc libc-dev | |
WORKDIR /app | |
COPY go.* ./ | |
RUN go mod download | |
COPY run/ ./run | |
COPY env/ ./env | |
COPY pkg/ ./pkg | |
COPY firestore/ ./firestore | |
RUN CGO_ENABLED=0 GOOS=linux go build -mod=readonly -o server ./run/worker/cmd | |
FROM alpine | |
RUN apk update | |
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ | |
COPY --from=builder /app/server /server | |
COPY --from=builder /app/run /run | |
CMD [ "/server" ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment