Skip to content

Commit 273c24f

Browse files
authored
feat: add Dockerfiles and build config with vendoring (GoogleCloudPlatform#3)
1 parent ca116ec commit 273c24f

9 files changed

+339
-1
lines changed

.build/alpine.yaml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
steps:
16+
- name: 'gcr.io/cloud-builders/docker'
17+
args:
18+
- 'build'
19+
- '--tag=gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}-alpine'
20+
- '--tag=us.gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}-alpine'
21+
- '--tag=eu.gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}-alpine'
22+
- '--tag=asia.gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}-alpine'
23+
- '-f=Dockerfile.alpine'
24+
- '.'
25+
images:
26+
- 'gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}-alpine'
27+
- 'us.gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}-alpine'
28+
- 'eu.gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}-alpine'
29+
- 'asia.gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}-alpine'

.build/buster.yaml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
steps:
16+
- name: 'gcr.io/cloud-builders/docker'
17+
args:
18+
- 'build'
19+
- '--tag=gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}-buster'
20+
- '--tag=us.gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}-buster'
21+
- '--tag=eu.gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}-buster'
22+
- '--tag=asia.gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}-buster'
23+
- '-f=Dockerfile.buster'
24+
- '.'
25+
images:
26+
- 'gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}-buster'
27+
- 'us.gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}-buster'
28+
- 'eu.gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}-buster'
29+
- 'asia.gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}-buster'

.build/default.yaml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
steps:
16+
- name: 'gcr.io/cloud-builders/docker'
17+
args:
18+
- 'build'
19+
- '--tag=gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}'
20+
- '--tag=us.gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}'
21+
- '--tag=eu.gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}'
22+
- '--tag=asia.gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}'
23+
- '.'
24+
images:
25+
- 'gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}'
26+
- 'us.gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}'
27+
- 'eu.gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}'
28+
- 'asia.gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}'

.build/gcs_upload.yaml

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
timeout: 900s
16+
options:
17+
env:
18+
- "CGO_ENABLED=0"
19+
20+
steps:
21+
- id: linux.amd64
22+
name: "golang:1.18"
23+
env:
24+
- "GOOS=linux"
25+
- "GOARCH=amd64"
26+
entrypoint: "bash"
27+
args:
28+
- "-c"
29+
- 'go build -ldflags "-X github.com/GoogleCloudPlatform/alloydb-auth-proxy/cmd.metadataString=$$GOOS.$$GOARCH" -o alloydb-auth-proxy.$$GOOS.$$GOARCH'
30+
- id: linux.386
31+
name: "golang:1.18"
32+
env:
33+
- "GOOS=linux"
34+
- "GOARCH=386"
35+
entrypoint: "bash"
36+
args:
37+
- "-c"
38+
- 'go build -ldflags "-X github.com/GoogleCloudPlatform/alloydb-auth-proxy/cmd.metadataString=$$GOOS.$$GOARCH" -o alloydb-auth-proxy.$$GOOS.$$GOARCH'
39+
- id: linux.arm64
40+
name: "golang:1.18"
41+
env:
42+
- "GOOS=linux"
43+
- "GOARCH=arm64"
44+
entrypoint: "bash"
45+
args:
46+
- "-c"
47+
- 'go build -ldflags "-X github.com/GoogleCloudPlatform/alloydb-auth-proxy/cmd.metadataString=$$GOOS.$$GOARCH" -o alloydb-auth-proxy.$$GOOS.$$GOARCH'
48+
- id: linux.arm
49+
name: "golang:1.18"
50+
env:
51+
- "GOOS=linux"
52+
- "GOARCH=arm"
53+
entrypoint: "bash"
54+
args:
55+
- "-c"
56+
- 'go build -ldflags "-X github.com/GoogleCloudPlatform/alloydb-auth-proxy/cmd.metadataString=$$GOOS.$$GOARCH" -o alloydb-auth-proxy.$$GOOS.$$GOARCH'
57+
- id: darwin.amd64
58+
name: "golang:1.18"
59+
env:
60+
- "GOOS=darwin"
61+
- "GOARCH=amd64"
62+
entrypoint: "bash"
63+
args:
64+
- "-c"
65+
- 'go build -ldflags "-X github.com/GoogleCloudPlatform/alloydb-auth-proxy/cmd.metadataString=$$GOOS.$$GOARCH" -o alloydb-auth-proxy.$$GOOS.$$GOARCH'
66+
- id: darwin.arm64
67+
name: "golang:1.18"
68+
env:
69+
- "GOOS=darwin"
70+
- "GOARCH=arm64"
71+
entrypoint: "bash"
72+
args:
73+
- "-c"
74+
- 'go build -ldflags "-X github.com/GoogleCloudPlatform/alloydb-auth-proxy/cmd.metadataString=$$GOOS.$$GOARCH" -o alloydb-auth-proxy.$$GOOS.$$GOARCH'
75+
- id: windows.amd64
76+
name: "golang:1.18"
77+
env:
78+
- "GOOS=windows"
79+
- "GOARCH=amd64"
80+
entrypoint: "bash"
81+
args:
82+
- "-c"
83+
- 'go build -ldflags "-X github.com/GoogleCloudPlatform/alloydb-auth-proxy/cmd.metadataString=$$GOOS.$$GOARCH" -o alloydb-auth-proxy-x64.exe'
84+
- id: windows.386
85+
name: "golang:1.18"
86+
env:
87+
- "GOOS=windows"
88+
- "GOARCH=386"
89+
entrypoint: "bash"
90+
args:
91+
- "-c"
92+
- 'go build -ldflags "-X github.com/GoogleCloudPlatform/alloydb-auth-proxy/cmd.metadataString=$$GOOS.$$GOARCH" -o alloydb-auth-proxy-x86.exe'
93+
artifacts:
94+
objects:
95+
location: "gs://alloydb-auth-proxy/v${_VERSION}/"
96+
paths:
97+
- "alloydb-auth-proxy*"

.build/release_artifacts.sh

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#! /bin/bash
2+
# Copyright 2020 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# This script distributes the artifacts for the AlloyDB auth proxy to their
17+
# different channels.
18+
19+
set -e # exit immediatly if any step fails
20+
21+
PROJ_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/.. >/dev/null 2>&1 && pwd )"
22+
cd $PROJ_ROOT
23+
24+
# get the current version
25+
export VERSION=$(cat cmd/version.txt)
26+
if [ -z "$VERSION" ]; then
27+
echo "error: No version.txt found in $PROJ_ROOT"
28+
exit 1
29+
fi
30+
31+
32+
read -p "This will release new AlloyDB auth proxy artifacts for \"$VERSION\", even if they already exist. Are you sure (y/Y)? " -n 1 -r
33+
echo
34+
if [[ ! $REPLY =~ ^[Yy]$ ]]
35+
then
36+
exit 1
37+
fi
38+
39+
# Build and push the container images
40+
gcloud builds submit --async --config .build/default.yaml --substitutions _VERSION=$VERSION
41+
gcloud builds submit --async --config .build/buster.yaml --substitutions _VERSION=$VERSION
42+
gcloud builds submit --async --config .build/alpine.yaml --substitutions _VERSION=$VERSION
43+
44+
# Build the binarys and upload to GCS
45+
gcloud builds submit --config .build/gcs_upload.yaml --substitutions _VERSION=$VERSION
46+
# cleam up any artifacts.json left by previous builds
47+
gsutil rm -f gs://alloydb-auth-proxy/v$VERSION/*.json 2> /dev/null || true
48+
49+
# Generate sha256 hashes for authentication
50+
echo -e "Add the following table to the release notes on GitHub: \n\n"
51+
echo "| filename | sha256 hash |"
52+
echo "|----------|-------------|"
53+
for f in $(gsutil ls "gs://alloydb-auth-proxy/v$VERSION/alloydb-auth-proxy*"); do
54+
file=$(basename $f)
55+
sha=$(gsutil cat $f | sha256sum --binary | head -c 64)
56+
echo "| [$file](https://storage.googleapis.com/alloydb-auth-proxy/v$VERSION/$file) | $sha |"
57+
done

