Browse Source

use action to collect docker tags

Nick Sweeting 4 years ago
parent
commit
4576b40ccb
1 changed files with 20 additions and 33 deletions
  1. 20 33
      .github/workflows/docker.yml

+ 20 - 33
.github/workflows/docker.yml

@@ -1,9 +1,7 @@
 name: Build Docker image
 name: Build Docker image
 
 
 on:
 on:
-  push:
-    branches:
-      - master
+  on: workflow_dispatch
   release:
   release:
     types:
     types:
       - created
       - created
@@ -16,12 +14,6 @@ jobs:
   buildx:
   buildx:
     runs-on: ubuntu-latest
     runs-on: ubuntu-latest
     steps:
     steps:
-      - name: Docker Login
-        uses: docker/login-action@v1
-        with:
-           username: ${{ secrets.DOCKER_USERNAME }}
-           password: ${{ secrets.DOCKER_PASSWORD }}
-      
       - name: Checkout
       - name: Checkout
         uses: actions/checkout@v2
         uses: actions/checkout@v2
         with:
         with:
@@ -51,28 +43,23 @@ jobs:
           key: ${{ runner.os }}-buildx-${{ github.sha }}
           key: ${{ runner.os }}-buildx-${{ github.sha }}
           restore-keys: |
           restore-keys: |
             ${{ runner.os }}-buildx-
             ${{ 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
       - name: Build and push
         id: docker_build
         id: docker_build
@@ -81,11 +68,11 @@ jobs:
           context: ./
           context: ./
           file: ./Dockerfile
           file: ./Dockerfile
           builder: ${{ steps.buildx.outputs.name }}
           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-from: type=local,src=/tmp/.buildx-cache
           cache-to: type=local,dest=/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
       - name: Image digest
         run: echo ${{ steps.docker_build.outputs.digest }}
         run: echo ${{ steps.docker_build.outputs.digest }}