73 lines
1.8 KiB
YAML
73 lines
1.8 KiB
YAML
name: Build and Deploy Go App
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- master
|
|
- cicd
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- uses: actions/setup-go@v6
|
|
with:
|
|
go-version: '^1.25'
|
|
check-latest: false
|
|
cache-dependency-path: |
|
|
modules/server/go.sum
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
# Build application
|
|
- name: Build Go app
|
|
run: |
|
|
cd modules/server
|
|
go mod tidy
|
|
go build -o nyanimedb .
|
|
|
|
- name: Upload built application to artifactory
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: nyanimedb
|
|
path: modules/server/nyanimedb
|
|
|
|
# Build Docker image
|
|
- name: Login to Docker Hub
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ vars.REGISTRY }}
|
|
username: ${{ secrets.REGISTRY_USERNAME }}
|
|
password: ${{ secrets.REGISTRY_TOKEN }}
|
|
|
|
- name: Build and push
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
file: Dockerfiles/Dockerfile_server
|
|
push: true
|
|
tags: meowgit.nekoea.red/nihonium/nyanimedb:latest
|
|
|
|
deploy:
|
|
runs-on: self-hosted
|
|
needs: build
|
|
env:
|
|
POSTGRES_USER: ${{ secrets.POSTGRES_USER }}
|
|
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
|
|
POSTGRES_DB: nyanimedb
|
|
POSTGRES_PORT: 5432
|
|
POSTGRES_VERSION: 18
|
|
LOG_LEVEL: ${{ vars.LOG_LEVEL }}
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Deploy containers locally
|
|
run: |
|
|
cd deploy
|
|
docker compose down || true
|
|
docker compose up -d
|