|
1 | | -name: Container (Docker) |
| 1 | +name: Container |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
| 5 | + tags-ignore: |
| 6 | + - "!v*" |
5 | 7 | pull_request: |
| 8 | + branches: |
| 9 | + - "develop" |
| 10 | + - "main" |
6 | 11 |
|
7 | 12 | env: |
8 | 13 | CARGO_TERM_COLOR: always |
9 | 14 |
|
10 | 15 | jobs: |
11 | 16 | test: |
12 | | - name: Test |
| 17 | + name: Test (Docker) |
13 | 18 | runs-on: ubuntu-latest |
14 | 19 |
|
15 | 20 | steps: |
16 | | - - id: checkout |
17 | | - name: Checkout Repository |
18 | | - uses: actions/checkout@v3 |
19 | | - |
20 | 21 | - id: setup |
21 | 22 | name: Setup Toolchain |
22 | 23 | uses: docker/setup-buildx-action@v2 |
|
25 | 26 | name: Build |
26 | 27 | uses: docker/build-push-action@v4 |
27 | 28 | with: |
28 | | - context: . |
29 | 29 | file: ./Containerfile |
30 | 30 | push: false |
31 | 31 | load: true |
|
40 | 40 | - id: compose |
41 | 41 | name: Compose |
42 | 42 | run: docker compose build |
| 43 | + |
| 44 | + check-secret: |
| 45 | + name: Check Secrets |
| 46 | + needs: test |
| 47 | + environment: dockerhub-torrust |
| 48 | + runs-on: ubuntu-latest |
| 49 | + |
| 50 | + outputs: |
| 51 | + publish: ${{ steps.docker_hub.outputs.publish }} |
| 52 | + |
| 53 | + steps: |
| 54 | + - id: docker_hub |
| 55 | + name: Docker Hub |
| 56 | + env: |
| 57 | + DOCKER_HUB_ACCESS_TOKEN: "${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}" |
| 58 | + if: "${{ env.DOCKER_HUB_ACCESS_TOKEN != '' }}" |
| 59 | + run: echo "publish=true" >> $GITHUB_OUTPUT |
| 60 | + |
| 61 | + publish: |
| 62 | + name: Publish |
| 63 | + environment: dockerhub-torrust |
| 64 | + needs: check-secret |
| 65 | + if: needs.check-secret.outputs.publish == 'true' |
| 66 | + runs-on: ubuntu-latest |
| 67 | + |
| 68 | + steps: |
| 69 | + - id: meta |
| 70 | + name: Docker meta |
| 71 | + uses: docker/metadata-action@v4 |
| 72 | + with: |
| 73 | + images: | |
| 74 | + "${{ secrets.DOCKER_HUB_USERNAME }}/${{secrets.DOCKER_HUB_REPOSITORY_NAME }}" |
| 75 | + tags: | |
| 76 | + type=ref,event=branch |
| 77 | + type=ref,event=pr |
| 78 | + type=semver,pattern={{version}} |
| 79 | + type=semver,pattern={{major}}.{{minor}} |
| 80 | +
|
| 81 | + - id: login |
| 82 | + name: Login to Docker Hub |
| 83 | + uses: docker/login-action@v2 |
| 84 | + with: |
| 85 | + username: ${{ secrets.DOCKER_HUB_USERNAME }} |
| 86 | + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} |
| 87 | + |
| 88 | + - id: setup |
| 89 | + name: Setup Toolchain |
| 90 | + uses: docker/setup-buildx-action@v2 |
| 91 | + |
| 92 | + - name: Build and push |
| 93 | + uses: docker/build-push-action@v4 |
| 94 | + with: |
| 95 | + file: ./Containerfile |
| 96 | + push: ${{ github.event_name != 'pull_request' }} |
| 97 | + tags: ${{ steps.meta.outputs.tags }} |
| 98 | + labels: ${{ steps.meta.outputs.labels }} |
| 99 | + cache-from: type=gha |
| 100 | + cache-to: type=gha,mode=max |
0 commit comments