67 lines
1.7 KiB
YAML
67 lines
1.7 KiB
YAML
name: Build & Deploy Costco Grocery List
|
|
|
|
on:
|
|
push:
|
|
branches: [ "main" ]
|
|
|
|
env:
|
|
IMAGE_NAME: costco-grocery-list
|
|
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
|
|
|
|
- name: Install backend dependencies
|
|
working-directory: backend
|
|
run: npm ci
|
|
|
|
- name: Run tests (if any)
|
|
working-directory: backend
|
|
run: npm test --if-present
|
|
|
|
- name: Docker login
|
|
run: |
|
|
echo "${{ secrets.REGISTRY_PASS }}" | docker login $REGISTRY \
|
|
-u "${{ secrets.REGISTRY_USER }}" --password-stdin
|
|
|
|
- name: Build Docker image
|
|
run: |
|
|
docker build -t $REGISTRY/${{ env.IMAGE_NAME }}:${{ github.sha }} .
|
|
docker tag $REGISTRY/${{ env.IMAGE_NAME }}:${{ github.sha }} $REGISTRY/${{ env.IMAGE_NAME }}:latest
|
|
|
|
- name: Push Docker image
|
|
run: |
|
|
docker push $REGISTRY/${{ env.IMAGE_NAME }}:${{ github.sha }}
|
|
docker push $REGISTRY/${{ env.IMAGE_NAME }}: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
|