From 690779a526f60ad686136f665f8b1b2e88ded16d Mon Sep 17 00:00:00 2001 From: nicobo Date: Thu, 21 Jan 2021 13:45:01 +0100 Subject: [PATCH] ~ creating a CI workflow to build & push tagged commits --- .../{dockerhub.yml => dockerhub-master.yml} | 9 +- .github/workflows/dockerhub-tag.yml | 131 ++++++++++++++++++ 2 files changed, 135 insertions(+), 5 deletions(-) rename .github/workflows/{dockerhub.yml => dockerhub-master.yml} (94%) create mode 100644 .github/workflows/dockerhub-tag.yml diff --git a/.github/workflows/dockerhub.yml b/.github/workflows/dockerhub-master.yml similarity index 94% rename from .github/workflows/dockerhub.yml rename to .github/workflows/dockerhub-master.yml index e4bf14f..0f9d98d 100644 --- a/.github/workflows/dockerhub.yml +++ b/.github/workflows/dockerhub-master.yml @@ -2,7 +2,7 @@ # Also, more details here : https://github.com/marketplace/actions/build-and-push-docker-images#update-dockerhub-repo-description # -name: Build and publish to Docker Hub +name: Build and publish to Docker Hub (master branch) on: push: @@ -56,7 +56,7 @@ jobs: platforms: linux/arm/v7,linux/arm64,linux/386,linux/amd64 push: true tags: | - nicolabs/nicobot:alpine + nicolabs/nicobot:alpine-dev cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache @@ -73,7 +73,7 @@ jobs: platforms: linux/arm/v7,linux/arm64,linux/386,linux/amd64 push: true tags: | - nicolabs/nicobot:debian + nicolabs/nicobot:debian-dev cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache @@ -90,8 +90,7 @@ jobs: platforms: linux/arm/v7,linux/arm64,linux/386,linux/amd64 push: true tags: | - nicolabs/nicobot:debian-signal - nicolabs/nicobot:latest + nicolabs/nicobot:debian-signal-dev cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache diff --git a/.github/workflows/dockerhub-tag.yml b/.github/workflows/dockerhub-tag.yml new file mode 100644 index 0000000..a824826 --- /dev/null +++ b/.github/workflows/dockerhub-tag.yml @@ -0,0 +1,131 @@ +# Just followed https://docs.docker.com/ci-cd/github-actions/ +# Also, more details here : https://github.com/marketplace/actions/build-and-push-docker-images#update-dockerhub-repo-description +# + +name: Build and publish to Docker Hub (tagged commit) + +on: + push: + tags: + - "v*.*.*" + +jobs: + build-publish: + name: Build, Publish + environment: prod + runs-on: ubuntu-latest + steps: + + - name: Checkout + uses: actions/checkout@v2 + + ############## + # Python is used to get the program's version + # + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.x' + + - name: Get program's version + run: | + # Prints Python version + python -c "import sys; print(sys.version)" + python -m pip install --upgrade pip + pip install -r requirements-build.txt + echo NICOBOT_VERSION=$(python setup.py --version) >> $GITHUB_ENV + + # + ############## + + - name: Docker meta + id: docker_meta + uses: crazy-max/ghaction-docker-meta@v1 + with: + images: name/app # list of Docker images to use as base name for tags + tag-sha: true # add git short SHA as Docker tag + + - name: Set up QEMU for multiarch + uses: docker/setup-qemu-action@v1 + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + + - name: Cache Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + + - name: Build and push alpine + id: docker_build_alpine + uses: docker/build-push-action@v2 + with: + context: ./ + file: ./alpine.Dockerfile + builder: ${{ steps.buildx.outputs.name }} + platforms: linux/arm/v7,linux/arm64,linux/386,linux/amd64 + push: true + tags: | + nicolabs/nicobot:alpine + nicolabs/nicobot:alpine-${{ env.NICOBOT_VERSION }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + + - name: Image digest + run: echo ${{ steps.docker_build_alpine.outputs.digest }} + + - name: Build and push debian + id: docker_build_debian + uses: docker/build-push-action@v2 + with: + context: ./ + file: ./debian.Dockerfile + builder: ${{ steps.buildx.outputs.name }} + platforms: linux/arm/v7,linux/arm64,linux/386,linux/amd64 + push: true + tags: | + nicolabs/nicobot:debian + nicolabs/nicobot:debian-${{ env.NICOBOT_VERSION }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + + - name: Image digest + run: echo ${{ steps.docker_build_debian.outputs.digest }} + + - name: Build and push debian-signal + id: docker_build_debian_signal + uses: docker/build-push-action@v2 + with: + context: ./ + file: ./debian-signal.Dockerfile + builder: ${{ steps.buildx.outputs.name }} + platforms: linux/arm/v7,linux/arm64,linux/386,linux/amd64 + push: true + tags: | + nicolabs/nicobot:debian-signal + nicolabs/nicobot:debian-signal-${{ env.NICOBOT_VERSION }} + nicolabs/nicobot:latest + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + + - name: Image digest + run: echo ${{ steps.docker_build_debian_signal.outputs.digest }} + + # https://github.com/marketplace/actions/build-and-push-docker-images#update-dockerhub-repo-description + - name: Update repo description + uses: peter-evans/dockerhub-description@v2 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_PASSWORD }} + repository: nicolabs/nicobot