refactor: remove redundant build stage and streamline Dockerfile #8
This file contains hidden or 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: | |
| push: | |
| branches: | |
| - main | |
| tags: | |
| - 'v*' | |
| workflow_dispatch: | |
| inputs: | |
| pretalx_version: | |
| description: 'pretalx version to build (tag or branch)' | |
| required: false | |
| default: 'main' | |
| repository_dispatch: | |
| types: [build-image] | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: coscup/pretalx | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Determine pretalx version | |
| id: version | |
| run: | | |
| if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then | |
| echo "pretalx_version=${{ github.event.inputs.pretalx_version }}" >> $GITHUB_OUTPUT | |
| elif [[ "${{ github.event_name }}" == "repository_dispatch" ]]; then | |
| echo "pretalx_version=${{ github.event.client_payload.version || 'main' }}" >> $GITHUB_OUTPUT | |
| elif [[ "${{ github.ref }}" == refs/tags/v* ]]; then | |
| echo "pretalx_version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT | |
| else | |
| echo "pretalx_version=main" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Extract metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=ref,event=branch | |
| type=ref,event=tag | |
| type=semver,pattern={{version}} | |
| type=semver,pattern={{major}}.{{minor}} | |
| type=raw,value=latest,enable={{is_default_branch}} | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| build-args: | | |
| PRETALX_VERSION=${{ steps.version.outputs.pretalx_version }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max |