From ca54c427496e3d7cd88fc919c9407183544263ff Mon Sep 17 00:00:00 2001 From: Kaan Yagci Date: Mon, 25 Mar 2024 19:13:16 +0100 Subject: [PATCH] chore(gha): add Docker build and publish workflow Signed-off-by: Kaan Yagci --- .../workflows/build_and_push_docker_image.yml | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 .github/workflows/build_and_push_docker_image.yml diff --git a/.github/workflows/build_and_push_docker_image.yml b/.github/workflows/build_and_push_docker_image.yml new file mode 100644 index 0000000..cdfca98 --- /dev/null +++ b/.github/workflows/build_and_push_docker_image.yml @@ -0,0 +1,74 @@ +name: Build and Push Docker Image + +on: + push: + branches: + - main + paths: + - 'Dockerfile' + - '.github/workflows/build_and_push_docker_image.yml' + + pull_request: + branches: + - main + types: + - opened + - synchronize + - reopened + paths: + - 'Dockerfile' + - '.github/workflows/build_and_push_docker_image.yml' + +concurrency: + group: "${{ github.workflow }}-${{ github.ref_name }}-${{ github.event_name }}" + cancel-in-progress: true + +jobs: + build-and-push: + runs-on: ubuntu-latest + strategy: + matrix: + DEBIAN_TAG: ["trixie", "trixie-slim", "bullseye", "bullseye-slim", "buster", "buster-slim", "bookworm-slim", "bookworm"] + OPENCV_VERSION: ["4.9.0", "4.8.1", "4.8.0", "4.7.0" ] + # OPENCV_VERSION: ["4.9.0", "4.8.1", "4.8.0", "4.7.0", "4.6.0", "4.5.5", "4.5.4", "4.5.3", "4.5.2", "4.5.1", "4.5.0", "4.4.0", "4.3.0", "4.2.0", "4.1.2", "4.1.1", "4.1.0", "4.0.1", "4.0.0"] + GO_VERSION: ["1.22.1", "1.22.0", "1.21.8", "1.21.7", "1.21.6", "1.21.5", "1.21.4", "1.21.3"] + steps: + - name: Checkout Repo + uses: actions/checkout@v4.1.2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3.2.0 + + - name: Login to DockerHub + if: github.event_name == 'push' + uses: docker/login-action@v3.1.0 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + + - name: Build Docker image + uses: docker/build-push-action@v5.3.0 + with: + context: . + file: Dockerfile + load: true # Change to load for PRs, no push + tags: makepad/go-opencv:${{ matrix.DEBIAN_TAG }}-${{ matrix.OPENCV_VERSION }} + build-args: | + DEBIAN_TAG=${{ matrix.DEBIAN_TAG }} + OPENCV_VERSION=${{ matrix.OPENCV_VERSION }} + GO_VERSION=${{matrix.GO_VERSION}} + + - name: Push Docker image + if: github.event_name == 'push' + uses: docker/build-push-action@v5.3.0 + with: + context: . + file: Dockerfile + push: true + tags: makepad/go-opencv:${{ matrix.DEBIAN_TAG }}-opencv-${{ matrix.OPENCV_VERSION }}-go${{ matrix.GO_VERSION }} + build-args: | + DEBIAN_TAG=${{ matrix.DEBIAN_TAG }} + OPENCV_VERSION=${{ matrix.OPENCV_VERSION }} + GO_VERSION=${{matrix.GO_VERSION}} + cache-from: type=registry,ref=makepad/opencv:${{ matrix.DEBIAN_TAG }}-opencv-${{ matrix.OPENCV_VERSION }}-go-${{ matrix.GO_VERSION }} + cache-to: type=inline