-
Notifications
You must be signed in to change notification settings - Fork 4
91 lines (79 loc) · 3.08 KB
/
docker-deploy.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
name: Docker Deploy
on:
workflow_run:
workflows: ["Run Tests"]
branches: [main]
types:
- completed
workflow_dispatch:
env:
TRIGGER_REGEX: ^DF-DOCKER
SHOULD_BUILD: false
jobs:
build-and-push:
runs-on: ubuntu-latest
environment: DiscoEnv
if: >
github.event.workflow_run.conclusion == 'success' ||
github.event_name == 'workflow_dispatch'
steps:
- name: Check out repository
uses: actions/checkout@v3
- name: Check commit message for keyword
id: check-commit-message
run: |
# Fetch the last commit message
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
# Check if the commit message starts with "${{ env.TRIGGER_REGEX }}"
if [[ "$COMMIT_MESSAGE" =~ ${{ env.TRIGGER_REGEX }} ]]; then
echo "Keyword found at the start of the commit message."
echo "SHOULD_BUILD=true" >> $GITHUB_ENV
else
echo "No relevant keyword found at the start of the commit message."
fi
- name: Set up Docker Buildx
if: ${{ env.SHOULD_BUILD == 'true' }}
uses: docker/setup-buildx-action@v2
- name: Log in to Docker Hub
if: ${{ env.SHOULD_BUILD == 'true' }}
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
- name: Set up QEMU
if: ${{ env.SHOULD_BUILD == 'true' }}
uses: docker/setup-qemu-action@v2
- name: Build and push Docker image (multi-arch)
if: ${{ env.SHOULD_BUILD == 'true' }}
uses: docker/build-push-action@v4
with:
platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ secrets.DOCKER_HUB_USERNAME }}/discoflix:latest
- name: Notify Discord
if: ${{ success() && env.SHOULD_BUILD == 'true' }}
run: |
COMMIT_SHA_SHORT=$(echo "${{ github.sha }}" | cut -c1-7)
curl -H "Content-Type: application/json" \
-d '{
"embeds": [{
"title": "DiscoFlix has been updated!",
"description": "The latest Docker images for DiscoFlix have been successfully built and pushed. Please update your containers to the latest version.",
"url": "https://github.com/${{ github.repository }}/commit/${{ github.sha }}",
"color": 5814783,
"fields": [
{
"name": "Commit",
"value": "[`'"$COMMIT_SHA_SHORT"'`](https://github.com/${{ github.repository }}/commit/${{ github.sha }})"
}
],
"image": {
"url": "https://i.imgur.com/wMhrFuq.png"
},
"footer": {
"text": "DiscoFlix Deployment"
}
}]
}' \
${{ secrets.DISCORD_WEBHOOK_URL }}