Skip to content

ci: remove no-cache #48

ci: remove no-cache

ci: remove no-cache #48

Workflow file for this run

name: Build and Deploy
on:
push:
branches: [main]
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
check-changes:
name: Check for changes
runs-on: ubuntu-latest
outputs:
should-deploy: ${{ steps.turbo-ignore.outputs.should-deploy }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
lfs: true
- name: Check if site needs deployment
id: turbo-ignore
run: |
npx turbo-ignore site || EXIT_CODE=$?
echo "should-deploy=${EXIT_CODE:-0}" >> $GITHUB_OUTPUT
build-and-deploy:
name: Build and Deploy
needs: check-changes
if: (needs.check-changes.outputs.should-deploy == '1' && github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch'
runs-on: self-hosted
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=sha,prefix={{branch}}-
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: ./site/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/arm64
secrets: |
SENTRY_AUTH_TOKEN=${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG=${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT=${{ secrets.SENTRY_PROJECT }}
NEXT_PUBLIC_SENTRY_DSN=${{ secrets.NEXT_PUBLIC_SENTRY_DSN }}
DIGITRANSIT_KEY=${{ secrets.DIGITRANSIT_KEY }}
NEXT_PUBLIC_DIGITRANSIT_KEY=${{ secrets.NEXT_PUBLIC_DIGITRANSIT_KEY }}
- name: Deploy to VPS
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.VPS_HOST }}
username: ${{ secrets.VPS_USERNAME }}
key: ${{ secrets.VPS_KEY }}
script: |
cd junat.live
git fetch origin
git reset --hard origin/main
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
# Update image reference in docker-compose
export IMAGE_TAG=$(echo '${{ steps.meta.outputs.tags }}' | head -n1 | cut -d':' -f2)
docker compose pull
docker compose up -d
docker system prune -f