diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 2a85086a..277061d1 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -1,9 +1,7 @@ name: Build Docker image on: - push: - branches: - - master + on: workflow_dispatch release: types: - created @@ -16,12 +14,6 @@ jobs: buildx: runs-on: ubuntu-latest steps: - - name: Docker Login - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - name: Checkout uses: actions/checkout@v2 with: @@ -51,28 +43,23 @@ jobs: key: ${{ runner.os }}-buildx-${{ github.sha }} restore-keys: | ${{ runner.os }}-buildx- - - - name: Prepare tags to publish - id: prep - run: | - # Always publish to latest. - TAGS="${{ secrets.DOCKER_USERNAME }}/archivebox:latest,archivebox/archivebox:latest" - if [[ $GITHUB_REF == refs/tags/* ]]; then - VERSION="${GITHUB_REF#refs/tags/}" - MINOR=${VERSION%.*} - MAJOR=${MINOR%.*} - TAGS="$TAGS,${{ secrets.DOCKER_USERNAME }}/archivebox:$VERSION,archivebox/archivebox:$VERSION" - TAGS="$TAGS,${{ secrets.DOCKER_USERNAME }}/archivebox:$MINOR,archivebox/archivebox:$MINOR" - TAGS="$TAGS,${{ secrets.DOCKER_USERNAME }}/archivebox:$MAJOR,archivebox/archivebox:$MAJOR" - else - VERSION=$GITHUB_SHA - TAGS="$TAGS,${{ secrets.DOCKER_USERNAME }}/archivebox:$VERSION,archivebox/archivebox:$VERSION" - fi - echo ::set-output name=tags::${TAGS} - env: - GITHUB_REF: ${{ github.ref }} - GITHUB_SHA: ${{ github.sha }} + - name: Docker Login + uses: docker/login-action@v1 + if: github.event_name != 'pull_request' + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Collect Docker tags + id: docker_meta + uses: crazy-max/ghaction-docker-meta@v1 + with: + images: archivebox/archivebox,nikisweeting/archivebox + tag-sha: true + tag-semver: | + {{version}} + {{major}}.{{minor}} - name: Build and push id: docker_build @@ -81,11 +68,11 @@ jobs: context: ./ file: ./Dockerfile builder: ${{ steps.buildx.outputs.name }} - push: true - tags: ${{ steps.prep.outputs.tags }} + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.docker_meta.outputs.tags }} cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache - platforms: linux/amd64,linux/arm64,linux/arm/v7 + platforms: linux/amd64,linux/386,linux/arm64,linux/arm/v7 - name: Image digest run: echo ${{ steps.docker_build.outputs.digest }}