-
Notifications
You must be signed in to change notification settings - Fork 10
191 lines (173 loc) · 7.31 KB
/
docker-image.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
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
name: Docker Image CI
on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:
push:
branches: [ "master" ]
paths-ignore:
- '**/README.md'
- 'Ubuntu/**'
- '.github/**'
- '.gitattributes'
- '.gitignore'
jobs:
fetch-latest-tags:
runs-on: ubuntu-latest
outputs:
PGAGENT_TAG: ${{ env.PGAGENT_TAG }}
SYS_STATS_TAG: ${{ env.SYS_STATS_TAG }}
ZILEAN_TAG: ${{ env.ZILEAN_TAG }}
RIVEN_TAG: ${{ env.RIVEN_TAG }}
RIVEN_FRONTEND_TAG: ${{ env.RIVEN_FRONTEND_TAG }}
steps:
- name: Fetch latest pgAgent release tag
run: |
PGAGENT_TAG=$(curl -s https://api.github.com/repos/pgadmin-org/pgagent/releases/latest | jq -r .tag_name)
echo "PGAGENT_TAG=$PGAGENT_TAG" >> $GITHUB_ENV
- name: Fetch latest system_stats release tag
run: |
SYS_STATS_TAG=$(curl -s https://api.github.com/repos/EnterpriseDB/system_stats/releases/latest | jq -r .tag_name)
echo "SYS_STATS_TAG=$SYS_STATS_TAG" >> $GITHUB_ENV
- name: Fetch latest zilean release tag
run: |
ZILEAN_TAG=$(curl -s https://api.github.com/repos/iPromKnight/zilean/releases/latest | jq -r .tag_name)
echo "ZILEAN_TAG=$ZILEAN_TAG" >> $GITHUB_ENV
- name: Fetch latest riven release tag
run: |
RIVEN_TAG=$(curl -s https://api.github.com/repos/rivenmedia/riven/releases/latest | jq -r .tag_name)
echo "RIVEN_TAG=$RIVEN_TAG" >> $GITHUB_ENV
- name: Fetch latest riven-frontend release tag
run: |
RIVEN_FRONTEND_TAG=$(curl -s https://api.github.com/repos/rivenmedia/riven-frontend/releases/latest | jq -r .tag_name)
echo "RIVEN_FRONTEND_TAG=$RIVEN_FRONTEND_TAG" >> $GITHUB_ENV
build-and-push:
needs: fetch-latest-tags
runs-on: self-hosted
outputs:
version: ${{ env.VERSION }}
repo_owner_lower: ${{ env.REPO_OWNER_LOWER }}
repo_name: ${{ env.REPO_NAME }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: 'all'
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Clean up unused Docker images and containers
run: docker system prune --all --force --volumes
- name: Pre-Build Disk Space
run: |
echo "Disk space before build:"
df -h
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Extract version and set environment variables
id: setup_env_vars
run: |
VERSION=$(grep -Po '(?<=version = ")[^"]+' main.py)
REPO_OWNER_LOWER=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
REPO_NAME=$(basename "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "REPO_OWNER_LOWER=$REPO_OWNER_LOWER" >> $GITHUB_ENV
echo "REPO_NAME=$REPO_NAME" >> $GITHUB_ENV
echo "version=$VERSION" >> $GITHUB_ENV
echo "repo_owner_lower=$REPO_OWNER_LOWER" >> $GITHUB_ENV
echo "repo_name=$REPO_NAME" >> $GITHUB_ENV
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Push Docker image
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
platforms: linux/amd64, linux/arm64 #, linux/arm/v7
cache-from: type=gha,scope=build
cache-to: type=gha,scope=build,mode=max
tags: |
${{ secrets.DOCKER_USERNAME }}/${{ env.REPO_NAME }}:${{ env.VERSION }}
${{ secrets.DOCKER_USERNAME }}/${{ env.REPO_NAME }}:latest
ghcr.io/${{ env.REPO_OWNER_LOWER }}/${{ env.REPO_NAME }}:${{ env.VERSION }}
ghcr.io/${{ env.REPO_OWNER_LOWER }}/${{ env.REPO_NAME }}:latest
build-args: |
PGAGENT_TAG=${{ needs.fetch-latest-tags.outputs.PGAGENT_TAG }}
SYS_STATS_TAG=${{ needs.fetch-latest-tags.outputs.SYS_STATS_TAG }}
ZILEAN_TAG=${{ needs.fetch-latest-tags.outputs.ZILEAN_TAG }}
RIVEN_TAG=${{ needs.fetch-latest-tags.outputs.RIVEN_TAG }}
RIVEN_FRONTEND_TAG=${{ needs.fetch-latest-tags.outputs.RIVEN_FRONTEND_TAG }}
push: true
release:
needs: build-and-push
runs-on: ubuntu-latest
outputs:
release_exists: ${{ steps.check_release.outputs.release_exists }}
env:
VERSION: ${{ needs.build-and-push.outputs.version }}
REPO_OWNER_LOWER: ${{ needs.build-and-push.outputs.repo_owner_lower }}
REPO_NAME: ${{ needs.build-and-push.outputs.repo_name }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Check if Release Exists
id: check_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ env.VERSION }}
run: |
if gh release view "${{ env.VERSION }}" --repo ${{ github.repository }}; then
echo "Release already exists for version ${{ needs.build-and-push.outputs.version }}"
echo "release_exists=true" >> $GITHUB_ENV
echo "release_exists=true" >> $GITHUB_OUTPUT
else
echo "Release does not exist for version ${{ needs.build-and-push.outputs.version }}"
echo "release_exists=false" >> $GITHUB_ENV
echo "release_exists=false" >> $GITHUB_OUTPUT
fi
- name: Create Release with CHANGELOG Notes
if: env.release_exists == 'false'
id: create_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
RELEASE_NOTES=$(awk '/^## Version \[${{ env.VERSION }}\]/ {flag=1; next} /^## Version \[/ {flag=0} flag' CHANGELOG.md)
gh release create ${{ env.VERSION }} \
--repo ${{ github.repository }} \
--title "Release ${{ env.VERSION }}" \
--notes "$RELEASE_NOTES" \
--draft=false \
--prerelease=false
announce:
needs: [release, build-and-push]
if: needs.release.outputs.release_exists == 'false'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Post announcement to Discord
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}
VERSION: ${{ needs.build-and-push.outputs.version }}
run: |
RELEASE_NOTES=$(awk '/^## Version \[${{ env.VERSION }}\]/ {flag=1; next} /^## Version \[/ {flag=0} flag' CHANGELOG.md)
ANNOUNCEMENT_BODY="🚀 **New Release: Version [${{ env.VERSION }}]**${RELEASE_NOTES}"
ESCAPED_BODY=$(echo "$ANNOUNCEMENT_BODY" | jq -Rsa .)
curl -H "Content-Type: application/json" \
-d "{\"content\": $ESCAPED_BODY, \"flags\": 4}" \
$DISCORD_WEBHOOK_URL