-
Notifications
You must be signed in to change notification settings - Fork 199
151 lines (131 loc) · 5.32 KB
/
publish-workflows-service.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
name: Publish workflows-service image
on:
workflow_dispatch:
push:
branches:
- dev
- test
- prod
- staging
- demo
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository_owner }}/workflows-service
jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install jq
run: sudo apt-get install jq
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: 'arm64,arm'
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get package version from package.json
id: get_version
run: |
PACKAGE_VERSION=$(jq -r '.version' services/workflows-service/package.json)
echo "::set-output name=version::$PACKAGE_VERSION"
- name: Print the version
run: echo "The version was ${{ steps.get_version.outputs.version }}"
- name: Extract metadata for non Prod Docker images
if: github.ref != 'refs/heads/prod'
id: branchmeta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=${{ github.head_ref || github.ref_name }}
type=raw,value=commit-${{ github.sha }}-${{ github.head_ref || github.ref_name }}
type=raw,value=${{ steps.get_version.outputs.version }}-${{ github.head_ref || github.ref_name }}
- name: Extract metadata (tags, labels) for demo Docker
if: github.ref == 'refs/heads/demo'
id: demometa
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=demo
type=raw,value=commit-${{ github.sha }}-demo
type=raw,value=${{ steps.get_version.outputs.version }}-demo
- name: Extract metadata (tags, labels) for test Docker
if: github.ref == 'refs/heads/test'
id: testmeta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=test
type=raw,value=commit-${{ github.sha }}-test
type=raw,value=${{ steps.get_version.outputs.version }}-test
- name: Extract metadata (tags, labels) for prod Docker
if: github.ref == 'refs/heads/prod'
# This branch will have the tag latest
id: prodmeta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=prod
type=raw,value=commit-${{ github.sha }}-prod
type=raw,value=${{ steps.get_version.outputs.version }}-prod
type=raw,value=latest
- name: Extract metadata for other branches Docker
if: ${{ github.event_name == 'workflow_dispatch' }}
id: branchmeta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=${{ github.head_ref || github.ref_name }}
type=raw,value=commit-${{ github.sha }}-${{ github.head_ref || github.ref_name }}
- name: Build and push Docker image for Dev
if: github.ref == 'refs/heads/dev'
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: services/workflows-service
push: true
tags: ${{ steps.devmeta.outputs.tags }}
- name: Build and push Docker image for Demo
if: github.ref == 'refs/heads/demo'
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: services/workflows-service
push: true
tags: ${{ steps.demometa.outputs.tags }}
labels: ${{ steps.devmeta.outputs.labels }}
- name: Build and push Docker image for Test
if: github.ref == 'refs/heads/test'
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: services/workflows-service
push: true
tags: ${{ steps.testmeta.outputs.tags }}
- name: Build and push Docker image for Prod
if: github.ref == 'refs/heads/prod'
uses: docker/build-push-action@v4
with:
context: services/workflows-service
platforms: linux/amd64, linux/arm64
push: true
tags: ${{ steps.prodmeta.outputs.tags }}
- name: Build and push Docker image for other branch
if: ${{ github.event_name == 'workflow_dispatch' }}
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: services/workflows-service
push: true
tags: ${{ steps.branchmeta.outputs.tags }}