-
Notifications
You must be signed in to change notification settings - Fork 0
183 lines (153 loc) · 6.06 KB
/
ci.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
name: CI Docker and Helm
on:
push:
branches:
- workflow/api-improve
env:
IMAGE_NAME: amelieloulou/transform-and-deliver-assets
CHART_PATH: ./opensource
jobs:
determine-version:
runs-on: ubuntu-latest
outputs:
new_version: ${{ steps.set_output.outputs.new_version }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Get the latest tag
id: get_latest_tag
run: |
git fetch --tags
latest_tag=$(git tag -l --sort=-v:refname | head -n 1)
if [ -z "$latest_tag" ]; then
latest_tag="0.0.0"
fi
echo "Latest tag: $latest_tag"
echo "tag=$latest_tag" >> $GITHUB_ENV
- name: Determine next version
id: set_output
run: |
latest_tag=${{ env.tag }}
echo "Latest tag: $latest_tag"
IFS='.' read -r -a version_parts <<< "$latest_tag"
major=${version_parts[0]}
minor=${version_parts[1]}
patch=${version_parts[2]}
if [[ "${{ github.event.head_commit.message }}" == *"major"* ]]; then
major=$((major + 1))
minor=0
patch=0
elif [[ "${{ github.event.head_commit.message }}" == *"minor"* ]]; then
minor=$((minor + 1))
patch=0
else
patch=$((patch + 1))
fi
new_version="$major.$minor.$patch"
while git rev-parse "refs/tags/$new_version" >/dev/null 2>&1; do
patch=$((patch + 1))
new_version="$major.$minor.$patch"
done
echo "New version: $new_version"
echo "new_version=$new_version" >> $GITHUB_ENV
echo "new_version=$new_version" >> $GITHUB_OUTPUT
- name: Update Helm chart version
run: |
sed -i "s/^version:.*/version: ${{ steps.set_output.outputs.new_version }}/" ${{ env.CHART_PATH }}/Chart.yaml
sed -i "s/^appVersion:.*/appVersion: '${{ steps.set_output.outputs.new_version }}'/" ${{ env.CHART_PATH }}/Chart.yaml
- name: Commit updated Helm chart version
run: |
git config --global user.name 'github-actions'
git config --global user.email '[email protected]'
git add ${{ env.CHART_PATH }}/Chart.yaml
git commit -m "Update Helm chart version to ${{ steps.set_output.outputs.new_version }}"
git push origin HEAD:${{ github.head_ref }} # Push changes to the current branch
- name: Create and push new tag
run: |
git tag ${{ steps.set_output.outputs.new_version }}
git push origin ${{ steps.set_output.outputs.new_version }}
build-and-push-docker-api:
runs-on: ubuntu-latest
needs: determine-version
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Cache npm dependencies for API
uses: actions/cache@v3
with:
path: src/api/node_modules
key: ${{ runner.os }}-api-node-modules-${{ hashFiles('src/api/package-lock.json') }}
restore-keys: |
${{ runner.os }}-api-node-modules-
- name: Install npm dependencies for API
working-directory: src/api
run: npm install
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
install: true
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ hashFiles('src/api/Dockerfile', 'src/api/.dockerignore') }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-${{ hashFiles('src/api/Dockerfile', 'src/api/.dockerignore') }}-
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Docker image API
run: |
docker buildx build --platform linux/amd64,linux/arm64 --push -t ${{ env.IMAGE_NAME }}:api-${{ needs.determine-version.outputs.new_version }} --cache-from=type=local,src=/tmp/.buildx-cache --cache-to=type=local,dest=/tmp/.buildx-cache,mode=max ./src/api
build-and-push-docker-job:
runs-on: ubuntu-latest
needs: determine-version
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
install: true
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ hashFiles('src/Dockerfile', 'src/.dockerignore') }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-${{ hashFiles('src/Dockerfile', 'src/.dockerignore') }}-
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Docker image Job
run: |
docker buildx build --platform linux/amd64,linux/arm64 --push -t ${{ env.IMAGE_NAME }}:job-${{ needs.determine-version.outputs.new_version }} --cache-from=type=local,src=/tmp/.buildx-cache --cache-to=type=local,dest=/tmp/.buildx-cache,mode=max ./src
publish-helm-chart:
runs-on: ubuntu-latest
needs:
- build-and-push-docker-api
- build-and-push-docker-job
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Install Helm
uses: azure/setup-helm@v3
with:
version: v3.11.1
- name: Package Helm chart
run: |
helm package ${{ env.CHART_PATH }}
- name: Push Helm chart to Docker Hub
run: |
helm push $(ls *.tgz) oci://registry-1.docker.io/amelieloulou