diff --git a/.github/workflows/auth-gateway.yml b/.github/workflows/auth-gateway.yml index c7329c7..a9b2d04 100644 --- a/.github/workflows/auth-gateway.yml +++ b/.github/workflows/auth-gateway.yml @@ -7,31 +7,22 @@ on: - apps/auth/services/gateway/** - go.mod - go.sum - -env: - IMAGE: homelab/auth-gateway + pull_request: + paths: + - apps/auth/services/gateway/** + - go.mod + - go.sum jobs: - build-and-deploy: - runs-on: self-hosted + test: + runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Build image - run: | - docker build \ - -t ${{ env.IMAGE }}:${{ github.sha }} \ - -t ${{ env.IMAGE }}:latest \ - -f apps/auth/services/gateway/Dockerfile \ - . + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod - - name: Import image into k3d - run: k3d image import ${{ env.IMAGE }}:${{ github.sha }} -c homelab - - - name: Deploy - run: | - kubectl set image deployment/gateway \ - gateway=${{ env.IMAGE }}:${{ github.sha }} \ - -n auth - kubectl rollout status deployment/gateway -n auth --timeout=120s + - name: Test + run: go test ./apps/auth/services/gateway/... diff --git a/.github/workflows/auth-users.yml b/.github/workflows/auth-users.yml index 26d623d..d07604d 100644 --- a/.github/workflows/auth-users.yml +++ b/.github/workflows/auth-users.yml @@ -7,31 +7,22 @@ on: - apps/auth/services/users/** - go.mod - go.sum - -env: - IMAGE: homelab/auth-users + pull_request: + paths: + - apps/auth/services/users/** + - go.mod + - go.sum jobs: - build-and-deploy: - runs-on: self-hosted + test: + runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Build image - run: | - docker build \ - -t ${{ env.IMAGE }}:${{ github.sha }} \ - -t ${{ env.IMAGE }}:latest \ - -f apps/auth/services/users/Dockerfile \ - . + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod - - name: Import image into k3d - run: k3d image import ${{ env.IMAGE }}:${{ github.sha }} -c homelab - - - name: Deploy - run: | - kubectl set image deployment/users \ - users=${{ env.IMAGE }}:${{ github.sha }} \ - -n auth - kubectl rollout status deployment/users -n auth --timeout=120s + - name: Test + run: go test ./apps/auth/services/users/... diff --git a/.github/workflows/finance-api.yml b/.github/workflows/finance-api.yml index 2ea5b28..06a1fda 100644 --- a/.github/workflows/finance-api.yml +++ b/.github/workflows/finance-api.yml @@ -7,34 +7,22 @@ on: - apps/finance/** - go.mod - go.sum - -env: - IMAGE: homelab/finance-api + pull_request: + paths: + - apps/finance/** + - go.mod + - go.sum jobs: - build-and-deploy: - runs-on: self-hosted + test: + runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Run tests + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + + - name: Test run: go test ./apps/finance/services/api/main/... - - - name: Build image - run: | - docker build \ - -t ${{ env.IMAGE }}:${{ github.sha }} \ - -t ${{ env.IMAGE }}:latest \ - -f apps/finance/services/api/Dockerfile \ - . - - - name: Import image into k3d - run: k3d image import ${{ env.IMAGE }}:${{ github.sha }} -c homelab - - - name: Deploy - run: | - kubectl set image deployment/api \ - api=${{ env.IMAGE }}:${{ github.sha }} \ - -n finance - kubectl rollout status deployment/api -n finance --timeout=120s diff --git a/Makefile b/Makefile index d380f21..62f757e 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ SHELL := /bin/zsh K3D_SCRIPT := infrastructure/k3d/k3d.sh TERRAFORM := terraform +SHA := $(shell git rev-parse --short HEAD) .PHONY: up up: ## Create the k3d dev cluster @@ -19,13 +20,28 @@ infra: ## Deploy shared infrastructure (MongoDB, monitoring, Traefik metrics) SERVICES := $(shell find apps -name Makefile -path "*/services/*" -exec dirname {} \;) +.PHONY: deploy-finance +deploy-finance: ## Build and deploy the finance API + $(MAKE) -C apps/finance/services/api build-deploy IMAGE_TAG=$(SHA) + +.PHONY: deploy-auth-users +deploy-auth-users: ## Build and deploy the auth users service + $(MAKE) -C apps/auth/services/users build-deploy IMAGE_TAG=$(SHA) + +.PHONY: deploy-auth-gateway +deploy-auth-gateway: ## Build and deploy the auth gateway service + $(MAKE) -C apps/auth/services/gateway build-deploy IMAGE_TAG=$(SHA) + +.PHONY: test +test: ## Run all tests + go test ./... + .PHONY: deploy-all deploy-all: ## Build, load, deploy, and restart every service @for dir in $(SERVICES); do \ echo "\033[36m>>> $$dir\033[0m"; \ - $(MAKE) -C "$$dir" build-deploy || true; \ + $(MAKE) -C "$$dir" build-deploy IMAGE_TAG=$(SHA) || true; \ done - $(MAKE) restart-all .PHONY: restart-all restart-all: ## Restart all deployments (pick up new images)