|
1 | 1 | name: Build and deploy
|
2 | 2 |
|
3 | 3 | on:
|
4 |
| - workflow_run: |
5 |
| - workflows: [Test] |
6 |
| - branches: [master] |
7 |
| - types: [completed] |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + tags: |
| 8 | + - '*' |
| 9 | +env: |
| 10 | + REGISTRY: ghcr.io |
| 11 | + IMAGE_NAME: ${{ github.repository }} |
| 12 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
8 | 13 |
|
9 | 14 | jobs:
|
10 | 15 | deploy:
|
11 |
| - if: ${{ github.event.workflow_run.conclusion == 'success' }} |
12 | 16 | name: Deploy
|
13 | 17 | runs-on: ubuntu-latest
|
| 18 | + permissions: |
| 19 | + contents: read |
| 20 | + packages: write |
14 | 21 | steps:
|
15 |
| - - name: Build container |
16 |
| - id: docker_build |
17 |
| - uses: docker/build-push-action@v2 |
| 22 | + - name: Login to GitHub Container Registry |
| 23 | + uses: docker/login-action@v3 |
18 | 24 | with:
|
19 |
| - load: true |
20 |
| - tags: insektionen/songbook-2.0:latest |
21 |
| - - name: Export container |
22 |
| - run: docker save insektionen/songbook-2.0:latest | gzip > songbook-2.0_latest.tar.gz |
23 |
| - - name: Copy to Server |
24 |
| - uses: appleboy/scp-action@master |
| 25 | + registry: ghcr.io |
| 26 | + username: ${{ github.actor }} |
| 27 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 28 | + - name: Extract metadata (tags, labels) for Docker |
| 29 | + id: meta |
| 30 | + uses: docker/metadata-action@v5 |
25 | 31 | with:
|
26 |
| - host: ${{ secrets.SSH_HOST }} |
27 |
| - username: ${{ secrets.SSH_USERNAME }} |
28 |
| - key: ${{ secrets.SSH_KEY }} |
29 |
| - port: 22 |
30 |
| - source: 'songbook-2.0_latest.tar.gz' |
31 |
| - target: '~/' |
32 |
| - - name: Import and start on Server |
| 32 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 33 | + - name: Build container |
| 34 | + uses: docker/build-push-action@v5 |
| 35 | + with: |
| 36 | + push: true |
| 37 | + tags: ${{ steps.meta.outputs.tags }} |
| 38 | + labels: ${{ steps.meta.outputs.labels }} |
| 39 | + - name: Start on Server |
33 | 40 | uses: appleboy/ssh-action@master
|
34 | 41 | with:
|
35 | 42 | host: ${{ secrets.SSH_HOST }}
|
36 | 43 | username: ${{ secrets.SSH_USERNAME }}
|
37 | 44 | key: ${{ secrets.SSH_KEY }}
|
38 |
| - port: 22 |
39 |
| - script: docker load < songbook-2.0_latest.tar.gz && cd songbook-2.0 && docker-compose up -d |
| 45 | + port: 2222 |
| 46 | + envs: GITHUB_TOKEN,GITHUB_ACTOR |
| 47 | + script: "cd songbook-2.0 && echo $GITHUB_TOKEN | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin && docker compose up -d" |
0 commit comments