Dockerfile

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright 2019 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Use the latest stable golang 1.x to compile to a binary
16+
FROM golang:1 as build
17+
18+
WORKDIR /go/src/alloydb-auth-proxy
19+
COPY . .
20+
21+
RUN go get ./...
22+
RUN CGO_ENABLED=0 go build -ldflags "-X main.metadataString=container"
23+
24+
# Final Stage
25+
FROM gcr.io/distroless/static:nonroot
26+
COPY --from=build --chown=nonroot /go/src/alloydb-auth-proxy/alloydb-auth-proxy /alloydb-auth-proxy
27+
# set the uid as an integer for compatibility with runAsNonRoot in Kubernetes
28+
USER 65532

Dockerfile.alpine

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Use the latest stable golang 1.x to compile to a binary
16+
FROM golang:1 as build
17+
18+
WORKDIR /go/src/alloydb-auth-proxy
19+
COPY . .
20+
21+
RUN go get ./...
22+
RUN go build -ldflags "-X main.metadataString=container.alpine"
23+
24+
# Final stage
25+
FROM alpine:3
26+
RUN apk add --no-cache \
27+
ca-certificates \
28+
libc6-compat
29+
# Install fuse and allow enable non-root users to mount
30+
RUN apk add --no-cache fuse && sed -i 's/^#user_allow_other$/user_allow_other/g' /etc/fuse.conf
31+
# Add a non-root user matching the nonroot user from the main container
32+
RUN addgroup -g 65532 -S nonroot && adduser -u 65532 -S nonroot -G nonroot
33+
# Set the uid as an integer for compatibility with runAsNonRoot in Kubernetes
34+
USER 65532
35+
36+
COPY --from=build --chown=nonroot /go/src/alloydb-auth-proxy/alloydb-auth-proxy /alloydb-auth-proxy

Dockerfile.buster

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Use the latest stable golang 1.x to compile to a binary
16+
FROM golang:1 as build
17+
18+
WORKDIR /go/src/alloydb-auth-proxy
19+
COPY . .
20+
21+
RUN go get ./...
22+
RUN go build -ldflags "-X main.metadataString=container.buster"
23+
24+
# Final stage
25+
FROM debian:buster
26+
RUN apt-get update && apt-get install -y ca-certificates
27+
# Install fuse and allow enable non-root users to mount
28+
RUN apt-get update && apt-get install -y fuse && sed -i 's/^#user_allow_other$/user_allow_other/g' /etc/fuse.conf
29+
# Add a non-root user matching the nonroot user from the main container
30+
RUN groupadd -g 65532 -r nonroot && useradd -u 65532 -g 65532 -r nonroot
31+
# Set the uid as an integer for compatibility with runAsNonRoot in Kubernetes
32+
USER 65532
33+
34+
COPY --from=build --chown=nonroot /go/src/alloydb-auth-proxy/alloydb-auth-proxy /alloydb-auth-proxy

cmd/version.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.0.0-dev
1+
0.1.0-dev

0 commit comments

Comments
 (0)