CI #29
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 | |
| on: workflow_dispatch | |
| jobs: | |
| build: | |
| name: Generate Docker Image | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Cache Docker layers | |
| uses: actions/cache@v4 | |
| with: | |
| path: /tmp/.buildx-cache | |
| key: ${{ runner.os }}-buildx-${{ github.sha }} | |
| restore-keys: | | |
| ${{ runner.os }}-buildx- | |
| - name: Create Env File | |
| run: | | |
| cat << EOF >> .env | |
| NEXT_PUBLIC_TINA_CLIENT_ID=${{ secrets.NEXT_PUBLIC_TINA_CLIENT_ID }} | |
| NEXT_SECRET_TOKEN=${{ secrets.NEXT_SECRET_TOKEN }} | |
| TINA_TOKEN=${{ secrets.TINA_TOKEN }} | |
| EOF | |
| - name: Build Docker Image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| tags: house:latest | |
| outputs: type=docker,dest=house.tar | |
| cache-from: type=local,src=/tmp/.buildx-cache | |
| cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max | |
| - name: Move Cache | |
| run: | | |
| rm -rf /tmp/.buildx-cache | |
| mv /tmp/.buildx-cache-new /tmp/.buildx-cache | |
| - name: Export Docker Image | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: house-docker-image | |
| path: house.tar | |
| retention-days: 1 | |
| deploy: | |
| name: Restart Server Docker Container | |
| runs-on: ubuntu-latest | |
| needs: build | |
| steps: | |
| - name: Import Docker Image | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: house-docker-image | |
| path: images | |
| - name: Upload Docker Image | |
| uses: appleboy/[email protected] | |
| with: | |
| host: ${{ secrets.SSH_HOST }} | |
| username: ${{ secrets.SSH_USERNAME }} | |
| key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| source: images/* | |
| target: ${{ secrets.IMAGE_DIR_PATH }} | |
| strip_components: 1 | |
| - name: Restart Docker Container | |
| uses: appleboy/[email protected] | |
| with: | |
| host: ${{ secrets.SSH_HOST }} | |
| username: ${{ secrets.SSH_USERNAME }} | |
| key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| script: | | |
| # load local image | |
| docker load -i ${{ secrets.IMAGE_DIR_PATH }}/house.tar | |
| # restart container | |
| docker stop house || true | |
| docker rm house || true | |
| docker run -d --name house -p 3000:3000 house | |
| # clean unused images | |
| docker image prune -f |