Skip to content

Commit b07eec6

Browse files
authored
chore: adds a cloudbuild file #630 (#634)
1 parent 8b664f7 commit b07eec6

File tree

2 files changed

+101
-2
lines changed

2 files changed

+101
-2
lines changed

Dockerfile

+5-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ ARG COMMIT
2020
ADD ./internal /go/src/apigeecli/internal
2121
ADD ./cmd /go/src/apigeecli/cmd
2222

23+
COPY .github/workflows/licenses.tpl /go/src/apigeecli
2324
COPY go.mod go.sum /go/src/apigeecli/
2425

2526
WORKDIR /go/src/apigeecli
@@ -28,6 +29,8 @@ ENV GO111MODULE=on
2829
RUN go mod tidy
2930
RUN go mod download
3031
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -buildvcs=true -a -gcflags='all="-l"' -ldflags='-s -w -extldflags "-static" -X main.version='${TAG}' -X main.commit='${COMMIT}' -X main.date='$(date +%FT%H:%I:%M+%Z) -o /go/bin/apigeecli /go/src/apigeecli/cmd/apigeecli/apigeecli.go
32+
RUN GOBIN=/tmp/ go install github.com/google/[email protected]
33+
RUN /tmp/go-licenses report ./... --template /go/src/apigeecli/licenses.tpl --ignore internal > /tmp/third-party-licenses.txt 2> /dev/null || echo "Ignore warnings"
3134

3235
FROM ghcr.io/jqlang/jq:1.7.1@sha256:096b83865ad59b5b02841f103f83f45c51318394331bf1995e187ea3be937432 AS jq
3336

@@ -41,8 +44,8 @@ LABEL org.opencontainers.image.url='https://github.com/apigee/apigeecli' \
4144
org.opencontainers.image.description='This is a tool to interact with Apigee APIs'
4245

4346
COPY --from=builder /go/bin/apigeecli /usr/local/bin/apigeecli
44-
COPY LICENSE.txt /
45-
COPY third-party-licenses.txt /
47+
COPY --chown=nonroot:nonroot LICENSE.txt /
48+
COPY --from=builder --chown=nonroot:nonroot /tmp/third-party-licenses.txt /
4649
COPY --from=jq /jq /usr/local/bin/jq
4750

4851
ENTRYPOINT [ "apigeecli" ]

cloudbuild.yaml

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Copyright 2022 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+
# gcloud builds submit --config=cloudbuild.yaml --project=project-name --substitutions=TAG="v0.65"
15+
steps:
16+
#publish latest cosign
17+
- name: 'gcr.io/cloud-builders/docker'
18+
id: build_cosign
19+
args:
20+
- 'build'
21+
- '-t'
22+
- '${_COSIGN_IMAGE_NAME}:latest'
23+
- '-f'
24+
- 'Dockerfile.cosign'
25+
- '.'
26+
- name: 'gcr.io/cloud-builders/docker'
27+
id: push_cosign
28+
args: ['push', '${_COSIGN_IMAGE_NAME}:latest']
29+
#publish apigeecli
30+
- name: 'gcr.io/cloud-builders/docker'
31+
id: build_apigeecli
32+
args:
33+
- 'build'
34+
- '-t'
35+
- '${_IMAGE_NAME}:${TAG_NAME}'
36+
- '-f'
37+
- 'Dockerfile'
38+
- '.'
39+
- '--build-arg'
40+
- 'TAG=${TAG_NAME}'
41+
- '--build-arg'
42+
- 'COMMIT=$COMMIT_SHA'
43+
- name: 'gcr.io/cloud-builders/docker'
44+
id: push_apigeecli
45+
args: ['push', '${_IMAGE_NAME}:${TAG_NAME}']
46+
- name: 'gcr.io/cloud-builders/docker'
47+
id: tag_latest_apigeecli
48+
args: ['tag', '${_IMAGE_NAME}:${TAG_NAME}', '${_IMAGE_NAME}:latest']
49+
- name: 'gcr.io/cloud-builders/docker'
50+
id: push_latest_apigeecli
51+
args: ['push', '${_IMAGE_NAME}:latest']
52+
53+
#sign and attach apigeecli
54+
- name: 'us-docker.pkg.dev/${PROJECT_ID}/${_REPO}/cosign:latest'
55+
id: sign_apigeecli
56+
entrypoint: 'sh'
57+
secretEnv: ['COSIGN_PASSWORD', 'COSIGN_PRIVATE_KEY']
58+
args:
59+
- -c
60+
- |
61+
echo "$$COSIGN_PRIVATE_KEY" > /tmp/cosign.key
62+
cosign sign --key=/tmp/cosign.key --output-signature=/tmp/apigeecli_${TAG_NAME}.sig --yes ${_IMAGE_NAME}:${TAG_NAME}
63+
cosign attach signature --signature=/tmp/apigeecli_${TAG_NAME}.sig ${_IMAGE_NAME}:${TAG_NAME}
64+
65+
- name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
66+
id: export_sbom
67+
entrypoint: gcloud
68+
args:
69+
- artifacts
70+
- sbom
71+
- export
72+
- --uri=${_IMAGE_NAME}:${TAG_NAME}
73+
- --project=${PROJECT_ID}
74+
75+
availableSecrets:
76+
secretManager:
77+
- versionName: projects/$PROJECT_ID/secrets/apigeecli-cosign-password/versions/latest
78+
env: 'COSIGN_PASSWORD'
79+
- versionName: projects/$PROJECT_ID/secrets/apigeecli-cosign-private-key/versions/latest
80+
env: 'COSIGN_PRIVATE_KEY'
81+
82+
images:
83+
- '${_IMAGE_NAME}:${TAG_NAME}'
84+
85+
#repo name
86+
substitutions:
87+
_REPO: "images"
88+
_IMAGE_NAME: "us-docker.pkg.dev/${PROJECT_ID}/${_REPO}/apigeecli"
89+
_COSIGN_IMAGE_NAME: "us-docker.pkg.dev/${PROJECT_ID}/${_REPO}/cosign"
90+
91+
options:
92+
machineType: E2_HIGHCPU_8
93+
logging: CLOUD_LOGGING_ONLY
94+
substitution_option: ALLOW_LOOSE
95+
dynamic_substitutions: true
96+
requestedVerifyOption: VERIFIED

0 commit comments

Comments
 (0)