-
Notifications
You must be signed in to change notification settings - Fork 1
100 lines (86 loc) · 4.18 KB
/
build-push-commit.yaml
File metadata and controls
100 lines (86 loc) · 4.18 KB
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
name: Build, Push and Commit Digest
on:
push:
branches:
- main
- develop
jobs:
build_and_push:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Get latest commit author and message
run: |
echo "COMMIT_AUTHOR=$(git log -1 --pretty=format:'%an')" >> $GITHUB_ENV
echo "COMMIT_MESSAGE=$(git log -1 --pretty=format:'%s')" >> $GITHUB_ENV
- name: Extract branch name
shell: bash
run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_ENV
- name: Build and push Docker image
run: |
if [ "${{ env.BRANCH_NAME }}" = "develop" ]
then
docker build --build-arg STAKING_API_URL="https://dev-staking-api.stakely.io/docs" --build-arg STAKING_API_DOC_JSON_URL="https://dev-staking-api.stakely.io/docs-json" --build-arg APP_URL="https://dev-app.stakely.io" -t stakely/stakely-docs:${{ env.BRANCH_NAME }} .
elif [ "${{ env.BRANCH_NAME }}" = "main" ]
then
docker build --build-arg STAKING_API_URL="https://staking-api.stakely.io/docs" --build-arg STAKING_API_DOC_JSON_URL="https://staking-api.stakely.io/docs-json" --build-arg APP_URL="https://app.stakely.io" -t stakely/stakely-docs:${{ env.BRANCH_NAME }} .
fi
echo '${{ secrets.DOCKERHUB_PASSWORD }}' | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
docker push stakely/stakely-docs:${{ env.BRANCH_NAME }}
- name: Get image digest
id: get_digest
run: |
digest=$(docker inspect --format='{{index .RepoDigests 0}}' stakely/stakely-docs:${{ env.BRANCH_NAME }})
echo "IMAGE_DIGEST=$digest" >> $GITHUB_ENV
- name: Setup SSH
uses: MrSquaare/ssh-setup-action@v2.0.1
with:
host: github.com
private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Clone manifests repository
run: git clone git@github.com:Stakely/kubernetes-manifests.git
- name: Commit and push digest to second repository
run: |
cd kubernetes-manifests
echo "Image Digest: ${{ env.IMAGE_DIGEST }}"
# Replaces the image digest with the new one to trigger ArgoCD
if [ "${{ env.BRANCH_NAME }}" = "main" ]
then
yq e '.frontend.docs.image = "${{ env.IMAGE_DIGEST }}"' -i web/values.production.yaml
elif [ "${{ env.BRANCH_NAME }}" = "develop" ]
then
yq e '.frontend.docs.image = "${{ env.IMAGE_DIGEST }}"' -i web/values.development.yaml
fi
git config --global user.email "workflows@stakely.io"
git config --global user.name "Stakely Workflow"
git add -A
git commit -m "Update stakely-docs:${{ env.BRANCH_NAME }} image digest"
git push
- name: Send Discord notification if success
uses: tsickert/discord-webhook@v5.3.0
with:
webhook-url: ${{ secrets.DISCORD_WEBHOOK_URL }}
username: 'GitHub Actions'
avatar-url: 'https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png'
embed-color: '3066993'
embed-description: |
Workflow _${{ github.workflow }}_ in repository https://github.com/${{ github.repository }}/tree/${{ env.BRANCH_NAME }} has completed and https://github.com/Stakely/kubernetes-manifests has been updated.
ArgoCD will deploy the changes in <3 min.
- **Commit**: _${{ env.COMMIT_MESSAGE }}_ by _${{ env.COMMIT_AUTHOR }}_
- **Branch**: ${{ github.ref_name }}
- **Status**: ${{ job.status }}
- name: Send Discord notification if error
if: failure()
uses: tsickert/discord-webhook@v5.3.0
with:
webhook-url: ${{ secrets.DISCORD_WEBHOOK_URL }}
username: 'GitHub Actions'
avatar-url: 'https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png'
embed-color: '15158332'
embed-description: |
Error with the workflow _${{ github.workflow }}_ in https://github.com/${{ github.repository }}/actions.
Nothing will be deployed until this is fixed.
- **Commit**: _${{ env.COMMIT_MESSAGE }}_ by _${{ env.COMMIT_AUTHOR }}_
- **Branch**: ${{ github.ref_name }}
- **Status**: ${{ job.status }}