Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Always build all binaries and migrations, simplify deployment #419

Merged
merged 5 commits into from
Aug 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 2 additions & 16 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,6 @@
# Test binary, built with `go test -c`
*.test

# Local built binaries, built with `go build .` in the folder.
cmd/add-realm/add-realm
cmd/add-users/add-users
cmd/adminapi/adminapi
cmd/apiserver/apiserver
cmd/cleanup/cleanup
cmd/e2e-runner/e2e-runner
cmd/get-certificate/get-certificate
cmd/get-code/get-code
cmd/get-token/get-token
cmd/migrate/migrate
cmd/server/server
tools/gen-secret/gen-secret
tools/seed/seed

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

Expand All @@ -35,6 +20,7 @@ tools/seed/seed
*.tfvars
terraform/state.tf

# Testing things
# Local things
bin/
local/
.env
220 changes: 204 additions & 16 deletions builders/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,212 @@
#
# Builds a container image.
#
options:
# N1_HIGHCPU_32 builds faster, but takes much longer to provision.
machineType: 'N1_HIGHCPU_8'
env:
- 'GOPATH=/go'
- 'GO111MODULE=on'
- 'GOPROXY=https://proxy.golang.org,direct'
- 'CGO_ENABLED=0'
- 'GOOS=linux'
- 'GOARCH=amd64'
volumes:
- name: 'go-modules'
path: '/go/pkg'

substitutions:
_SERVICE:
_REPO: 'github.com/google/exposure-notifications-verification-server'
_TAG:

steps:
- id: 'build'
name: 'registry.hub.docker.com/library/docker:18'
args: [
'build',
'--tag', 'gcr.io/${PROJECT_ID}/github.com/google/exposure-notifications-verification-server/cmd/${_SERVICE}:${_TAG}',
'--build-arg', 'SERVICE=${_SERVICE}',
'.',
]

- id: 'publish'
name: 'registry.hub.docker.com/library/docker:18'
args: [
'push',
'gcr.io/${PROJECT_ID}/github.com/google/exposure-notifications-verification-server/cmd/${_SERVICE}:${_TAG}',
]
- id: 'restore-cache'
name: 'us-docker.pkg.dev/vargolabs/gcs-cacher/gcs-cacher:0.1'
args:
- '-bucket=${PROJECT_ID}-cloudbuild-cache'
- '-restore=go-{{ hashGlob "go.mod" }}'
- '-restore=go-'
- '-dir=/go/pkg'
- '-allow-failure'

- id: 'download-modules'
name: 'golang:1.15'
args:
- 'go'
- 'mod'
- 'download'
- '-x'
waitFor:
- 'restore-cache'

- id: 'save-cache'
name: 'us-docker.pkg.dev/vargolabs/gcs-cacher/gcs-cacher:0.1'
args:
- '-bucket=${PROJECT_ID}-cloudbuild-cache'
- '-cache=go-{{ hashGlob "go.mod" }}'
- '-dir=/go/pkg'
waitFor:
- 'download-modules'

#
# adminapi
#
- id: 'build-adminapi'
name: 'golang:1.15'
args:
- 'go'
- 'build'
- '-trimpath'
- '-ldflags=-s -w -X=${_REPO}/pkg/buildinfo.BuildID=${BUILD_ID} -X=${_REPO}/pkg/buildinfo.BuildTag=${_TAG} -extldflags=-static'
- '-o=./bin/adminapi'
- './cmd/adminapi'
waitFor:
- 'download-modules'

- id: 'dockerize-adminapi'
name: 'docker:19'
args:
- 'build'
- '--file=builders/service.dockerfile'
- '--tag=gcr.io/${PROJECT_ID}/${_REPO}/adminapi:${_TAG}'
- '--build-arg=SERVICE=adminapi'
- '.'
waitFor:
- 'build-adminapi'

#
# apiserver
#
- id: 'build-apiserver'
name: 'golang:1.15'
args:
- 'go'
- 'build'
- '-trimpath'
- '-ldflags=-s -w -X=${_REPO}/pkg/buildinfo.BuildID=${BUILD_ID} -X=${_REPO}/pkg/buildinfo.BuildTag=${_TAG} -extldflags=-static'
- '-o=./bin/apiserver'
- './cmd/apiserver'
waitFor:
- 'download-modules'

- id: 'dockerize-apiserver'
name: 'docker:19'
args:
- 'build'
- '--file=builders/service.dockerfile'
- '--tag=gcr.io/${PROJECT_ID}/${_REPO}/apiserver:${_TAG}'
- '--build-arg=SERVICE=apiserver'
- '.'
waitFor:
- 'build-apiserver'

