-
-
Notifications
You must be signed in to change notification settings - Fork 33
152 lines (132 loc) · 5.42 KB
/
container-release.yml
File metadata and controls
152 lines (132 loc) · 5.42 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
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
name: Publish Containerized Demo
on:
release:
types: [created]
push:
branches:
- master
paths:
- 'examples/**'
- '.github/workflows/container-release.yml'
workflow_dispatch:
jobs:
publish-container:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set version tag
id: set_version
run: |
if [[ "${{ github.event_name }}" == "release" ]]; then
echo "VERSION=${{ github.event.release.tag_name }}" >> $GITHUB_ENV
echo "IS_RELEASE=true" >> $GITHUB_ENV
else
echo "VERSION=latest" >> $GITHUB_ENV
echo "IS_RELEASE=false" >> $GITHUB_ENV
fi
- name: Send Initial Slack Message
id: send_initial_slack_release
uses: rennf93/good-comms@master
with:
SLACK_WEBHOOK: '${{ secrets.SLACK_WEBHOOK }}'
SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }}
STATUS: 'Started'
CHANNEL_ID: '${{ secrets.SLACK_CHANNEL }}'
AUTHOR_NAME: 'FastAPI Guard - Containerized Release'
AUTHOR_LINK: 'https://github.com/rennf93/fastapi-guard'
AUTHOR_ICON: ':whale:'
TITLE: 'Containerized Release Started'
TITLE_LINK: 'https://github.com/rennf93/fastapi-guard/actions'
MESSAGE: |
.
*${{ env.IS_RELEASE == 'true' && format('NEW VERSION v{0}', env.VERSION) || 'EXAMPLE CODE CHANGES' }} TRIGGERED CONTAINERIZED RELEASE!*
Commit:
${{ github.event.head_commit.message }}
.
COLOR: warning
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.10'
- name: Log in to GHCR
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Compose
uses: docker/setup-compose-action@v2
with:
version: latest
- name: Build with Docker Compose
working-directory: ./examples/advanced_app
run: |
docker compose build
- name: List Docker images
run: |
echo "Available Docker images:"
docker images
- name: Tag and Push to GHCR
run: |
IMAGE_NAME=$(docker images --format "{{.Repository}}:{{.Tag}}" | grep "fastapi-guard-example" | head -n 1)
echo "Using image: ${IMAGE_NAME}"
docker tag ${IMAGE_NAME} ghcr.io/${{ github.repository_owner }}/fastapi-guard-example:latest
docker push ghcr.io/${{ github.repository_owner }}/fastapi-guard-example:latest
if [[ "${{ env.IS_RELEASE }}" == "true" ]]; then
docker tag ${IMAGE_NAME} ghcr.io/${{ github.repository_owner }}/fastapi-guard-example:${{ env.VERSION }}
docker push ghcr.io/${{ github.repository_owner }}/fastapi-guard-example:${{ env.VERSION }}
fi
- name: Notify Success on Slack Channel
uses: rennf93/good-comms@master
with:
SLACK_WEBHOOK: '${{ secrets.SLACK_WEBHOOK }}'
SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }}
STATUS: 'Success'
CHANNEL_ID: '${{ secrets.SLACK_CHANNEL }}'
AUTHOR_NAME: 'FastAPI Guard - Containerized Release'
AUTHOR_LINK: 'https://github.com/rennf93/fastapi-guard'
AUTHOR_ICON: ':gem:'
TITLE: 'Containerized Release Successful'
TITLE_LINK: 'https://github.com/rennf93/fastapi-guard/pkgs/container/fastapi-guard'
MESSAGE: |
.
*Containerized Release ${{ env.IS_RELEASE == 'true' && format('v{0}', env.VERSION) || '(from code changes)' }} Published to GHCR!*
.
Example App: `ghcr.io/${{ github.repository_owner }}/fastapi-guard-example:latest`
${{ env.IS_RELEASE == 'true' && format('Version tag: `ghcr.io/{0}/fastapi-guard-example:{1}`', github.repository_owner, env.VERSION) || '' }}
Commit message:
${{ github.event.head_commit.message }}
Commit URL:
${{ github.event.head_commit.url }}
.
COLOR: good
SLACK_THREAD_TS: ${{ steps.send_initial_slack_release.outputs.SLACK_THREAD_TS }}
- name: Send Failure Notification to Slack
if: failure()
uses: rennf93/good-comms@master
with:
SLACK_WEBHOOK: '${{ secrets.SLACK_WEBHOOK }}'
SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }}
STATUS: 'Failed'
CHANNEL_ID: '${{ secrets.SLACK_CHANNEL }}'
AUTHOR_NAME: 'FastAPI Guard - Containerized Release'
AUTHOR_LINK: 'https://github.com/rennf93/fastapi-guard'
AUTHOR_ICON: ':skull:'
TITLE: 'Containerized Release Failed'
TITLE_LINK: 'https://github.com/rennf93/fastapi-guard/actions'
MESSAGE: |
.
*Containerized Release ${{ env.IS_RELEASE == 'true' && format('v{0}', env.VERSION) || '(from code changes)' }} Failed!*
.
Containerized Release failed for commit:
${{ github.event.head_commit.message }}
Commit URL:
${{ github.event.head_commit.url }}
Please check the logs for more details.
.
COLOR: danger
SLACK_THREAD_TS: ${{ steps.send_initial_slack_release.outputs.SLACK_THREAD_TS }}