From 798c4a3240a1564326f2360f0a0013e830fcfb71 Mon Sep 17 00:00:00 2001 From: Timo Behrendt Date: Mon, 1 Apr 2024 20:59:18 +0200 Subject: [PATCH 1/6] refactor: CI/CD pipelines --- .gitea/actions/cd-action.yaml | 48 ++++++++++++++++++++++++++++++++ .gitea/actions/ci-action.yaml | 38 +++++++++++++++++++++++++ .gitea/workflows/cd.yaml | 52 +++++++---------------------------- .gitea/workflows/ci.yaml | 37 ++----------------------- 4 files changed, 98 insertions(+), 77 deletions(-) create mode 100644 .gitea/actions/cd-action.yaml create mode 100644 .gitea/actions/ci-action.yaml diff --git a/.gitea/actions/cd-action.yaml b/.gitea/actions/cd-action.yaml new file mode 100644 index 0000000..c55f6d9 --- /dev/null +++ b/.gitea/actions/cd-action.yaml @@ -0,0 +1,48 @@ +name: CD Action + +on: + workflow_call: + secrets: [REGISTRY_USER, REGISTRY_PASSWORD] + inputs: + DOCKER_REGISTRY: + required: true + type: string + +jobs: + build_and_push: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to Registry + uses: docker/login-action@v2 + with: + registry: ${{ input.DOCKER_REGISTRY }} + username: ${{ secrets.REGISTRY_USER }} + password: ${{ secrets.REGISTRY_PASSWORD }} + + - name: Get Metadata + id: meta + run: | + echo REPO_NAME=$(echo ${GITHUB_REPOSITORY} | awk -F"/" '{print $2}' | tr '[:upper:]' '[:lower:]') >> $GITHUB_OUTPUT + echo REPO_VERSION=$(git describe --tags --always | sed 's/^v//') >> $GITHUB_OUTPUT + + - name: Build and push + uses: docker/build-push-action@v4 + with: + context: . + file: ./Dockerfile + platforms: | + linux/amd64 + linux/arm64 + push: true + tags: | + ${{ input.DOCKER_REGISTRY }}/t.behrendt/${{ steps.meta.outputs.REPO_NAME }}:${{ steps.meta.outputs.REPO_VERSION }} + ${{ input.DOCKER_REGISTRY }}/t.behrendt/${{ steps.meta.outputs.REPO_NAME }}:latest diff --git a/.gitea/actions/ci-action.yaml b/.gitea/actions/ci-action.yaml new file mode 100644 index 0000000..ca4fa06 --- /dev/null +++ b/.gitea/actions/ci-action.yaml @@ -0,0 +1,38 @@ +name: CI Action + +on: + workflow_call: + +jobs: + test: + name: test + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + check-latest: true + - name: Create cache key + uses: https://gitea.com/actions/go-hashfiles@v0.0.1 + id: hash-go + with: + patterns: | + go.mod + go.sum + - name: cache go + id: cache-go + uses: actions/cache@v4 + with: + path: | + /go_path + /go_cache + key: go_path-${{ steps.hash-go.outputs.hash }} + restore-keys: |- + go_cache-${{ steps.hash-go.outputs.hash }} + - name: build + run: make build + - name: test + run: make test diff --git a/.gitea/workflows/cd.yaml b/.gitea/workflows/cd.yaml index 5407dda..c5947b4 100644 --- a/.gitea/workflows/cd.yaml +++ b/.gitea/workflows/cd.yaml @@ -1,52 +1,20 @@ name: CD on: - workflow_run: - workflows: - - CI + push: branches: - main - types: - - completed env: DOCKER_REGISTRY: gitea.t000-n.de jobs: - build: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Login to Registry - uses: docker/login-action@v2 - with: - registry: ${{ env.DOCKER_REGISTRY }} - username: ${{ secrets.REGISTRY_USER }} - password: ${{ secrets.REGISTRY_PASSWORD }} - - - name: Get Metadata - id: meta - run: | - echo REPO_NAME=$(echo ${GITHUB_REPOSITORY} | awk -F"/" '{print $2}' | tr '[:upper:]' '[:lower:]') >> $GITHUB_OUTPUT - echo REPO_VERSION=$(git describe --tags --always | sed 's/^v//') >> $GITHUB_OUTPUT - - - name: Build and push - uses: docker/build-push-action@v4 - with: - context: . - file: ./Dockerfile - platforms: | - linux/amd64 - linux/arm64 - push: true - tags: | - ${{ env.DOCKER_REGISTRY }}/t.behrendt/${{ steps.meta.outputs.REPO_NAME }}:${{ steps.meta.outputs.REPO_VERSION }} - ${{ env.DOCKER_REGISTRY }}/t.behrendt/${{ steps.meta.outputs.REPO_NAME }}:latest + test: + uses: ./.gitea/actions/ci-action.yaml + + build_and_push: + uses: ./.gitea/actions/cd-action.yaml + with: + DOCKER_REGISTRY: ${{ env.DOCKER_REGISTRY }} + requires: + - test diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml index 8d5c7d9..cf271da 100644 --- a/.gitea/workflows/ci.yaml +++ b/.gitea/workflows/ci.yaml @@ -1,9 +1,6 @@ name: CI on: pull_request: - push: - branches: - - main env: GOPATH: /go_path @@ -11,35 +8,5 @@ env: RUNNER_TOOL_CACHE: /toolcache jobs: - testing: - name: test - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Setup go - uses: actions/setup-go@v5 - with: - go-version-file: go.mod - check-latest: true - - name: Create cache key - uses: https://gitea.com/actions/go-hashfiles@v0.0.1 - id: hash-go - with: - patterns: | - go.mod - go.sum - - name: cache go - id: cache-go - uses: actions/cache@v4 - with: - path: | - /go_path - /go_cache - key: go_path-${{ steps.hash-go.outputs.hash }} - restore-keys: |- - go_cache-${{ steps.hash-go.outputs.hash }} - - name: build - run: make build - - name: test - run: make test + test: + uses: ./.gitea/actions/ci-action.yaml -- 2.49.1 From 9dc3feecf4c8a7abd7e7825673020141678e19ae Mon Sep 17 00:00:00 2001 From: Timo Behrendt Date: Mon, 1 Apr 2024 21:28:48 +0200 Subject: [PATCH 2/6] fix: workflows referencing actions --- .gitea/workflows/cd.yaml | 12 ++++++++---- .gitea/workflows/ci.yaml | 6 +++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/.gitea/workflows/cd.yaml b/.gitea/workflows/cd.yaml index c5947b4..ef3c9ff 100644 --- a/.gitea/workflows/cd.yaml +++ b/.gitea/workflows/cd.yaml @@ -10,11 +10,15 @@ env: jobs: test: - uses: ./.gitea/actions/ci-action.yaml + runs-on: ubuntu-latest + steps: + - uses: ./.gitea/actions/ci-action.yaml build_and_push: - uses: ./.gitea/actions/cd-action.yaml - with: - DOCKER_REGISTRY: ${{ env.DOCKER_REGISTRY }} + runs-on: ubuntu-latest requires: - test + steps: + - uses: ./.gitea/actions/cd-action.yaml + with: + DOCKER_REGISTRY: ${{ env.DOCKER_REGISTRY }} diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml index cf271da..25860d6 100644 --- a/.gitea/workflows/ci.yaml +++ b/.gitea/workflows/ci.yaml @@ -9,4 +9,8 @@ env: jobs: test: - uses: ./.gitea/actions/ci-action.yaml + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - uses: ./.gitea/actions/ci-action.yaml -- 2.49.1 From 3dac8a1a7ec6acfc2a823690f571a5c25726ccad Mon Sep 17 00:00:00 2001 From: Timo Behrendt Date: Mon, 1 Apr 2024 21:37:34 +0200 Subject: [PATCH 3/6] fix: switch to relative paths referencing local actions --- .gitea/workflows/cd.yaml | 4 ++-- .gitea/workflows/ci.yaml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitea/workflows/cd.yaml b/.gitea/workflows/cd.yaml index ef3c9ff..1518d32 100644 --- a/.gitea/workflows/cd.yaml +++ b/.gitea/workflows/cd.yaml @@ -12,13 +12,13 @@ jobs: test: runs-on: ubuntu-latest steps: - - uses: ./.gitea/actions/ci-action.yaml + - uses: ../actions/ci-action.yaml build_and_push: runs-on: ubuntu-latest requires: - test steps: - - uses: ./.gitea/actions/cd-action.yaml + - uses: ../actions/cd-action.yaml with: DOCKER_REGISTRY: ${{ env.DOCKER_REGISTRY }} diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml index 25860d6..27ad2dc 100644 --- a/.gitea/workflows/ci.yaml +++ b/.gitea/workflows/ci.yaml @@ -12,5 +12,5 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 - - uses: ./.gitea/actions/ci-action.yaml + uses: actions/checkout@v4 + - uses: ../actions/ci-action.yaml -- 2.49.1 From 5e79f01fc43fbe9034b4867c030990b8b5b8460d Mon Sep 17 00:00:00 2001 From: Timo Behrendt Date: Mon, 1 Apr 2024 21:39:22 +0200 Subject: [PATCH 4/6] fix: switch back to absolute paths and move actions into workflow dir --- .gitea/{actions => workflows}/cd-action.yaml | 0 .gitea/workflows/cd.yaml | 4 ++-- .gitea/{actions => workflows}/ci-action.yaml | 0 .gitea/workflows/ci.yaml | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) rename .gitea/{actions => workflows}/cd-action.yaml (100%) rename .gitea/{actions => workflows}/ci-action.yaml (100%) diff --git a/.gitea/actions/cd-action.yaml b/.gitea/workflows/cd-action.yaml similarity index 100% rename from .gitea/actions/cd-action.yaml rename to .gitea/workflows/cd-action.yaml diff --git a/.gitea/workflows/cd.yaml b/.gitea/workflows/cd.yaml index 1518d32..606a873 100644 --- a/.gitea/workflows/cd.yaml +++ b/.gitea/workflows/cd.yaml @@ -12,13 +12,13 @@ jobs: test: runs-on: ubuntu-latest steps: - - uses: ../actions/ci-action.yaml + - uses: ./.gitea/workflows/ci-action.yaml build_and_push: runs-on: ubuntu-latest requires: - test steps: - - uses: ../actions/cd-action.yaml + - uses: ./.gitea/workflows/cd-action.yaml with: DOCKER_REGISTRY: ${{ env.DOCKER_REGISTRY }} diff --git a/.gitea/actions/ci-action.yaml b/.gitea/workflows/ci-action.yaml similarity index 100% rename from .gitea/actions/ci-action.yaml rename to .gitea/workflows/ci-action.yaml diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml index 27ad2dc..e7247eb 100644 --- a/.gitea/workflows/ci.yaml +++ b/.gitea/workflows/ci.yaml @@ -13,4 +13,4 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - - uses: ../actions/ci-action.yaml + - uses: ./.gitea/workflows/cd-action.yaml -- 2.49.1 From 6f7fef20cb984c85b3676fbe7ffc67aad0a44cc3 Mon Sep 17 00:00:00 2001 From: Timo Behrendt Date: Mon, 1 Apr 2024 21:44:13 +0200 Subject: [PATCH 5/6] test: different actions format --- .../{workflows/ci-action.yaml => actions/ci-action/action.yaml} | 0 .gitea/workflows/ci.yaml | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename .gitea/{workflows/ci-action.yaml => actions/ci-action/action.yaml} (100%) diff --git a/.gitea/workflows/ci-action.yaml b/.gitea/actions/ci-action/action.yaml similarity index 100% rename from .gitea/workflows/ci-action.yaml rename to .gitea/actions/ci-action/action.yaml diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml index e7247eb..8484233 100644 --- a/.gitea/workflows/ci.yaml +++ b/.gitea/workflows/ci.yaml @@ -13,4 +13,4 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - - uses: ./.gitea/workflows/cd-action.yaml + - uses: ./.gitea/actions/ci-action -- 2.49.1 From 388d8f6f3ef9c808a2a26e2642121b85acd2d20f Mon Sep 17 00:00:00 2001 From: Timo Behrendt Date: Mon, 1 Apr 2024 21:46:07 +0200 Subject: [PATCH 6/6] refactor: give up on split actions and replicate CI test job in CD pipeline --- .gitea/actions/ci-action/action.yaml | 38 --------------- .gitea/workflows/cd-action.yaml | 48 ------------------- .gitea/workflows/cd.yaml | 71 ++++++++++++++++++++++++++-- .gitea/workflows/ci.yaml | 32 +++++++++++-- 4 files changed, 95 insertions(+), 94 deletions(-) delete mode 100644 .gitea/actions/ci-action/action.yaml delete mode 100644 .gitea/workflows/cd-action.yaml diff --git a/.gitea/actions/ci-action/action.yaml b/.gitea/actions/ci-action/action.yaml deleted file mode 100644 index ca4fa06..0000000 --- a/.gitea/actions/ci-action/action.yaml +++ /dev/null @@ -1,38 +0,0 @@ -name: CI Action - -on: - workflow_call: - -jobs: - test: - name: test - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Setup go - uses: actions/setup-go@v5 - with: - go-version-file: go.mod - check-latest: true - - name: Create cache key - uses: https://gitea.com/actions/go-hashfiles@v0.0.1 - id: hash-go - with: - patterns: | - go.mod - go.sum - - name: cache go - id: cache-go - uses: actions/cache@v4 - with: - path: | - /go_path - /go_cache - key: go_path-${{ steps.hash-go.outputs.hash }} - restore-keys: |- - go_cache-${{ steps.hash-go.outputs.hash }} - - name: build - run: make build - - name: test - run: make test diff --git a/.gitea/workflows/cd-action.yaml b/.gitea/workflows/cd-action.yaml deleted file mode 100644 index c55f6d9..0000000 --- a/.gitea/workflows/cd-action.yaml +++ /dev/null @@ -1,48 +0,0 @@ -name: CD Action - -on: - workflow_call: - secrets: [REGISTRY_USER, REGISTRY_PASSWORD] - inputs: - DOCKER_REGISTRY: - required: true - type: string - -jobs: - build_and_push: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Login to Registry - uses: docker/login-action@v2 - with: - registry: ${{ input.DOCKER_REGISTRY }} - username: ${{ secrets.REGISTRY_USER }} - password: ${{ secrets.REGISTRY_PASSWORD }} - - - name: Get Metadata - id: meta - run: | - echo REPO_NAME=$(echo ${GITHUB_REPOSITORY} | awk -F"/" '{print $2}' | tr '[:upper:]' '[:lower:]') >> $GITHUB_OUTPUT - echo REPO_VERSION=$(git describe --tags --always | sed 's/^v//') >> $GITHUB_OUTPUT - - - name: Build and push - uses: docker/build-push-action@v4 - with: - context: . - file: ./Dockerfile - platforms: | - linux/amd64 - linux/arm64 - push: true - tags: | - ${{ input.DOCKER_REGISTRY }}/t.behrendt/${{ steps.meta.outputs.REPO_NAME }}:${{ steps.meta.outputs.REPO_VERSION }} - ${{ input.DOCKER_REGISTRY }}/t.behrendt/${{ steps.meta.outputs.REPO_NAME }}:latest diff --git a/.gitea/workflows/cd.yaml b/.gitea/workflows/cd.yaml index 606a873..b1d4396 100644 --- a/.gitea/workflows/cd.yaml +++ b/.gitea/workflows/cd.yaml @@ -10,15 +10,76 @@ env: jobs: test: + name: test runs-on: ubuntu-latest steps: - - uses: ./.gitea/workflows/ci-action.yaml + - name: Checkout + uses: actions/checkout@v4 + - name: Setup go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + check-latest: true + - name: Create cache key + uses: https://gitea.com/actions/go-hashfiles@v0.0.1 + id: hash-go + with: + patterns: | + go.mod + go.sum + - name: cache go + id: cache-go + uses: actions/cache@v4 + with: + path: | + /go_path + /go_cache + key: go_path-${{ steps.hash-go.outputs.hash }} + restore-keys: |- + go_cache-${{ steps.hash-go.outputs.hash }} + - name: build + run: make build + - name: test + run: make test + build_and_push: - runs-on: ubuntu-latest + name: Build and push requires: - test + runs-on: ubuntu-latest steps: - - uses: ./.gitea/workflows/cd-action.yaml - with: - DOCKER_REGISTRY: ${{ env.DOCKER_REGISTRY }} + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to Registry + uses: docker/login-action@v2 + with: + registry: ${{ input.DOCKER_REGISTRY }} + username: ${{ secrets.REGISTRY_USER }} + password: ${{ secrets.REGISTRY_PASSWORD }} + + - name: Get Metadata + id: meta + run: | + echo REPO_NAME=$(echo ${GITHUB_REPOSITORY} | awk -F"/" '{print $2}' | tr '[:upper:]' '[:lower:]') >> $GITHUB_OUTPUT + echo REPO_VERSION=$(git describe --tags --always | sed 's/^v//') >> $GITHUB_OUTPUT + + - name: Build and push + uses: docker/build-push-action@v4 + with: + context: . + file: ./Dockerfile + platforms: | + linux/amd64 + linux/arm64 + push: true + tags: | + ${{ input.DOCKER_REGISTRY }}/t.behrendt/${{ steps.meta.outputs.REPO_NAME }}:${{ steps.meta.outputs.REPO_VERSION }} + ${{ input.DOCKER_REGISTRY }}/t.behrendt/${{ steps.meta.outputs.REPO_NAME }}:latest diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml index 8484233..dac1a20 100644 --- a/.gitea/workflows/ci.yaml +++ b/.gitea/workflows/ci.yaml @@ -9,8 +9,34 @@ env: jobs: test: + name: test runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v4 - - uses: ./.gitea/actions/ci-action + - name: Checkout + uses: actions/checkout@v4 + - name: Setup go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + check-latest: true + - name: Create cache key + uses: https://gitea.com/actions/go-hashfiles@v0.0.1 + id: hash-go + with: + patterns: | + go.mod + go.sum + - name: cache go + id: cache-go + uses: actions/cache@v4 + with: + path: | + /go_path + /go_cache + key: go_path-${{ steps.hash-go.outputs.hash }} + restore-keys: |- + go_cache-${{ steps.hash-go.outputs.hash }} + - name: build + run: make build + - name: test + run: make test -- 2.49.1