-
Notifications
You must be signed in to change notification settings - Fork 1
73 lines (62 loc) · 2.44 KB
/
docker-build.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
name: Build and Publish Docker Image
on:
schedule:
- cron: "0 0 * * *" # Runs daily at midnight UTC
workflow_dispatch: # Allows manual triggering
jobs:
build-and-publish:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Get latest release tag and check for new release
id: check_release
run: |
RELEASE_TAG=$(curl -s https://api.github.com/repos/get-convex/convex-backend/releases/latest | grep "tag_name" | cut -d\" -f4)
echo "RELEASE_TAG=$RELEASE_TAG" >> $GITHUB_ENV
PREVIOUS_TAG=$(docker inspect ghcr.io/${{ github.repository }}:latest --format '{{ index .Config.Labels "org.opencontainers.image.version" }}' || echo "none")
if [ -z "$PREVIOUS_TAG" ]; then
echo "No previous image found. Proceeding with the build of release: $RELEASE_TAG."
elif [ "$RELEASE_TAG" == "$PREVIOUS_TAG" ]; then
echo "No new release detected. Exiting."
exit 0
else
echo "New release detected: $RELEASE_TAG"
fi
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Docker 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@v5
with:
context: .
push: true
tags: |
ghcr.io/${{ github.repository }}:$RELEASE_TAG
ghcr.io/${{ github.repository }}:latest
platforms: linux/amd64,linux/arm64
build-args: |
RELEASE_TAG=$RELEASE_TAG
labels: |
org.opencontainers.image.version=$RELEASE_TAG
- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.RELEASE_TAG }}
release_name: "Release ${{ env.RELEASE_TAG }}"
body: |
New Docker images have been built and are available at the following locations:
- `ghcr.io/${{ github.repository }}:${{ env.RELEASE_TAG }}`
- `ghcr.io/${{ github.repository }}:latest`
draft: false
prerelease: false
- name: Post build cleanup
run: docker system prune -f