-
Notifications
You must be signed in to change notification settings - Fork 37
65 lines (62 loc) · 1.83 KB
/
docker.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
name: Push to GCR GitHub Action
on:
push:
branches:
- '**'
tags:
- '**'
# pull_request:
# branches:
# - 'main'
jobs:
check-env:
runs-on: ubuntu-latest
# assign output from step to job output
outputs:
gcloud-service-key: ${{ steps.gcloud-service-key.outputs.defined }}
steps:
- id: gcloud-service-key
# assign GCLOUD_SERVICE_KEY to env for access in conditional
env:
GCLOUD_SERVICE_KEY: ${{ secrets.GCLOUD_SERVICE_KEY }}
if: "${{ env.GCLOUD_SERVICE_KEY != '' }}"
# runs if GCLOUD_SERVICE_KEY is defined, so we set the output to true
run: echo "::set-output name=defined::true"
build-and-push-to-gcr:
runs-on: ubuntu-latest
# uses check-env to determine if secrets.GCLOUD_SERVICE_KEY is defined
needs: [check-env]
if: needs.check-env.outputs.gcloud-service-key == 'true'
steps:
- uses: actions/checkout@v4
-
name: Docker meta
id: meta
uses: docker/metadata-action@v3
with:
# list of Docker images to use as base name for tags
images: |
gcr.io/clabs-optics/optics-agent
# generate Docker tags based on the following events/attributes
tags: |
type=ref,event=branch
type=ref,event=pr
type=sha
-
name: Login to GCR
uses: docker/login-action@v1
with:
registry: gcr.io
username: _json_key
password: ${{ secrets.GCLOUD_SERVICE_KEY }}
-
name: Build and push
uses: docker/build-push-action@v2
env:
DOCKER_BUILDKIT: 1
with:
context: ./rust
file: ./rust/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}