Build and Publish Docker Image #2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |