92 lines
2.5 KiB
YAML
92 lines
2.5 KiB
YAML
name: Build & Deploy Costco Grocery List
|
|
|
|
on:
|
|
push:
|
|
branches: [ "main" ]
|
|
|
|
env:
|
|
REGISTRY: git.nicosaya.com
|
|
|
|
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/costco-grocery-list-backend:${{ github.sha }} \
|
|
-t $REGISTRY/costco-grocery-list-backend:latest \
|
|
-f backend/Dockerfile backend/
|
|
|
|
- name: Push Backend Image
|
|
run: |
|
|
docker push $REGISTRY/costco-grocery-list-backend:${{ github.sha }}
|
|
docker push $REGISTRY/costco-grocery-list-backend:latest
|
|
|
|
# -------------------------
|
|
# 🔹 Build Frontend Image
|
|
# -------------------------
|
|
- name: Build Frontend Image
|
|
run: |
|
|
docker build \
|
|
-t $REGISTRY/costco-grocery-list-frontend:${{ github.sha }} \
|
|
-t $REGISTRY/costco-grocery-list-frontend:latest \
|
|
-f frontend/Dockerfile frontend/
|
|
|
|
- name: Push Frontend Image
|
|
run: |
|
|
docker push $REGISTRY/costco-grocery-list-frontend:${{ github.sha }}
|
|
docker push $REGISTRY/costco-grocery-list-frontend:latest
|
|
|
|
deploy:
|
|
needs: build
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- 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
|
|
|
|
- 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
|