From 456658a96c71df66850b232ea71d8d6626c23937 Mon Sep 17 00:00:00 2001 From: Mirko Milovanovic Date: Sun, 9 Feb 2025 15:20:33 +0000 Subject: [PATCH] (feat:) CI-CD workflow for building and pushing Docker images (#2) Reviewed-on: https://gitea.kobim.cloud/kobim/peertube-collector/pulls/2 Co-authored-by: Mirko Milovanovic Co-committed-by: Mirko Milovanovic --- .../setup-docker-environment/action.yml | 14 ++++++++ .github/workflows/feature-pr-build.yml | 27 ++++++++++++++ .github/workflows/main.yml | 36 +++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 .github/actions/setup-docker-environment/action.yml create mode 100644 .github/workflows/feature-pr-build.yml create mode 100644 .github/workflows/main.yml diff --git a/.github/actions/setup-docker-environment/action.yml b/.github/actions/setup-docker-environment/action.yml new file mode 100644 index 0000000..7cce6cf --- /dev/null +++ b/.github/actions/setup-docker-environment/action.yml @@ -0,0 +1,14 @@ +name: "Setup Docker Environment" +description: "Common steps for setting up Docker build environment (checkout, QEMU, and Buildx)" + +runs: + using: "composite" + steps: + - name: Checkout repository + uses: actions/checkout@v4.2.2 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3.4.0 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3.9.0 diff --git a/.github/workflows/feature-pr-build.yml b/.github/workflows/feature-pr-build.yml new file mode 100644 index 0000000..e68eda6 --- /dev/null +++ b/.github/workflows/feature-pr-build.yml @@ -0,0 +1,27 @@ +name: Build Docker Image for Pull Request + +on: + pull_request: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository actions + uses: actions/checkout@v2 + + - name: Setup Docker Environment + uses: ./.github/actions/setup-docker-environment + + - name: Build Docker image + uses: docker/build-push-action@v6.13.0 + with: + context: . + push: false + tags: ${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ github.event.pull_request.number }} + platforms: | + linux/amd64 + linux/arm64 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..5a7d451 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,36 @@ +name: Build and Push Docker Image + +on: + push: + branches: + - main + +env: + REGISTRY_URL: gitea.kobim.cloud + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout repository actions + uses: actions/checkout@v2 + + - name: Setup Docker Environment + uses: ./.github/actions/setup-docker-environment + + - name: Log in to Docker registry + uses: docker/login-action@v3.3.0 + with: + registry: ${{ env.REGISTRY_URL }} + username: ${{ github.actor }} + password: ${{ secrets.REGISTRY_TOKEN }} + + - name: Build and push Docker image + uses: docker/build-push-action@v6.13.0 + with: + context: . + push: true + tags: ${{ env.REGISTRY_URL }}/${{ github.repository_owner }}/${{ github.event.repository.name }}:latest + platforms: | + linux/amd64 + linux/arm64 \ No newline at end of file