1
- name : default
1
+ name : docker-build
2
2
3
3
on :
4
- push :
5
4
pull_request :
6
5
branches :
7
6
- main
8
- - develop
7
+ - test
8
+ push :
9
+ branches :
10
+ - main
11
+ - test
12
+ tags :
13
+ - ' v*'
9
14
10
15
jobs :
11
- # integration:
12
- # runs-on: ubuntu-latest
13
-
14
- # container: "node:16"
15
-
16
- # steps:
17
- # - uses: actions/checkout@v2
18
-
19
- # - name: Audit
20
- # run: npm audit
21
- delivery :
16
+ build :
22
17
runs-on : ubuntu-latest
23
- # needs: integration
24
-
25
- if : github.ref == 'refs/heads/main' && github.event_name == 'push'
18
+ permissions :
19
+ contents : read
20
+ packages : write
26
21
27
22
steps :
28
- - uses : actions/checkout@v2
23
+ - name : Checkout
24
+ uses : actions/checkout@v3
29
25
30
- - name : Set up Docker Buildx
31
- uses : docker/setup-buildx-action@v1
26
+ # https://docs.docker.com/build/ci/github-actions/multi-platform/
27
+ - name : Set up QEMU
28
+ uses : docker/setup-qemu-action@v2
32
29
33
- - name : Cache Docker layers
34
- uses : actions/cache@v2
35
- with :
36
- path : /tmp/.buildx-cache
37
- key : ${{ runner.os }}-buildx-${{ github.sha }}
38
- restore-keys : |
39
- ${{ runner.os }}-buildx-
30
+ # Workaround: https://github.com/docker/build-push-action/issues/461
31
+ - name : Setup Docker buildx
32
+ uses : docker/setup-buildx-action@v2
40
33
41
34
- name : Configure AWS credentials
42
35
uses : aws-actions/configure-aws-credentials@v1
@@ -49,19 +42,49 @@ jobs:
49
42
id : login-ecr
50
43
uses : aws-actions/amazon-ecr-login@v1
51
44
52
- # - name: Login to DockerHub
53
- # uses: docker/login-action@v1
54
- # with:
55
- # username: ${{ secrets.DOCKER_HUB_USERNAME }}
56
- # password: ${{ secrets.DOCKER_HUB_PASSWORD }}
45
+ - name : Log in to the github container registry
46
+ uses : docker/login-action@v2
47
+ with :
48
+ registry : ghcr.io
49
+ username : ${{ github.actor }}
50
+ password : ${{ secrets.GITHUB_TOKEN }}
57
51
58
- - name : Build, tag, and push docker image to AWS ECR
59
- uses : docker/build-push-action@v2
52
+ # https://github.com/docker/login-action
53
+ - name : Login to DockerHub
54
+ uses : docker/login-action@v2
60
55
with :
61
- push : true
56
+ username : ${{ secrets.DOCKERHUB_USER }}
57
+ password : ${{ secrets.DOCKERHUB_TOKEN }}
58
+
59
+ - name : Extract metadata (tags, labels) for Docker
60
+ id : meta
61
+ uses : docker/metadata-action@v4
62
+ with :
63
+ github-token : ${{ secrets.GITHUB_TOKEN }}
64
+ images : |
65
+ ${{ steps.login-ecr.outputs.registry }}/fcd
66
+ ghcr.io/${{ github.repository }}
67
+ terraformlabs/fcd
62
68
tags : |
63
- ${{ steps.login-ecr.outputs.registry }}/fcd:${{ github.sha }}
64
- ${{ steps.login-ecr.outputs.registry }}/fcd:latest
65
- # terramoney/fcd:latest
66
- cache-from : type=local,src=/tmp/.buildx-cache
67
- cache-to : type=local,dest=/tmp/.buildx-cache
69
+ type=sha
70
+ type=edge,branch=test
71
+ type=semver,pattern={{tag}}
72
+ type=semver,pattern={{version}}
73
+ type=raw,value=latest,enable={{is_default_branch}}
74
+
75
+ - name : Build docker image
76
+ uses : docker/build-push-action@v3
77
+ with :
78
+ push : ${{ github.event_name != 'pull_request' }}
79
+ file : Dockerfile
80
+ platforms : linux/amd64,linux/arm64
81
+ tags : ${{ env.DOCKER_METADATA_OUTPUT_TAGS }}
82
+ labels : ${{ env.DOCKER_METADATA_OUTPUT_LABELS }}
83
+
84
+ on :
85
+ push :
86
+ pull_request :
87
+ branches :
88
+ - main
89
+ - develop
90
+
0 commit comments