generated from javidahmed64592/template-python
-
Notifications
You must be signed in to change notification settings - Fork 0
175 lines (151 loc) · 7.93 KB
/
docker.yml
File metadata and controls
175 lines (151 loc) · 7.93 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
name: Docker
on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:
jobs:
build-docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: ./.github/actions/docker/build-start-services
if: github.event.repository.name == 'python-template-server'
- uses: javidahmed64592/python-template-server/.github/actions/docker/build-start-services@main
if: github.event.repository.name != 'python-template-server'
- uses: ./.github/actions/docker/show-logs
if: github.event.repository.name == 'python-template-server'
- uses: javidahmed64592/python-template-server/.github/actions/docker/show-logs@main
if: github.event.repository.name != 'python-template-server'
- uses: ./.github/actions/docker/check-containers
if: github.event.repository.name == 'python-template-server'
with:
port: 443
- uses: javidahmed64592/python-template-server/.github/actions/docker/check-containers@main
if: github.event.repository.name != 'python-template-server'
with:
port: 443
- uses: ./.github/actions/docker/stop-services
if: github.event.repository.name == 'python-template-server'
- uses: javidahmed64592/python-template-server/.github/actions/docker/stop-services@main
if: github.event.repository.name != 'python-template-server'
prepare-release:
runs-on: ubuntu-latest
needs: [build-docker]
steps:
- uses: actions/checkout@v6
- uses: javidahmed64592/template-python/.github/actions/setup/install-python-dev@main
- uses: ./.github/actions/docker/prepare-release
if: github.event.repository.name == 'python-template-server'
- uses: javidahmed64592/python-template-server/.github/actions/docker/prepare-release@main
if: github.event.repository.name != 'python-template-server'
publish-release:
runs-on: ubuntu-latest
needs: [prepare-release]
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
permissions:
contents: write
packages: write
steps:
- uses: actions/checkout@v6
- uses: javidahmed64592/template-python/.github/actions/setup/install-python-core@main
- uses: ./.github/actions/docker/check-repo-name
if: github.event.repository.name == 'python-template-server'
id: check_repo_name_local
- uses: javidahmed64592/python-template-server/.github/actions/docker/check-repo-name@main
if: github.event.repository.name != 'python-template-server'
id: check_repo_name_remote
- id: check_repo_name
run: echo "should_release=${{ steps.check_repo_name_local.outputs.should_release || steps.check_repo_name_remote.outputs.should_release }}" >> $GITHUB_OUTPUT
shell: bash
- uses: ./.github/actions/docker/get-version
if: steps.check_repo_name.outputs.should_release == 'true' && github.event.repository.name == 'python-template-server'
id: get_version_local
- uses: javidahmed64592/python-template-server/.github/actions/docker/get-version@main
if: steps.check_repo_name.outputs.should_release == 'true' && github.event.repository.name != 'python-template-server'
id: get_version_remote
- id: get_version
if: steps.check_repo_name.outputs.should_release == 'true'
run: |
echo "version=${{ steps.get_version_local.outputs.version || steps.get_version_remote.outputs.version }}" >> $GITHUB_OUTPUT
echo "tag=${{ steps.get_version_local.outputs.tag || steps.get_version_remote.outputs.tag }}" >> $GITHUB_OUTPUT
shell: bash
- uses: ./.github/actions/docker/check-tag
if: steps.check_repo_name.outputs.should_release == 'true' && github.event.repository.name == 'python-template-server'
id: check_tag_local
with:
version: ${{ steps.get_version.outputs.version }}
- uses: javidahmed64592/python-template-server/.github/actions/docker/check-tag@main
if: steps.check_repo_name.outputs.should_release == 'true' && github.event.repository.name != 'python-template-server'
id: check_tag_remote
with:
version: ${{ steps.get_version.outputs.version }}
- id: check_tag
if: steps.check_repo_name.outputs.should_release == 'true'
run: echo "tag_exists=${{ steps.check_tag_local.outputs.tag_exists || steps.check_tag_remote.outputs.tag_exists }}" >> $GITHUB_OUTPUT
shell: bash
- name: Download release tarball
if: steps.check_repo_name.outputs.should_release == 'true' && steps.check_tag.outputs.tag_exists == 'false'
uses: actions/download-artifact@v8
with:
name: ${{ env.PACKAGE_NAME }}_release
- name: Set up Docker Buildx
if: steps.check_repo_name.outputs.should_release == 'true' && steps.check_tag.outputs.tag_exists == 'false'
uses: docker/setup-buildx-action@v4
- name: Log in to GitHub Container Registry
if: steps.check_repo_name.outputs.should_release == 'true' && steps.check_tag.outputs.tag_exists == 'false'
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for Docker
if: steps.check_repo_name.outputs.should_release == 'true' && steps.check_tag.outputs.tag_exists == 'false'
id: meta
uses: docker/metadata-action@v6
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=semver,pattern={{version}},value=v${{ steps.get_version.outputs.version }}
type=semver,pattern={{major}}.{{minor}},value=v${{ steps.get_version.outputs.version }}
type=semver,pattern={{major}},value=v${{ steps.get_version.outputs.version }}
type=raw,value=latest
- name: Build and push Docker image
if: steps.check_repo_name.outputs.should_release == 'true' && steps.check_tag.outputs.tag_exists == 'false'
uses: docker/build-push-action@v7
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64
- uses: ./.github/actions/docker/generate-release-notes
if: steps.check_repo_name.outputs.should_release == 'true' && steps.check_tag.outputs.tag_exists == 'false' && github.event.repository.name == 'python-template-server'
id: release_notes_local
with:
version: ${{ steps.get_version.outputs.version }}
- uses: javidahmed64592/python-template-server/.github/actions/docker/generate-release-notes@main
if: steps.check_repo_name.outputs.should_release == 'true' && steps.check_tag.outputs.tag_exists == 'false' && github.event.repository.name != 'python-template-server'
id: release_notes_remote
with:
version: ${{ steps.get_version.outputs.version }}
- id: release_notes
if: steps.check_repo_name.outputs.should_release == 'true' && steps.check_tag.outputs.tag_exists == 'false'
run: echo "release_notes_file=${{ steps.release_notes_local.outputs.release_notes_file || steps.release_notes_remote.outputs.release_notes_file }}" >> $GITHUB_OUTPUT
shell: bash
- name: Create GitHub Release
if: steps.check_repo_name.outputs.should_release == 'true' && steps.check_tag.outputs.tag_exists == 'false'
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.get_version.outputs.tag }}
name: "${{ github.event.repository.name }} ${{ steps.get_version.outputs.version }}"
body_path: ${{ steps.release_notes.outputs.release_notes_file }}
draft: false
prerelease: false
generate_release_notes: false
files: ${{ env.PACKAGE_NAME }}_${{ steps.get_version.outputs.version }}.tar.gz