From 7a85977ed21e2f071d59e90e4e9db439f0f9776e Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Thu, 10 Aug 2023 15:27:20 -0700 Subject: [PATCH 1/2] CI: Add cloudbuild deploy script --- Dockerfile.dbbrowser | 14 ++++++++++++++ cmd/gopogh-server/main.go | 6 ------ deploy/cloudrun/deploy.sh | 18 ++++++++++++++++++ 3 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 Dockerfile.dbbrowser create mode 100755 deploy/cloudrun/deploy.sh diff --git a/Dockerfile.dbbrowser b/Dockerfile.dbbrowser new file mode 100644 index 0000000..a754ac1 --- /dev/null +++ b/Dockerfile.dbbrowser @@ -0,0 +1,14 @@ +FROM golang:1.21 AS builder +WORKDIR /app +COPY go.mod go.sum ./ +RUN go mod download +COPY cmd/dbbrowser/ ./ +COPY pkg ./pkg +RUN CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -o /dbbrowser + +FROM alpine:3 +WORKDIR / +RUN apk add --no-cache ca-certificates +COPY --from=builder /dbbrowser /dbbrowser +EXPOSE 8080 +CMD ["/dbbrowser", "-use_cloudsql", "-use_iam_auth"] diff --git a/cmd/gopogh-server/main.go b/cmd/gopogh-server/main.go index e572ea2..f87f649 100644 --- a/cmd/gopogh-server/main.go +++ b/cmd/gopogh-server/main.go @@ -16,12 +16,6 @@ var useIAMAuth = flag.Bool("use_iam_auth", false, "whether to use IAM to authent func main() { flag.Parse() - if *dbPath == "" { - log.Fatalf("The db_path flag is required") - } - if *dbHost == "" { - log.Fatalf("The db_host flag is required") - } flagValues := db.FlagValues{ Backend: "postgres", Host: *dbHost, diff --git a/deploy/cloudrun/deploy.sh b/deploy/cloudrun/deploy.sh new file mode 100755 index 0000000..ea18a7d --- /dev/null +++ b/deploy/cloudrun/deploy.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +set -eux + +export IMAGE=gcr.io/k8s-minikube/dbbrowser + +docker buildx build --platform linux/amd64 -t "${IMAGE}" -f Dockerfile.dbbrowser . + +docker push "${IMAGE}" || exit 2 + +gcloud run deploy dbbrowser \ + --project k8s-minikube \ + --image "${IMAGE}" \ + --set-env-vars="DB_HOST=${DB_HOST},DB_PATH=${DB_PATH}" \ + --allow-unauthenticated \ + --region us-central1 \ + --memory 2Gi \ + --platform managed From 407676bec7e5797f9f3c8eee956fd34fcae0bb63 Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Fri, 11 Aug 2023 12:07:59 -0700 Subject: [PATCH 2/2] renamed --- Dockerfile.dbbrowser | 14 -------------- Dockerfile.server | 14 ++++++++++++++ deploy/cloudrun/deploy.sh | 8 ++++---- 3 files changed, 18 insertions(+), 18 deletions(-) delete mode 100644 Dockerfile.dbbrowser create mode 100644 Dockerfile.server diff --git a/Dockerfile.dbbrowser b/Dockerfile.dbbrowser deleted file mode 100644 index a754ac1..0000000 --- a/Dockerfile.dbbrowser +++ /dev/null @@ -1,14 +0,0 @@ -FROM golang:1.21 AS builder -WORKDIR /app -COPY go.mod go.sum ./ -RUN go mod download -COPY cmd/dbbrowser/ ./ -COPY pkg ./pkg -RUN CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -o /dbbrowser - -FROM alpine:3 -WORKDIR / -RUN apk add --no-cache ca-certificates -COPY --from=builder /dbbrowser /dbbrowser -EXPOSE 8080 -CMD ["/dbbrowser", "-use_cloudsql", "-use_iam_auth"] diff --git a/Dockerfile.server b/Dockerfile.server new file mode 100644 index 0000000..713213b --- /dev/null +++ b/Dockerfile.server @@ -0,0 +1,14 @@ +FROM golang:1.21 AS builder +WORKDIR /app +COPY go.mod go.sum ./ +RUN go mod download +COPY cmd/gopogh-server/main.go ./ +COPY pkg ./pkg +RUN CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -o /gopogh-server + +FROM alpine:3 +WORKDIR / +RUN apk add --no-cache ca-certificates +COPY --from=builder /gopogh-server /gopogh-server +EXPOSE 8080 +CMD ["/gopogh-server", "-use_cloudsql", "-use_iam_auth"] diff --git a/deploy/cloudrun/deploy.sh b/deploy/cloudrun/deploy.sh index ea18a7d..e650639 100755 --- a/deploy/cloudrun/deploy.sh +++ b/deploy/cloudrun/deploy.sh @@ -2,17 +2,17 @@ set -eux -export IMAGE=gcr.io/k8s-minikube/dbbrowser +export IMAGE=gcr.io/k8s-minikube/gopogh-server -docker buildx build --platform linux/amd64 -t "${IMAGE}" -f Dockerfile.dbbrowser . +docker buildx build --platform linux/amd64 -t "${IMAGE}" -f Dockerfile.server . docker push "${IMAGE}" || exit 2 -gcloud run deploy dbbrowser \ +gcloud run deploy gopogh-server \ --project k8s-minikube \ --image "${IMAGE}" \ --set-env-vars="DB_HOST=${DB_HOST},DB_PATH=${DB_PATH}" \ --allow-unauthenticated \ --region us-central1 \ - --memory 2Gi \ + --memory 4Gi \ --platform managed