Merge pull request #5 from phakphum-dev/ttamx/contest #125
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: CI/CD | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - dockerfile: Dockerfile.web | |
| image: ghcr.io/${{ github.repository_owner }}/otog-web | |
| - dockerfile: Dockerfile.api | |
| image: ghcr.io/${{ github.repository_owner }}/otog-api | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to the Container registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set up environment | |
| run: | | |
| echo "NEXTAUTH_SECRET=${{ secrets.NEXTAUTH_SECRET }}" >> apps/web/.env.local | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: ${{ matrix.dockerfile }} | |
| push: true | |
| tags: ${{ matrix.image }}:latest | |
| cache-from: type=registry,ref=${{ matrix.image }}:buildcache | |
| cache-to: type=registry,ref=${{ matrix.image }}:buildcache,mode=max | |
| deploy: | |
| runs-on: ubuntu-latest | |
| needs: build | |
| steps: | |
| - name: Connect to WARP | |
| uses: Boostport/setup-cloudflare-warp@v1 | |
| with: | |
| organization: ${{ secrets.CLOUDFLARE_ORGANIZATION }} | |
| auth_client_id: ${{ secrets.CLOUDFLARE_AUTH_CLIENT_ID }} | |
| auth_client_secret: ${{ secrets.CLOUDFLARE_AUTH_CLIENT_SECRET }} | |
| - name: Deploy to host | |
| uses: appleboy/[email protected] | |
| with: | |
| host: ${{ secrets.SSH_HOST }} | |
| username: ${{ secrets.SSH_USERNAME }} | |
| key: ${{ secrets.SSH_KEY }} | |
| script_stop: true | |
| script: | | |
| cd otog | |
| git checkout main; git pull | |
| make compose-pull | |
| make compose-prod | |
| docker image prune -f |