Explorar o código

Add github workflow for docker build and push (#1790)

* init gha for docker

* update tag name

* remove test branch/repository

* enhance information
mmacata %!s(int64=3) %!d(string=hai) anos
pai
achega
53a7768cf2

+ 195 - 0
.github/workflows/docker.yml

@@ -0,0 +1,195 @@
+# This workflow builds and pushes docker images to dockerhub
+#
+# Summary
+#
+# job docker-branch-os-matrix:
+# * creates tags latest-alpine, latest-debian and latest-ubuntu for master branch
+# * creates tags stable-alpine, stable-debian and stable-ubuntu for releasebranch_7_8
+# * if action would trigger other branches as well, they would create
+#   tags <branch_name>-alpine, <branch_name>-debian and <branch_name>-ubuntu
+#
+# job docker-master-latest:
+# * creates tag latest for master branch
+#
+# job docker-release-os-matrix:
+# * creates tags <version>-alpine, <version>-debian and <version>-ubuntu for each release
+
+name: Docker
+
+on:
+  push:
+    branches: [master, releasebranch_7_8]
+    tags: ['*.*.*']
+    paths-ignore: ['doc/**']
+  release:
+    types: [published]
+
+env:
+    # Additionally mentioned in docker-sha-release-latest
+    # as use of variable fails there
+    DOCKERHUB_REPOSITORY: mundialis/grass-py3-pdal
+
+jobs:
+
+  # Only run for push to configured branches, do not run for releases.
+  # Take care of different os. For master branch, created tags are:
+  # latest-alpine, latest-debian, latest-ubuntu
+  # For releasebranch_7_8, created tags are:
+  # stable-alpine, stable-debian, stable-ubuntu
+  docker-branch-os-matrix:
+    name: build and push ${{ matrix.os }} for branch
+    if: startsWith(github.ref, 'refs/tags/') != true
+    runs-on: ubuntu-latest
+
+    strategy:
+      matrix:
+        os:
+          - alpine
+          - debian
+          - ubuntu
+      fail-fast: false
+
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v2
+        with:
+          fetch-depth: 0
+      - id: meta
+        name: Create tag name
+        run: |
+          if [ "$GITHUB_REF" == "refs/heads/master" ]
+          then
+            TAG_PREFIX=latest
+          elif [ "$GITHUB_REF" == "refs/heads/releasebranch_7_8" ]
+          then
+            TAG_PREFIX=stable
+          else
+            # use branch name as TAG_PREFIX
+            TAG_PREFIX=`echo $GITHUB_REF|cut -d '/' -f3`
+          fi
+          tag="${DOCKERHUB_REPOSITORY}:${TAG_PREFIX}-${{ matrix.os }}"
+          echo "::set-output name=tags::$tag"
+      - name: Log
+        run: |
+          echo ${{ steps.meta.outputs.tags }}
+      - name: Set up QEMU
+        uses: docker/setup-qemu-action@v1
+      - name: Set up Docker Buildx
+        uses: docker/setup-buildx-action@v1
+      - name: Login to DockerHub
+        uses: docker/login-action@v1
+        with:
+          username: ${{ secrets.DOCKERHUB_USERNAME }}
+          password: ${{ secrets.DOCKERHUB_TOKEN  }}
+      - name: Build and push
+        id: docker_build
+        uses: docker/build-push-action@v2
+        with:
+          push: true
+          pull: true
+          context: .
+          tags: ${{ steps.meta.outputs.tags }}
+          file: docker/${{ matrix.os }}/Dockerfile
+      - name: Image digest
+        run: echo ${{ steps.docker_build.outputs.digest }}
+
+
+  # Only run for push to master branch
+  # Take care of tag latest
+  # This job needs to build the configured image (ubuntu)
+  # again for master branch to create latest tag.
+  docker-master-latest:
+    name: build and push latest for master branch
+    if: startsWith(github.ref, 'refs/heads/master')
+    runs-on: ubuntu-latest
+
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v2
+        with:
+          fetch-depth: 0
+      - id: meta
+        name: Create tag name
+        run: |
+          tag=${DOCKERHUB_REPOSITORY}:latest
+          echo "::set-output name=tags::$tag"
+      - name: Log
+        run: echo ${{ steps.meta.outputs.tags }}
+      - name: Set up QEMU
+        uses: docker/setup-qemu-action@v1
+      - name: Set up Docker Buildx
+        uses: docker/setup-buildx-action@v1
+      - name: Login to DockerHub
+        uses: docker/login-action@v1
+        with:
+          username: ${{ secrets.DOCKERHUB_USERNAME }}
+          password: ${{ secrets.DOCKERHUB_TOKEN  }}
+      - name: Build and push
+        id: docker_build
+        uses: docker/build-push-action@v2
+        with:
+          push: true
+          pull: true
+          context: .
+          tags: ${{ steps.meta.outputs.tags }}
+          file: docker/ubuntu/Dockerfile
+      - name: Image digest
+        run: echo ${{ steps.docker_build.outputs.digest }}
+
+
+  # run for releases, take care of release tags
+  docker-release-os-matrix:
+    name: build and push release for ${{ matrix.os }}
+    if: startsWith(github.ref, 'refs/tags/')
+    runs-on: ubuntu-latest
+    strategy:
+      matrix:
+        os:
+          - alpine
+          - debian
+          - ubuntu
+      fail-fast: false
+
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v2
+        with:
+          fetch-depth: 0
+      - name: Create image and tag name
+        id: meta
+        uses: docker/metadata-action@v3
+        with:
+          # images: ${DOCKERHUB_REPOSITORY}
+          images: mundialis/grass-py3-pdal
+          tags: |
+            type=ref,event=tag
+          flavor: |
+            latest=false
+      - id: meta2
+        name: Update tag name
+        run: |
+          tag="${{ steps.meta.outputs.tags }}-${{ matrix.os }}"
+          echo "::set-output name=tags::$tag"
+      - name: Log
+        run: |
+          echo ${{ steps.meta2.outputs.tags }}
+      - name: Set up QEMU
+        uses: docker/setup-qemu-action@v1
+      - name: Set up Docker Buildx
+        uses: docker/setup-buildx-action@v1
+      - name: Login to DockerHub
+        uses: docker/login-action@v1
+        with:
+          username: ${{ secrets.DOCKERHUB_USERNAME }}
+          password: ${{ secrets.DOCKERHUB_TOKEN  }}
+      - name: Build and push
+        id: docker_build
+        uses: docker/build-push-action@v2
+        with:
+          push: true
+          pull: true
+          context: .
+          tags: ${{ steps.meta2.outputs.tags }}
+          file: docker/${{ matrix.os }}/Dockerfile
+      - name: Image digest
+        run: echo ${{ steps.docker_build.outputs.digest }}

docker/alpine/Dockerfile_alpine → docker/alpine/Dockerfile


+ 2 - 2
docker/alpine/README.md

@@ -17,7 +17,7 @@ __Build the docker with__:
 
 ```bash
 docker build \
-         --file docker/alpine/Dockerfile_alpine \
+         --file docker/alpine/Dockerfile \
          --tag grass-py3-pdal:latest-alpine .
 ```
 
@@ -41,7 +41,7 @@ and build and enter with:
 
 ```bash
 $ docker build \
-         -f docker/alpine/Dockerfile_alpine \
+         -f docker/alpine/Dockerfile \
          -t grass-py3-pdal:stable-alpine .
 
 $ docker run -it grass-py3-pdal:stable-alpine /bin/bash

docker/debian/Dockerfile_debian_pdal → docker/debian/Dockerfile


+ 2 - 2
docker/debian/README.md

@@ -17,7 +17,7 @@ __Build the docker with__:
 
 ```bash
 docker build \
-         --file docker/debian/Dockerfile_debian_pdal \
+         --file docker/debian/Dockerfile \
          --tag grass-py3-pdal:latest-debian .
 ```
 
@@ -40,7 +40,7 @@ and build and enter with:
 
 ```bash
 $ docker build \
-         -f docker/debian/Dockerfile_debian_pdal \
+         -f docker/debian/Dockerfile \
          -t grass-py3-pdal:stable-debian .
 
 $ docker run -it grass-py3-pdal:stable-debian /bin/bash

docker/ubuntu/Dockerfile_ubuntu_pdal → docker/ubuntu/Dockerfile


+ 2 - 2
docker/ubuntu/README.md

@@ -19,7 +19,7 @@ __Build the docker with__:
 
 ```bash
 docker build \
-         --file docker/ubuntu/Dockerfile_ubuntu_pdal \
+         --file docker/ubuntu/Dockerfile \
          --tag grass-py3-pdal:stable-ubuntu .
 ```
 
@@ -43,7 +43,7 @@ and build and enter with:
 
 ```bash
 $ docker build \
-         -f docker/ubuntu/Dockerfile_ubuntu_pdal \
+         -f docker/ubuntu/Dockerfile \
          -t grass-py3-pdal:stable-ubuntu .
 
 $ docker run -it grass-py3-pdal:stable-ubuntu /bin/bash