diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a265515..1e85491 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,21 +1,21 @@ -name: Docker Image CI +# name: Docker Image CI -on: - pull_request: - branches: [ "main" ] - paths-ignore: [ "docs/**" ] +# on: +# pull_request: +# branches: [ "main" ] +# paths-ignore: [ "docs/**" ] - push: - paths-ignore: [ "docs/**" ] +# push: +# paths-ignore: [ "docs/**" ] -jobs: - build: - name: CI Build - runs-on: ubuntu-latest +# jobs: +# build: +# name: CI Build +# runs-on: ubuntu-latest - steps: - - name: Checkout Code Repository - uses: actions/checkout@v2 +# steps: +# - name: Checkout Code Repository +# uses: actions/checkout@v2 - - name: Build the Stack - run: docker-compose build +# - name: Build the Stack +# run: docker-compose build diff --git a/.github/workflows/deployment.yml b/.github/workflows/deployment.yml index 63f6881..bcaa672 100644 --- a/.github/workflows/deployment.yml +++ b/.github/workflows/deployment.yml @@ -2,30 +2,80 @@ name: Docker Image Deployment on: push: + branches: ["main"] tags: ["*.*.*"] workflow_dispatch: + pull_request: env: IMAGE_NAME: debian-torproxy jobs: build: - name: Build container image + name: Build + if: github.repository == 'j3lte/debian-torproxy' runs-on: ubuntu-latest + env: + # Define tags to use for Docker images based on Git tags/branches (for docker/metadata-action) + # For a new commit on default branch (master), use the literal tag 'latest' on Docker image. + # For a new commit on other branches, use the branch name as the tag for Docker image. + # For a new tag, copy that tag name as the tag for Docker image. + IMAGE_TAGS: | + type=raw,value=latest,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }},suffix=-debian + type=ref,event=branch,enable=${{ !endsWith(github.ref, github.event.repository.default_branch) }},suffix=-debian + type=ref,event=tag,suffix=-debian + # Define default tag "flavor" for docker/metadata-action per + # https://github.com/docker/metadata-action#flavor-input + # We turn off 'latest' tag by default. + TAGS_FLAVOR: | + latest=false + steps: - - name: Checkout repository + # https://github.com/actions/checkout + - name: Checkout codebase uses: actions/checkout@v2 - - name: Get tag - id: tag - uses: dawidd6/action-get-tag@v1 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + with: + platforms: linux/amd64,linux/arm64,linux/arm/v7 + + # https://github.com/docker/setup-buildx-action + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v2 + - name: Login to image-repository , build and push + if: github.event_name != 'pull_request' uses: docker/login-action@v1 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - run: | - docker build -f ./Dockerfile . -t ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:${{ steps.tag.outputs.tag }} - docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:${{ steps.tag.outputs.tag }} - docker tag ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:${{ steps.tag.outputs.tag }} ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:latest - docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:latest + ############################################### + # Build/Push image + ############################################### + # https://github.com/docker/metadata-action + # Get Metadata for docker_build step below + - name: Sync metadata (tags, labels) from GitHub to Docker for 'debian-torproxy' image + id: meta_build + uses: docker/metadata-action@v3 + with: + images: j3lte/debian-torproxy + tags: ${{ env.IMAGE_TAGS }} + flavor: ${{ env.TAGS_FLAVOR }} + + # https://github.com/docker/build-push-action + - name: Build and push 'debian-torproxy' image + id: docker_build + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + platforms: linux/amd64 + # For pull requests, we run the Docker build (to ensure no PR changes break the build), + # but we ONLY do an image push to DockerHub if it's NOT a PR + push: ${{ github.event_name != 'pull_request' }} + # Use tags / labels provided by 'docker/metadata-action' above + tags: ${{ steps.meta_build.outputs.tags }} + labels: ${{ steps.meta_build.outputs.labels }}