costco-grocery-list/.gitea/workflows/deploy.yml
Workflow config file is invalid. Please check your config file: yaml: unmarshal errors: line 109: cannot unmarshal !!seq into model.Job
2025-11-26 20:52:13 -08:00

131 lines
3.9 KiB
YAML

name: Build & Deploy Costco Grocery List
on:
push:
branches: [ "main" ]
env:
REGISTRY: git.nicosaya.com/nalalangan/costco-grocery-list
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 20
# -------------------------
# 🔹 BACKEND TESTS
# -------------------------
- name: Install backend dependencies
working-directory: backend
run: npm ci
- name: Run backend tests
working-directory: backend
run: npm test --if-present
# -------------------------
# 🔹 Docker Login
# -------------------------
- name: Docker login
run: |
echo "${{ secrets.REGISTRY_PASS }}" | docker login $REGISTRY \
-u "${{ secrets.REGISTRY_USER }}" --password-stdin
# -------------------------
# 🔹 Build Backend Image
# -------------------------
- name: Build Backend Image
run: |
docker build \
-t $REGISTRY/backend:${{ github.sha }} \
-t $REGISTRY/backend:latest \
-f backend/Dockerfile backend/
- name: Push Backend Image
run: |
docker push $REGISTRY/backend:${{ github.sha }}
docker push $REGISTRY/backend:latest
# -------------------------
# 🔹 Build Frontend Image
# -------------------------
- name: Build Frontend Image
run: |
docker build \
-t $REGISTRY/frontend:${{ github.sha }} \
-t $REGISTRY/frontend:latest \
-f frontend/Dockerfile.dev frontend/
- name: Push Frontend Image
run: |
docker push $REGISTRY/frontend:${{ github.sha }}
docker push $REGISTRY/frontend:latest
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Install SSH key
run: |
mkdir -p ~/.ssh
echo "${{ secrets.DEPLOY_KEY }}" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
ssh-keyscan -H "${{ secrets.DEPLOY_HOST }}" >> ~/.ssh/known_hosts
# ---------------------------------------------------------
# 1. Upload docker-compose.yml to the production directory
# ---------------------------------------------------------
- name: Upload docker-compose.yml
run: |
ssh ${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }} "mkdir -p /opt/costco-app"
scp docker-compose.yml \
${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}:/opt/costco-app/docker-compose.yml
# ---------------------------------------------------------
# 2. Deploy using the uploaded compose file
# ---------------------------------------------------------
- name: Deploy via SSH
run: |
ssh ${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }} << 'EOF'
cd /opt/costco-app
docker compose pull
docker compose up -d --remove-orphans
docker image prune -f
EOF
notify:
- name: Wait for ntfy service to be healthy
run: |
ssh -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP '
echo "Waiting for ntfy container..."
for i in {1..30}; do
STATUS=$(docker inspect --format="{{json .State.Health.Status }}" ntfy)
if [[ $STATUS == "\"healthy\"" ]]; then
echo "ntfy is healthy!"
exit 0
fi
echo "ntfy not ready yet ($STATUS). Retrying..."
sleep 2
done
echo "Error: ntfy did not become healthy in time."
exit 1
'
- name: Notify ntfy
run: |
curl -d "🚀 Deployment successful: $IMAGE_NAME:$GITHUB_SHA" \
https://ntfy.nicosaya.com/server-deploy