1+ name : DOCKER
2+
3+ on :
4+ push :
5+ branches :
6+ - master
7+ - development
8+ tags :
9+ - " v*.*.*"
10+ workflow_dispatch :
11+
12+ env :
13+ REPOSITORY : flood_warning_information_system/application
14+
15+ jobs :
16+ docker-build :
17+ runs-on : ubuntu-latest
18+ # These permissions are needed to interact with GitHub's OIDC Token endpoint.
19+ permissions :
20+ id-token : write
21+ contents : read
22+ steps :
23+ - name : Checkout repository
24+ uses : actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # 6.0.0
25+ with :
26+ fetch-depth : 0 # Shallow clones block `git describe --always --tags` from working later in 'Set all tags'
27+ # Configure our AWS credentials and region environment variables for use in other GitHub Actions
28+ # https://github.com/aws-actions/configure-aws-credentials
29+ - name : Configure AWS Credentials
30+ uses : aws-actions/configure-aws-credentials@56d6a583f00f6bad6d19d91d53a7bc3b8143d0e9 # 5.1.1
31+ with :
32+ aws-region : ${{ secrets.AWS_ENV_REGION }}
33+ role-to-assume : arn:aws:iam::${{ secrets.AWS_ENV_ACCOUNT }}:role/${{ secrets.AWS_ENV_ROLE }}
34+
35+ # Login to AWS ECR private. It will use the credentials we configured in the previous step
36+ # https://github.com/aws-actions/amazon-ecr-login
37+ - name : Login to Amazon ECR
38+ id : login-ecr
39+ uses : aws-actions/amazon-ecr-login@062b18b96a7aff071d4dc91bc00c4c1a7945b076 # 2.0.1
40+
41+ - name : Generate raw tag
42+ id : raw-tag
43+ run :
44+ echo "raw_tag=$(git describe --always --tags)" >> $GITHUB_OUTPUT
45+
46+ - name : Extract Docker metadata
47+ id : meta
48+ uses : docker/metadata-action@318604b99e75e41977312d83839a89be02ca4893 # 5.9.0
49+ with :
50+ flavor : |
51+ latest=false
52+ images : ${{ steps.login-ecr.outputs.registry }}/${{ env.REPOSITORY }}
53+ tags : |
54+ type=semver,event=tag,priority=900,pattern={{version}},value=${{ steps.raw-tag.outputs.raw_tag }},enable=${{ startsWith(github.ref, 'refs/tags/v') }}
55+ type=raw,priority=800,value=${{ steps.raw-tag.outputs.raw_tag }},enable=${{ github.ref == format('refs/heads/{0}', 'master') }}
56+ type=raw,priority=800,value=${{ steps.raw-tag.outputs.raw_tag }},enable=${{ github.ref == format('refs/heads/{0}', 'development') }}
57+ type=raw,event=branch,value={{branch}}-{{sha}},enable=${{ contains(github.ref, '/NI-') }}
58+ labels : |
59+ org.opencontainers.image.licenses=OGL-UK-3.0
60+
61+ # Build and push Docker image with Buildx
62+ # https://github.com/docker/build-push-action
63+ - name : Build and push Docker image
64+ uses : docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # 6.18.0
65+ with :
66+ context : .
67+ target : production
68+ build-args : |
69+ GIT_COMMIT=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}
70+ BUILD_VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}
71+ push : true
72+ labels : ${{ steps.meta.outputs.labels }}
73+ tags : ${{ steps.meta.outputs.tags }}
74+
75+ # Generate a summary that will be displayed against the Job when selected in the Actions tab.
76+ # We this to quickly see details for the image generated instead of digging into the build output.
77+ # https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#adding-a-job-summary
78+ - name : Generate job summary
79+ id : summary
80+ run : |
81+ {
82+ echo "### Docker Image details"
83+ echo "The tag is **${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}**"
84+ echo "| Label | Value |"
85+ echo "| ---------- | ----- |"
86+ echo "| created | ${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }} |"
87+ echo "| description| ${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.description'] }} |"
88+ echo "| licenses | ${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.licenses'] }} |"
89+ echo "| revision | ${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }} |"
90+ echo "| source | ${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.source'] }} |"
91+ echo "| title | ${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.title'] }} |"
92+ echo "| url | ${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.url'] }} |"
93+ echo "| version | ${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }} |"
94+ } >> $GITHUB_STEP_SUMMARY
0 commit comments