ci: add Forgejo build and deployment workflows
This commit is contained in:
parent
abb207d608
commit
d3ee64282d
4 changed files with 181 additions and 155 deletions
|
|
@ -1,58 +1,41 @@
|
|||
name: CI/CD
|
||||
name: Build, test, publish, deploy
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main, develop]
|
||||
tags: ['v*']
|
||||
pull_request:
|
||||
branches: [main, develop]
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
REGISTRY: nexus-registry.urpi.be
|
||||
GO_VERSION: "1.27.1"
|
||||
REGISTRY: nexus.urpi.be
|
||||
IMAGE_NAME: docker-hosted/go-loose
|
||||
GO_VERSION: '1.27.1'
|
||||
|
||||
jobs:
|
||||
build-and-test:
|
||||
name: Build and Test
|
||||
build-test:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v5
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: ${{ env.GO_VERSION }}
|
||||
go-version-file: go.mod
|
||||
cache: true
|
||||
|
||||
- name: Download dependencies
|
||||
run: go mod download
|
||||
|
||||
- name: Build
|
||||
run: go build ./...
|
||||
|
||||
- name: Run unit tests
|
||||
run: go test -race ./... -count=1
|
||||
|
||||
- name: Run vet
|
||||
run: go vet ./...
|
||||
|
||||
- name: Check formatting
|
||||
- name: Build and test Go service
|
||||
run: |
|
||||
if [ "$(gofmt -l . | grep -v vendor | grep -v dist | wc -l)" -gt 0 ]; then
|
||||
echo "Code is not formatted:"
|
||||
gofmt -l . | grep -v vendor | grep -v dist
|
||||
exit 1
|
||||
fi
|
||||
go mod download
|
||||
go vet ./...
|
||||
go test -race ./... -count=1
|
||||
go build ./...
|
||||
- uses: azure/setup-helm@v4
|
||||
with:
|
||||
version: v3.18.6
|
||||
- name: Validate production chart
|
||||
run: |
|
||||
helm dependency build deploy/helm/go-loose
|
||||
helm lint deploy/helm/go-loose -f deploy/helm/go-loose/values-prd.yaml
|
||||
|
||||
integration-test:
|
||||
name: Integration Tests
|
||||
runs-on: ubuntu-latest
|
||||
needs: build-and-test
|
||||
needs: build-test
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:17-alpine
|
||||
|
|
@ -60,151 +43,71 @@ jobs:
|
|||
POSTGRES_DB: goloose
|
||||
POSTGRES_USER: goloose
|
||||
POSTGRES_PASSWORD: goloose
|
||||
ports: ['5432:5432']
|
||||
ports: [5432:5432]
|
||||
options: >-
|
||||
--health-cmd="pg_isready -U goloose -d goloose"
|
||||
--health-interval=5s
|
||||
--health-timeout=3s
|
||||
--health-retries=10
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v5
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: ${{ env.GO_VERSION }}
|
||||
go-version-file: go.mod
|
||||
cache: true
|
||||
|
||||
- name: Download dependencies
|
||||
run: go mod download
|
||||
|
||||
- name: Create test databases
|
||||
- name: Run database-backed tests
|
||||
env:
|
||||
PGPASSWORD: goloose
|
||||
GO_LOOSE_TEST_DATABASE_URL: postgres://goloose:goloose@localhost:5432/goloose_test?sslmode=disable
|
||||
GO_LOOSE_TEST_SERVER_DATABASE_URL: postgres://goloose:goloose@localhost:5432/goloose_server_test?sslmode=disable
|
||||
GO_LOOSE_BEHAVIOUR_DATABASE_URL: postgres://goloose:goloose@localhost:5432/goloose_behaviour_test?sslmode=disable
|
||||
run: |
|
||||
sleep 5
|
||||
createdb -h localhost -U goloose goloose_test || true
|
||||
createdb -h localhost -U goloose goloose_server_test || true
|
||||
createdb -h localhost -U goloose goloose_behaviour_test || true
|
||||
|
||||
- name: Run integration tests
|
||||
env:
|
||||
GO_LOOSE_TEST_DATABASE_URL: postgres://goloose:goloose@localhost:5432/goloose_test?sslmode=disable
|
||||
GO_LOOSE_TEST_SERVER_DATABASE_URL: postgres://goloose:goloose@localhost:5432/goloose_server_test?sslmode=disable
|
||||
GO_LOOSE_BEHAVIOUR_DATABASE_URL: postgres://goloose:goloose@localhost:5432/goloose_behaviour_test?sslmode=disable
|
||||
run: |
|
||||
go test -race ./internal/store/ ./internal/server/ -count=1
|
||||
GO_LOOSE_BEHAVIOUR=1 go test ./internal/behaviour/ -count=1 -v
|
||||
|
||||
docker:
|
||||
name: Build and Push Docker Image
|
||||
publish:
|
||||
if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || (github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main')
|
||||
needs: [build-test, integration-test]
|
||||
runs-on: ubuntu-latest
|
||||
needs: [build-and-test, integration-test]
|
||||
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Log in to Nexus Registry
|
||||
uses: docker/login-action@v3
|
||||
- uses: actions/checkout@v4
|
||||
- uses: docker/setup-buildx-action@v3
|
||||
- uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ secrets.NEXUS_USERNAME }}
|
||||
password: ${{ secrets.NEXUS_PASSWORD }}
|
||||
|
||||
- name: Extract metadata for Docker
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||
tags: |
|
||||
type=ref,event=branch
|
||||
type=ref,event=pr
|
||||
type=semver,pattern={{version}}
|
||||
type=semver,pattern={{major}}.{{minor}}
|
||||
type=sha
|
||||
|
||||
- name: Build and push Docker image
|
||||
uses: docker/build-push-action@v5
|
||||
- uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
file: Dockerfile
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
|
||||
# deploy-tst:
|
||||
# name: Deploy to TST
|
||||
# runs-on: ubuntu-latest
|
||||
# needs: docker
|
||||
# if: github.event_name == 'push' && github.ref == 'refs/heads/develop'
|
||||
# permissions:
|
||||
# contents: read
|
||||
# id-token: write
|
||||
# environment: tst
|
||||
#
|
||||
# steps:
|
||||
# - name: Checkout repository
|
||||
# uses: actions/checkout@v4
|
||||
#
|
||||
# - name: Set up Helm
|
||||
# uses: azure/setup-helm@v4
|
||||
# with:
|
||||
# version: 'v3.14.0'
|
||||
#
|
||||
# - name: Set up kubectl
|
||||
# uses: azure/k8s-set-context@v4
|
||||
# with:
|
||||
# kubeconfig: ${{ secrets.KUBECONFIG_TST }}
|
||||
#
|
||||
# - name: Deploy to TST with Helm
|
||||
# run: |
|
||||
# helm upgrade --install go-loose ./deploy/helm/go-loose \
|
||||
# --namespace go-loose \
|
||||
# --create-namespace \
|
||||
# --set image.repository=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} \
|
||||
# --set image.tag=${{ github.sha }} \
|
||||
# --set image.pullSecrets[0].name=nexus-registry \
|
||||
# --wait --timeout 5m
|
||||
tags: |
|
||||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
|
||||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
|
||||
|
||||
deploy-prd:
|
||||
name: Deploy to PRD
|
||||
if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || (github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main')
|
||||
needs: publish
|
||||
runs-on: ubuntu-latest
|
||||
needs: docker
|
||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
|
||||
permissions:
|
||||
contents: read
|
||||
id-token: write
|
||||
environment: prd
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Helm
|
||||
uses: azure/setup-helm@v4
|
||||
- uses: actions/checkout@v4
|
||||
- uses: azure/setup-helm@v4
|
||||
with:
|
||||
version: 'v3.14.0'
|
||||
|
||||
- name: Set up kubectl
|
||||
uses: azure/k8s-set-context@v4
|
||||
version: v3.18.6
|
||||
- uses: azure/setup-kubectl@v4
|
||||
with:
|
||||
kubeconfig: ${{ secrets.KUBECONFIG_PRD }}
|
||||
|
||||
- name: Deploy to PRD with Helm
|
||||
version: v1.32.2
|
||||
- name: Bootstrap resources and deploy go-loose
|
||||
env:
|
||||
KUBECONFIG_PRD: ${{ secrets.KUBECONFIG_PRD }}
|
||||
NEXUS_USERNAME: ${{ secrets.NEXUS_USERNAME }}
|
||||
NEXUS_PASSWORD: ${{ secrets.NEXUS_PASSWORD }}
|
||||
run: |
|
||||
helm upgrade --install go-loose ./deploy/helm/go-loose \
|
||||
--namespace go-loose \
|
||||
--create-namespace \
|
||||
--values ./deploy/helm/go-loose/values-prd.yaml \
|
||||
--set image.repository=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} \
|
||||
--set image.tag=${{ github.ref_name }} \
|
||||
--wait --timeout 5m
|
||||
set -Eeuo pipefail
|
||||
bash .forgejo/scripts/deploy-prd.sh deploy/helm/go-loose go-loose go-loose "${{ github.sha }}" \
|
||||
--set-string ingress.className=nginx
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue