1
+ name : cd
2
+ on :
3
+ push :
4
+ branches :
5
+ - master
6
+ tags :
7
+ - v*
8
+ workflow_dispatch :
9
+
10
+ permissions :
11
+ contents : read
12
+
13
+ jobs :
14
+ test :
15
+ runs-on : ubuntu-latest
16
+ steps :
17
+ - name : checkout
18
+ uses : actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
19
+ - uses : actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5
20
+ with :
21
+ go-version-file : go.mod
22
+ cache : true
23
+ - name : build package
24
+ run : go build
25
+ - name : build docker image
26
+ run : docker build . --tag gravitational/missing-container-metrics:test
27
+
28
+ build_and_push_docker_image :
29
+ runs-on : ubuntu-latest
30
+ needs : [test]
31
+ name : Build and push Docker image
32
+ env :
33
+ AWS_REGION : us-east-1
34
+ AWS_ROLE : arn:aws:iam::146628656107:role/missing-container-metrics-github-action-ecr-role
35
+ permissions :
36
+ packages : write
37
+ id-token : write
38
+ steps :
39
+ - name : Checkout repo
40
+ uses : actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
41
+ - name : Set up QEMU
42
+ uses : docker/setup-qemu-action@v3
43
+ - name : Setup docker buildx
44
+ uses : docker/setup-buildx-action@v3
45
+
46
+ - name : Configure AWS credentials
47
+ uses : aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4
48
+ with :
49
+ aws-region : ${{ env.AWS_REGION }}
50
+ role-to-assume : ${{ env.AWS_ROLE }}
51
+ - name : Login to ECR
52
+ id : login-ecr
53
+ uses : aws-actions/amazon-ecr-login@062b18b96a7aff071d4dc91bc00c4c1a7945b076 # v2
54
+ with :
55
+ registry-type : public
56
+
57
+ - name : Login to GitHub Container Registry
58
+ id : login-ghcr
59
+ uses : docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
60
+ with :
61
+ registry : ghcr.io
62
+ username : ${{ github.actor }}
63
+ password : ${{ secrets.GITHUB_TOKEN }}
64
+
65
+ - name : Prepare docker labels and tags
66
+ id : meta
67
+ uses : docker/metadata-action@v5
68
+ with :
69
+ images : |
70
+ ${{ steps.login-ecr.outputs.registry }}/${{ github.repository }}
71
+ ghcr.io/${{ github.repository }}
72
+ flavor : |
73
+ latest=false
74
+ # Enable sha tag on branch push events and workflow dispatches.
75
+ # Enable semver tags on tag push events, but don't overwrite major/minor tags for prereleases.
76
+ tags : |
77
+ type=sha,prefix={{branch}}-,suffix=-{{date 'YYYYMMDDTHHmmss'}},format=short,enable=${{ startsWith(github.ref, 'refs/heads/') }}
78
+ type=semver,pattern={{major}},enable=${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') && !contains(github.ref, '-') }}
79
+ type=semver,pattern={{major}}.{{minor}},enable=${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') && !contains(github.ref, '-') }}
80
+ type=semver,pattern={{version}},enable=${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }}
81
+
82
+ - name : Build the Docker image and push
83
+ uses : docker/build-push-action@v5
84
+ with :
85
+ push : true
86
+ platforms : linux/amd64,linux/arm64
87
+ tags : ${{ steps.meta.outputs.tags }}
88
+ labels : ${{ steps.meta.outputs.labels }}
89
+ cache-from : type=gha
90
+ cache-to : type=gha,mode=max
0 commit comments