Skip to content

Commit 24dfe4c

Browse files
committed
update docker build steps for envs
1 parent 910bb5e commit 24dfe4c

File tree

1 file changed

+77
-12
lines changed

1 file changed

+77
-12
lines changed

.github/workflows/build-and-publish-docker.yml

Lines changed: 77 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Create and publish a Docker image
1+
name: Deploy application
22

33
on:
44
workflow_dispatch:
@@ -12,14 +12,19 @@ env:
1212
IMAGE_NAME: ${{ github.repository }}
1313

1414
jobs:
15-
build-and-push-image:
15+
build:
16+
name: Build docker image
1617
runs-on: ubuntu-latest
1718
permissions:
1819
contents: read
1920
packages: write
2021
attestations: write
21-
id-token: write
22-
#
22+
23+
outputs:
24+
build_image: ${{ steps.output.outputs.build_image }}
25+
build_image_tag: ${{ steps.output.outputs.build_image_tag }}
26+
version: ${{ steps.output.outputs.version }}
27+
2328
steps:
2429
- name: Checkout repository
2530
uses: actions/checkout@v4
@@ -37,19 +42,79 @@ jobs:
3742
with:
3843
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
3944

40-
- name: Build and push Docker image
45+
- name: Extract version number
46+
id: package-version
47+
uses: martinbeentjes/npm-get-version-action@v1.3.1
48+
49+
- name: Build and publish image
4150
id: push
4251
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
4352
with:
4453
context: .
4554
push: true
46-
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.run_number }}
55+
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.package-version.outputs.current-version }}-build.${{ github.run_number }}
4756
labels: ${{ steps.meta.outputs.labels }}
4857

49-
- name: Generate artifact attestation
50-
uses: actions/attest-build-provenance@v2
58+
- name: Store outputs
59+
id: output
60+
run: |
61+
echo "build_image=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}" >> "$GITHUB_OUTPUT"
62+
echo "build_image_tag=${{ steps.package-version.outputs.current-version }}-build.${{ github.run_number }}" >> "$GITHUB_OUTPUT"
63+
echo "version=${{ steps.package-version.outputs.current-version }}" >> "$GITHUB_OUTPUT"
64+
65+
deploy-dev:
66+
name: Deploy to Development
67+
runs-on: ubuntu-latest
68+
needs: build
69+
environment: 'development'
70+
permissions:
71+
contents: read
72+
packages: write
73+
attestations: write
74+
steps:
75+
- name: Deploy to Development
76+
uses: shrink/actions-docker-registry-tag@v4
5177
with:
52-
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
53-
subject-digest: ${{ steps.push.outputs.digest }}
54-
push-to-registry: true
55-
78+
registry: ghcr.io
79+
repository: ${{ needs.build.outputs.build_image }}
80+
target: ${{ needs.build.outputs.build_image_tag }}
81+
tags: |
82+
${{ needs.build.outputs.version }}-dev
83+
84+
deploy-staging:
85+
name: Deploy to Staging
86+
runs-on: ubuntu-latest
87+
needs: build
88+
environment: 'staging'
89+
permissions:
90+
contents: read
91+
packages: write
92+
attestations: write
93+
steps:
94+
- name: Deploy to Staging
95+
uses: shrink/actions-docker-registry-tag@v4
96+
with:
97+
registry: ghcr.io
98+
repository: ${{ needs.build.outputs.build_image }}
99+
target: ${{ needs.build.outputs.build_image_tag }}
100+
tags: |
101+
${{ needs.build.outputs.version }}-staging
102+
103+
deploy-prod:
104+
name: Deploy to Production
105+
runs-on: ubuntu-latest
106+
needs: build
107+
environment: 'production'
108+
permissions:
109+
contents: read
110+
packages: write
111+
attestations: write
112+
steps:
113+
- name: Deploy to Production
114+
uses: shrink/actions-docker-registry-tag@v4
115+
with:
116+
registry: ghcr.io
117+
repository: ${{ needs.build.outputs.build_image }}
118+
target: ${{ needs.build.outputs.build_image_tag }}
119+
tags: |
120+
${{ needs.build.outputs.version }}

0 commit comments

Comments
 (0)