name: Docker Build & Push
on:
push:
branches: [main]
pull_request:
branches: [main]
types: [opened, synchronize, reopened]
jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with:
persist-credentials: false
- name: Log in to Docker Hub
if: github.event_name != 'pull_request' || (github.event.pull_request.head.repo.full_name == github.repository && github.event.pull_request.user.login != 'dependabot[bot]')
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f with:
username: ${{ vars.DOCKER_USER }}
password: ${{ secrets.DOCKER_PAT }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c - name: Set image tag
id: image
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
echo "tag=neuromod:pr-${{ github.sha }}" >> "$GITHUB_OUTPUT"
else
echo "tag=${{ vars.DOCKER_USER }}/neuromod:${{ github.sha }}" >> "$GITHUB_OUTPUT"
fi
- name: Build and push
uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a with:
context: .
load: ${{ github.event_name == 'pull_request' }}
tags: ${{ steps.image.outputs.tag }}
outputs: ${{ github.event_name == 'pull_request' && 'type=docker' || 'type=registry' }}
- name: Verify image builds example binary
if: github.event_name == 'pull_request'
run: |
docker run --rm "${{ steps.image.outputs.tag }}" ls /usr/local/bin/