forked from iCyris/Vidar-Website
-
Notifications
You must be signed in to change notification settings - Fork 3
59 lines (49 loc) · 1.97 KB
/
docker_cd.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
name: Docker Image CI
on:
push:
branches:
- master
workflow_dispatch:
env:
DEPLOY_NAME: 'vidar-website'
IMAGE_REPO: 'vidar-team/vidar-website'
IMAGE_BASE: 'registry.cn-hangzhou.aliyuncs.com'
jobs:
build:
if: github.repository == 'vidar-team/Vidar-Website'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Gen tag
id: gen-tag
run: |
echo "tag=$(date +%s)" >> $GITHUB_OUTPUT
echo "Generated tag: ${{ steps.gen-tag.outputs.tag }}"
- name: Build the Docker image
run: |
echo "Building Website image with tag: ${{ steps.gen-tag.outputs.tag }}"
docker build --no-cache -f Dockerfile ./ --tag ${{ env.IMAGE_BASE }}/${{ env.IMAGE_REPO }}-main:${{ steps.gen-tag.outputs.tag }}
- name: Push the Docker image
timeout-minutes: 3
run: |
echo "Logging into Docker registry: ${{ env.IMAGE_BASE }}"
docker login --username ${{ secrets.DOCKER_USERNAME }} --password ${{ secrets.DOCKER_PASSWORD }} ${{ env.IMAGE_BASE }}
echo "Pushing Website Docker image with tag: ${{ steps.gen-tag.outputs.tag }}"
docker push ${{ env.IMAGE_BASE }}/${{ env.IMAGE_REPO }}-main:${{ steps.gen-tag.outputs.tag }}
- name: Checkout ArgoCD
uses: actions/checkout@v4
with:
repository: vidar-team-devops/argocd
ssh-key: ${{ secrets.ARGO_KEY_SSH }}
path: deploy
- name: Update ArgoCD
run: |
cd deploy/vidar-website
git config user.name github-actions
git config user.email github-actions@github.com
sed -i "s|^\(\s*name:\s*.*-\)[0-9]\+|\1${{ steps.gen-tag.outputs.tag }}|" ./mainpage-sync.yml
sed -i "s|^\(\s*image:\s*.*:\)[0-9]\+|\1${{ steps.gen-tag.outputs.tag }}|" ./mainpage-sync.yml
git add .
git commit -m "update: image of mainpage"
git push