fix: use git reset in deploy to avoid local conflicts #49
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy to my Raspberry Pi | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to GHCR | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and push server | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: apps/server/Dockerfile | |
| platforms: linux/arm64 | |
| push: true | |
| tags: ghcr.io/eric-jy-park/bookmarket-server:latest | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Build and push web | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: apps/web/Dockerfile | |
| platforms: linux/arm64 | |
| push: true | |
| tags: ghcr.io/eric-jy-park/bookmarket-web:latest | |
| build-args: | | |
| NEXT_PUBLIC_BASE_URL=${{ secrets.NEXT_PUBLIC_BASE_URL }} | |
| NEXT_PUBLIC_GOOGLE_CLIENT_ID=${{ secrets.NEXT_PUBLIC_GOOGLE_CLIENT_ID }} | |
| NEXT_PUBLIC_GITHUB_CLIENT_ID=${{ secrets.NEXT_PUBLIC_GITHUB_CLIENT_ID }} | |
| NEXT_PUBLIC_GITHUB_REDIRECT_URI=${{ secrets.NEXT_PUBLIC_GITHUB_REDIRECT_URI }} | |
| NEXT_PUBLIC_DOMAIN=${{ secrets.NEXT_PUBLIC_DOMAIN }} | |
| NEXT_PUBLIC_UMAMI_WEBSITE_ID=${{ secrets.NEXT_PUBLIC_UMAMI_WEBSITE_ID }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| deploy: | |
| runs-on: ubuntu-latest | |
| needs: build-and-push | |
| permissions: | |
| packages: read | |
| steps: | |
| - name: Connect to Tailscale | |
| uses: tailscale/github-action@v2 | |
| with: | |
| oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }} | |
| oauth-secret: ${{ secrets.TS_OAUTH_SECRET }} | |
| tags: tag:ci | |
| - name: Deploy to Raspberry Pi | |
| uses: appleboy/ssh-action@v1.0.3 | |
| with: | |
| host: ${{ secrets.HOST }} | |
| username: ${{ secrets.USERNAME }} | |
| password: ${{ secrets.PASSWORD }} | |
| script_stop: true | |
| command_timeout: 10m | |
| envs: GHCR_TOKEN | |
| script: | | |
| echo $GHCR_TOKEN | docker login ghcr.io -u ${{ github.actor }} --password-stdin | |
| cd /home/ericpark/Desktop/apps/bookmarket | |
| git fetch origin main | |
| git reset --hard origin/main | |
| docker compose pull | |
| docker compose up -d --remove-orphans | |
| env: | |
| GHCR_TOKEN: ${{ secrets.GITHUB_TOKEN }} |