Skip to content

2024.08.08

2024.08.08 #58

name: Image Build and Push
env:
IMAGE_NAME: ${{ github.repository }}
on:
pull_request:
push:
branches:
- main
release:
types:
- created
jobs:
python:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Get version number for tagging the image
id: get_version
run: |
git fetch --all --tags
echo "VERSION=$(git describe --tags)" >> $GITHUB_OUTPUT
- name: Build and don't push
if: github.event_name == 'pull_request'
uses: docker/build-push-action@v5
with:
context: python
push: false
tags: ghcr.io/${{ env.IMAGE_NAME }}:test
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Log in to the Container registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: "ghcr.io"
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
if: github.event_name != 'pull_request'
uses: docker/build-push-action@v5
with:
context: python
push: true
tags: ghcr.io/${{ env.IMAGE_NAME }}:${{ steps.get_version.outputs.VERSION }},ghcr.io/${{ env.IMAGE_NAME }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max