From f6aefb32c2fe41a51dac47341f970b5ec8b74369 Mon Sep 17 00:00:00 2001 From: MarkBzm Date: Wed, 16 Apr 2025 18:34:36 +0300 Subject: [PATCH 1/3] init ci --- .github/workflows/ci.yml | 67 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..0dcc7fe --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,67 @@ +name: CI Pipeline + +on: + push: + branches: [ ci ] + +jobs: + test: + name: Run Tests + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.21' + cache: true + + - name: Install dependencies + run: | + cd gin-api + go mod download + + - name: Run tests + run: | + cd gin-api + go test ./... + + - name: Run test coverage + run: | + cd gin-api + go test -cover ./... + + build: + name: Build Docker Image + runs-on: ubuntu-latest + needs: test + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Build backend image + uses: docker/build-push-action@v4 + with: + context: ./gin-api + file: ./gin-api/Dockerfile + push: false + tags: sviper-backend:latest + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Build seeder image + uses: docker/build-push-action@v4 + with: + context: ./gin-api + file: ./gin-api/Dockerfile.seeder + push: false + tags: sviper-seeder:latest + cache-from: type=gha + cache-to: type=gha,mode=max From d6b1c90ff249c4ea01e6cfe0a2fb78303774176b Mon Sep 17 00:00:00 2001 From: MarkBzm Date: Wed, 16 Apr 2025 18:43:05 +0300 Subject: [PATCH 2/3] add config dir --- gin-api/config/stub | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 gin-api/config/stub diff --git a/gin-api/config/stub b/gin-api/config/stub new file mode 100644 index 0000000..e69de29 From b7a8ed6a95dc6c270a922750855fe850f54f4a0a Mon Sep 17 00:00:00 2001 From: MarkBzm Date: Wed, 16 Apr 2025 20:07:16 +0300 Subject: [PATCH 3/3] pushing gin-api to GH CR --- .github/workflows/ci.yml | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0dcc7fe..dbd102e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,7 +2,9 @@ name: CI Pipeline on: push: - branches: [ ci ] + branches: [ "cd" ] + pull_request: + branches: [ main, master ] jobs: test: @@ -35,9 +37,12 @@ jobs: go test -cover ./... build: - name: Build Docker Image + name: Build and Push Docker Images runs-on: ubuntu-latest needs: test + permissions: + contents: read + packages: write steps: - name: Checkout code @@ -46,13 +51,32 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 - - name: Build backend image + - name: Login to GitHub Container Registry + if: github.event_name != 'pull_request' + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract backend metadata + id: meta-backend + uses: docker/metadata-action@v4 + with: + images: ghcr.io/${{ github.repository_owner }}/backend + tags: | + type=ref,event=branch + type=ref,event=pr + type=sha,format=short + + - name: Build and push backend image uses: docker/build-push-action@v4 with: context: ./gin-api file: ./gin-api/Dockerfile - push: false - tags: sviper-backend:latest + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta-backend.outputs.tags }} + labels: ${{ steps.meta-backend.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max