|
9 | 9 | jobs: |
10 | 10 | build-and-push: |
11 | 11 | runs-on: ubuntu-latest |
| 12 | + permissions: |
| 13 | + contents: read |
| 14 | + packages: write |
| 15 | + |
12 | 16 | steps: |
13 | | - - uses: actions/checkout@v4 |
14 | | - - uses: docker/setup-buildx-action@v3 |
15 | | - - uses: docker/login-action@v3 |
| 17 | + - name: Checkout repo |
| 18 | + uses: actions/checkout@v4 |
| 19 | + |
| 20 | + - name: Set up Docker Buildx |
| 21 | + uses: docker/setup-buildx-action@v3 |
| 22 | + |
| 23 | + - name: Log in to GHCR |
| 24 | + uses: docker/login-action@v3 |
16 | 25 | with: |
17 | 26 | registry: ghcr.io |
18 | 27 | username: ${{ github.actor }} |
19 | 28 | password: ${{ secrets.GITHUB_TOKEN }} |
20 | | - - uses: docker/build-push-action@v6 |
| 29 | + |
| 30 | + - name: Build and push image |
| 31 | + uses: docker/build-push-action@v6 |
21 | 32 | with: |
22 | 33 | context: ./plate-server |
23 | | - push: true |
24 | | - tags: ghcr.io/whatnext-id/plate-code-detector:latest |
| 34 | + push: ${{ github.event_name == 'push' }} |
| 35 | + tags: plate-code-detector:latest |
25 | 36 | cache-from: type=gha |
26 | 37 | cache-to: type=gha,mode=max |
27 | 38 |
|
28 | 39 | deploy: |
29 | | - needs: build-and-push |
30 | 40 | runs-on: ubuntu-latest |
| 41 | + needs: build-and-push |
| 42 | + if: github.event_name == 'push' |
| 43 | + |
31 | 44 | steps: |
| 45 | + - name: Setup SSH |
| 46 | + run: | |
| 47 | + mkdir -p ~/.ssh |
| 48 | + echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_ed25519 |
| 49 | + chmod 600 ~/.ssh/id_ed25519 |
| 50 | + ssh-keyscan -p 22 -H ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts |
| 51 | +
|
32 | 52 | - name: Deploy to server |
33 | 53 | run: | |
34 | 54 | ssh -i ~/.ssh/id_ed25519 ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }} << 'EOF' |
| 55 | + echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin |
35 | 56 | cd ~/PlateCode/plate-server |
36 | 57 | docker compose pull |
37 | | - docker compose up -d # no --build ! |
38 | | - docker image prune -f # no -a ! |
| 58 | + docker compose --project-name platecode up -d |
| 59 | + docker image prune -f |
39 | 60 | EOF |
0 commit comments