-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Update GitHub Actions workflow for golang linting, testing, an…
…d building
- Loading branch information
Showing
7 changed files
with
267 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
name: Lint, Test, Build and Deploy golang | ||
|
||
on: | ||
push: | ||
branches: ["develop", "feat/backend/deployment-and-up"] | ||
paths: [ | ||
"occupi-backend/cmd/**", | ||
"occupi-backend/configs/**", | ||
"occupi-backend/pkg/**", | ||
"occupi-backend/.golangci.yml", | ||
"occupi-backend/tests/**", | ||
".github/workflows/lint-test-build-golang.yml", | ||
".github/workflows/deploy-golang-develop.yml" | ||
] | ||
|
||
workflow_dispatch: | ||
|
||
defaults: | ||
run: | ||
working-directory: occupi-backend | ||
|
||
jobs: | ||
build-push-docker: | ||
name: Build and Push Develop Docker Image | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v2 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
|
||
- name: Login to DockerHub | ||
uses: docker/login-action@v2 | ||
with: | ||
username: ${{ secrets.DOCKER_USERNAME }} | ||
password: ${{ secrets.DOCKER_PASSWORD }} | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: . | ||
file: ./Dockerfile | ||
platforms: linux/amd64,linux/arm64 | ||
push: true | ||
tags: ${{ secrets.DOCKER_USERNAME }}/occupi-backend:latest | ||
|
||
deploy: | ||
needs: build-push-docker | ||
name: Deploy to Develop | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: SSH to VM | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{ secrets.VM_IP }} | ||
username: ${{ secrets.VM_USERNAME }} | ||
key: ${{ secrets.VM_SSH_KEY }} | ||
script: | | ||
cd /home/Y2KODELABS/occupi-backend | ||
gpg --quiet --batch --yes --decrypt --passphrase=$GPG_PASSPHRASE --output .env .env.gpg | ||
docker-compose -f docker-compose.traefik.yml up -d | ||
docker-compose -f docker-compose.dev.yml pull | ||
docker-compose -f docker-compose.dev.yml up -d --build | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
name: Lint, Test and Build golang | ||
|
||
on: | ||
push: | ||
branches: ["master"] | ||
paths: [ | ||
"occupi-backend/cmd/**", | ||
"occupi-backend/configs/**", | ||
"occupi-backend/pkg/**", | ||
"occupi-backend/.golangci.yml", | ||
"occupi-backend/tests/**", | ||
".github/workflows/lint-test-build-golang.yml", | ||
".github/workflows/deploy-golang-prod.yml" | ||
] | ||
|
||
workflow_dispatch: | ||
|
||
defaults: | ||
run: | ||
working-directory: occupi-backend | ||
|
||
jobs: | ||
lint: | ||
name: Lint | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: '1.21' # Specify the Go version you are using | ||
|
||
- name: Install golangci-lint | ||
run: | | ||
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest | ||
- name: Run golangci-lint | ||
run: | | ||
golangci-lint run | ||
test: | ||
needs: lint | ||
name: Test | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: '1.21' # Specify the Go version you are using | ||
|
||
- name: Run tests | ||
run: | | ||
go test -v -coverpkg=github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils,github.com/COS301-SE-2024/occupi/occupi-backend/pkg/handlers ./tests/... -coverprofile=coverage.out | ||
- name: Upload coverage reports to Codecov | ||
uses: codecov/[email protected] | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
|
||
build: | ||
needs: test | ||
name: Build | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: '1.21' # Specify the Go version you are using | ||
|
||
- name: Build the code | ||
run: | | ||
go build -v cmd/occupi-backend/main.go | ||
build-push-docker: | ||
needs: build | ||
name: Build and Push Master Docker Image | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v2 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
|
||
- name: Login to DockerHub | ||
uses: docker/login-action@v2 | ||
with: | ||
username: ${{ secrets.DOCKER_USERNAME }} | ||
password: ${{ secrets.DOCKER_PASSWORD }} | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: . | ||
file: ./Dockerfile | ||
platforms: linux/amd64,linux/arm64 | ||
push: true | ||
tags: ${{ secrets.DOCKER_USERNAME }}/occupi-backend:latest | ||
|
||
deploy: | ||
needs: build-push-docker | ||
name: Deploy to Master | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: SSH to VM | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{ secrets.VM_IP }} | ||
username: ${{ secrets.VM_USERNAME }} | ||
key: ${{ secrets.VM_SSH_KEY }} | ||
script: | | ||
cd /home/Y2KODELABS/occupi-backend | ||
gpg --quiet --batch --yes --decrypt --passphrase=$GPG_PASSPHRASE --output .env .env.gpg | ||
docker-compose -f docker-compose.traefik.yml up -d | ||
docker-compose -f docker-compose.prod.yml pull | ||
docker-compose -f docker-compose.prod.yml up -d --build | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,4 +18,7 @@ | |
*.tmp | ||
*.swp | ||
*.gitignore | ||
*.md | ||
*.md | ||
*.out | ||
*.toml | ||
*.exe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
version: '3.8' | ||
services: | ||
occupi-backend-dev: | ||
build: . | ||
container_name: occupi-backend-dev | ||
env_file: | ||
- .env | ||
environment: | ||
- ENV=development | ||
networks: | ||
- webnet | ||
labels: | ||
- "traefik.http.routers.occupi-backend-dev.rule=Host(`dev.occupi.tech`, `www.dev.occupi.tech`)" | ||
- "traefik.http.services.occupi-backend-dev.loadbalancer.server.port=8080" | ||
|
||
networks: | ||
webnet: | ||
external: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
version: '3.8' | ||
services: | ||
occupi-backend-prod: | ||
build: . | ||
container_name: occupi-backend-prod | ||
env_file: | ||
- .env | ||
environment: | ||
- ENV=production | ||
networks: | ||
- webnet | ||
labels: | ||
- "traefik.http.routers.occupi-backend-prod.rule=Host(`occupi.tech`)" | ||
- "traefik.http.services.occupi-backend-prod.loadbalancer.server.port=8080" | ||
|
||
networks: | ||
webnet: | ||
external: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
version: '3.8' | ||
services: | ||
traefik: | ||
image: traefik:v3.0.2 | ||
command: | ||
- "--api.insecure=true" | ||
- "--providers.docker=true" | ||
- "--entrypoints.web.address=:80" | ||
- "--entrypoints.websecure.address=:443" | ||
- "--certificatesresolvers.myresolver.acme.tlschallenge=true" | ||
- "--certificatesresolvers.myresolver.acme.email=u21546551@tuks.co.za" | ||
- "--certificatesresolvers.myresolver.acme.storage=/letsencrypt/acme.json" | ||
ports: | ||
- "80:80" | ||
- "443:443" | ||
volumes: | ||
- "/var/run/docker.sock:/var/run/docker.sock:ro" | ||
- "./letsencrypt:/letsencrypt" | ||
networks: | ||
- webnet | ||
|
||
networks: | ||
webnet: | ||
external: true |