From c2aee1633b7dd5ff01064811fdedee99751ddab3 Mon Sep 17 00:00:00 2001 From: Nico Date: Tue, 25 Nov 2025 20:31:59 -0800 Subject: [PATCH] Adding gitea workflow --- .vscode/settings.json | 3 ++ gitea/workflows/deploy.yml | 66 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 gitea/workflows/deploy.yml diff --git a/.vscode/settings.json b/.vscode/settings.json index e6d4b42..5fff71a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -48,6 +48,9 @@ // File Icons // ============================ "workbench.iconTheme": "material-icon-theme", + "material-icon-theme.folders.associations": { + "gitea/workflows": "repository", + }, // ============================ // Explorer cleanup diff --git a/gitea/workflows/deploy.yml b/gitea/workflows/deploy.yml new file mode 100644 index 0000000..b5ee22b --- /dev/null +++ b/gitea/workflows/deploy.yml @@ -0,0 +1,66 @@ +name: Build & Deploy Costco Grocery List + +on: + push: + branches: [ "main" ] + +env: + IMAGE_NAME: costco-grocery-list + REGISTRY: gitea.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