Build and Publish Docker Image #22
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: | |
| - master | |
| paths: | |
| - 'Dockerfile.*' | |
| - 'misc/*' | |
| schedule: | |
| - cron: '0 0 * * 0' | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_TOKEN }} | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: Dockerfile.texlive | |
| push: true | |
| tags: maclotsen/texlive:latest | |
| - name: Build and push Docker image (with Google Fonts) | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: Dockerfile.google-fonts | |
| push: true | |
| tags: maclotsen/texlive:with-gf | |
| notify: | |
| needs: build | |
| if: always() | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Compose build status | |
| id: compose | |
| run: | | |
| if [ "${{ needs.build.result }}" = "success" ]; then | |
| echo "status=SUCCESS" >> $GITHUB_OUTPUT | |
| body="Docker images built and pushed successfully.\n\nImages:\n- maclotsen/texlive:latest\n- maclotsen/texlive:with-gf\n\nWorkflow: ${{ github.workflow }}\nRun ID: ${{ github.run_id }}\nRun Number: ${{ github.run_number }}\nRepository: ${{ github.repository }}\nBranch/Ref: ${{ github.ref }}\nCommit: ${{ github.sha }}\nActor: ${{ github.actor }}" | |
| else | |
| echo "status=FAILURE" >> $GITHUB_OUTPUT | |
| body="Docker image build or push failed.\n\nPlease check the workflow run logs for details.\n\nIntended images:\n- maclotsen/texlive:latest\n- maclotsen/texlive:with-gf\n\nWorkflow: ${{ github.workflow }}\nRun ID: ${{ github.run_id }}\nRun Number: ${{ github.run_number }}\nRepository: ${{ github.repository }}\nBranch/Ref: ${{ github.ref }}\nCommit: ${{ github.sha }}\nActor: ${{ github.actor }}" | |
| fi | |
| { | |
| echo "body<<EOF" | |
| echo "$body" | |
| echo "EOF" | |
| } >> $GITHUB_OUTPUT | |
| - name: Add job summary | |
| run: | | |
| echo "## Docker Image Build Status: ${{ steps.compose.outputs.status }}" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "${{ steps.compose.outputs.body }}" >> $GITHUB_STEP_SUMMARY | |
| - name: Send status email | |
| continue-on-error: true | |
| uses: dawidd6/action-send-mail@v3 | |
| with: | |
| server_address: ${{ secrets.SMTP_SERVER }} | |
| server_port: ${{ secrets.SMTP_PORT }} | |
| username: ${{ secrets.SMTP_USERNAME }} | |
| password: ${{ secrets.SMTP_PASSWORD }} | |
| subject: "[XDP Docker] Build maclotsen/texlive images: ${{ steps.compose.outputs.status }}" | |
| to: ${{ secrets.EMAIL_TO }} | |
| from: ${{ secrets.EMAIL_FROM }} | |
| content_type: text/plain | |
| body: ${{ steps.compose.outputs.body }} |