#
# cleanup
#
- id: 'build-cleanup'
name: 'golang:1.15'
args:
- 'go'
- 'build'
- '-trimpath'
- '-ldflags=-s -w -X=${_REPO}/pkg/buildinfo.BuildID=${BUILD_ID} -X=${_REPO}/pkg/buildinfo.BuildTag=${_TAG} -extldflags=-static'
- '-o=./bin/cleanup'
- './cmd/cleanup'
waitFor:
- 'download-modules'

- id: 'dockerize-cleanup'
name: 'docker:19'
args:
- 'build'
- '--file=builders/service.dockerfile'
- '--tag=gcr.io/${PROJECT_ID}/${_REPO}/cleanup:${_TAG}'
- '--build-arg=SERVICE=cleanup'
- '.'
waitFor:
- 'build-cleanup'

#
# e2e-runner
#
- id: 'build-e2e-runner'
name: 'golang:1.15'
args:
- 'go'
- 'build'
- '-trimpath'
- '-ldflags=-s -w -X=${_REPO}/pkg/buildinfo.BuildID=${BUILD_ID} -X=${_REPO}/pkg/buildinfo.BuildTag=${_TAG} -extldflags=-static'
- '-o=./bin/e2e-runner'
- './cmd/e2e-runner'
waitFor:
- 'download-modules'

- id: 'dockerize-e2e-runner'
name: 'docker:19'
args:
- 'build'
- '--file=builders/service.dockerfile'
- '--tag=gcr.io/${PROJECT_ID}/${_REPO}/e2e-runner:${_TAG}'
- '--build-arg=SERVICE=e2e-runner'
- '.'
waitFor:
- 'build-e2e-runner'

#
# migrate
#
- id: 'build-migrate'
name: 'golang:1.15'
args:
- 'go'
- 'build'
- '-trimpath'
- '-ldflags=-s -w -X=${_REPO}/pkg/buildinfo.BuildID=${BUILD_ID} -X=${_REPO}/pkg/buildinfo.BuildTag=${_TAG} -extldflags=-static'
- '-o=./bin/migrate'
- './cmd/migrate'
waitFor:
- 'download-modules'

- id: 'dockerize-migrate'
name: 'docker:19'
args:
- 'build'
- '--file=builders/migrate.dockerfile'
- '--tag=gcr.io/${PROJECT_ID}/${_REPO}/migrate:${_TAG}'
- '--build-arg=SERVICE=migrate'
- '.'
waitFor:
- 'build-migrate'

#
# server
#
- id: 'build-server'
name: 'golang:1.15'
args:
- 'go'
- 'build'
- '-trimpath'
- '-ldflags=-s -w -X=${_REPO}/pkg/buildinfo.BuildID=${BUILD_ID} -X=${_REPO}/pkg/buildinfo.BuildTag=${_TAG} -extldflags=-static'
- '-o=./bin/server'
- './cmd/server'
waitFor:
- 'download-modules'

- id: 'dockerize-server'
name: 'docker:19'
args:
- 'build'
- '--file=builders/service.dockerfile'
- '--tag=gcr.io/${PROJECT_ID}/${_REPO}/server:${_TAG}'
- '--build-arg=SERVICE=server'
- '.'
waitFor:
- 'build-server'

images:
- 'gcr.io/${PROJECT_ID}/${_REPO}/adminapi:${_TAG}'
- 'gcr.io/${PROJECT_ID}/${_REPO}/apiserver:${_TAG}'
- 'gcr.io/${PROJECT_ID}/${_REPO}/cleanup:${_TAG}'
- 'gcr.io/${PROJECT_ID}/${_REPO}/migrate:${_TAG}'
- 'gcr.io/${PROJECT_ID}/${_REPO}/server:${_TAG}'
42 changes: 42 additions & 0 deletions builders/cloud-sql-exec
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash

# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -eEuo pipefail

DB_PORT=${DB_PORT:-5432}

if [ -z "${DB_CONN:-}" ]; then
echo "missing DB_CONN"
exit 1
fi

function cleanup {
echo "==> Terminating proxy (PID ${CLOUD_SQL_PID})"
if [ -n "${CLOUD_SQL_PID:-}" ]; then
kill -SIGINT "${CLOUD_SQL_PID}"
fi
}

echo "==> Staring Cloud SQL Proxy"
/cloud_sql_proxy -instances=${DB_CONN}=tcp:${DB_PORT} &
CLOUD_SQL_PID=$!
trap cleanup EXIT

echo "==> Waiting for proxy to be ready"
sleep 5

echo "==> Running command ($@)"
$@
Loading