Build and Deploy / test-backend (push) Successful in 1m0s
Build and Deploy / lint-frontend (push) Successful in 2m3s
Build and Deploy / build-backend (push) Successful in 4s
Build and Deploy / build-frontend (push) Successful in 3s
Build and Deploy / deploy (push) Successful in 4s
141 lines
3.6 KiB
YAML
141 lines
3.6 KiB
YAML
name: Build and Deploy
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
test-backend:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Test backend
|
|
run: |
|
|
docker run --rm \
|
|
-v "$PWD/kotosoft-id-backend:/app" \
|
|
-w /app \
|
|
golang:1.25-alpine3.21 \
|
|
sh -c 'go mod tidy && go test ./...'
|
|
|
|
lint-frontend:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Lint frontend
|
|
run: |
|
|
docker run --rm \
|
|
-v "$PWD/kotosoft-id-frontend:/app" \
|
|
-w /app \
|
|
node:20-alpine \
|
|
sh -c 'npm install && npm run lint'
|
|
|
|
build-backend:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Build backend
|
|
run: |
|
|
docker build \
|
|
-t 172.17.0.1:5000/kotosoft_id_backend:latest \
|
|
-f kotosoft-id-backend/Dockerfile \
|
|
kotosoft-id-backend
|
|
|
|
- name: Push backend
|
|
run: |
|
|
docker push 172.17.0.1:5000/kotosoft_id_backend:latest
|
|
|
|
build-frontend:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Build frontend
|
|
run: |
|
|
docker build \
|
|
-t 172.17.0.1:5000/kotosoft_id_frontend:latest \
|
|
-f kotosoft-id-frontend/Dockerfile \
|
|
kotosoft-id-frontend
|
|
|
|
- name: Push frontend
|
|
run: |
|
|
docker push 172.17.0.1:5000/kotosoft_id_frontend:latest
|
|
|
|
deploy:
|
|
runs-on: ubuntu-latest
|
|
|
|
needs:
|
|
- test-backend
|
|
- lint-frontend
|
|
- build-backend
|
|
- build-frontend
|
|
|
|
env:
|
|
FRONTEND_URL: ${{ vars.FRONTEND_URL }}
|
|
BACKEND_URL: ${{ vars.BACKEND_URL }}
|
|
POSTGRES_URL: ${{ secrets.POSTGRES_URL }}
|
|
REDIS_URL: ${{ secrets.REDIS_URL }}
|
|
JWT_SECRET: ${{ secrets.JWT_SECRET }}
|
|
CLIENT_ID: ${{ vars.CLIENT_ID }}
|
|
CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }}
|
|
CLIENT_NAME: ${{ vars.CLIENT_NAME }}
|
|
CLIENT_REDIRECT_URIS: ${{ vars.CLIENT_REDIRECT_URIS }}
|
|
DOMAIN: ${{ vars.DOMAIN }}
|
|
API_DOMAIN: ${{ vars.API_DOMAIN }}
|
|
LETSENCRYPT_EMAIL: ${{ vars.LETSENCRYPT_EMAIL }}
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Prepare SSH
|
|
run: |
|
|
mkdir -p ~/.ssh
|
|
echo "${{ secrets.DEPLOY_SSH_KEY }}" > ~/.ssh/deploy_key
|
|
chmod 600 ~/.ssh/deploy_key
|
|
ssh-keyscan -p 1650 -H "${{ vars.DEPLOY_HOST }}" >> ~/.ssh/known_hosts
|
|
|
|
- name: Build .env for remote
|
|
run: |
|
|
cat > .env <<EOF
|
|
FRONTEND_URL=${FRONTEND_URL}
|
|
BACKEND_URL=${BACKEND_URL}
|
|
POSTGRES_URL=${POSTGRES_URL}
|
|
REDIS_URL=${REDIS_URL}
|
|
JWT_SECRET=${JWT_SECRET}
|
|
CLIENT_ID=${CLIENT_ID}
|
|
CLIENT_SECRET=${CLIENT_SECRET}
|
|
CLIENT_NAME=${CLIENT_NAME}
|
|
CLIENT_REDIRECT_URIS=${CLIENT_REDIRECT_URIS}
|
|
DOMAIN=${DOMAIN}
|
|
API_DOMAIN=${API_DOMAIN}
|
|
LETSENCRYPT_EMAIL=${LETSENCRYPT_EMAIL}
|
|
EOF
|
|
|
|
- name: Copy compose file and env
|
|
run: |
|
|
scp -P 1650 -i ~/.ssh/deploy_key -o StrictHostKeyChecking=no \
|
|
docker-compose.yml .env \
|
|
"${{ vars.DEPLOY_USER }}@${{ vars.DEPLOY_HOST }}:/opt/app/"
|
|
|
|
- name: Deploy
|
|
run: |
|
|
ssh -p 1650 -i ~/.ssh/deploy_key "${{ vars.DEPLOY_USER }}@${{ vars.DEPLOY_HOST }}" '
|
|
set -e
|
|
cd /opt/app
|
|
docker compose -p kotosoft pull
|
|
docker compose -p kotosoft up -d --remove-orphans
|
|
' |