|
| 1 | +name: Docker |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + # Publish `master` as Docker `latest` image. |
| 6 | + branches: |
| 7 | + - master |
| 8 | + |
| 9 | + # Publish `v1.2.3` tags as releases. |
| 10 | + tags: |
| 11 | + - v* |
| 12 | + # Run tests for any PRs. |
| 13 | + # pull_request: |
| 14 | +env: |
| 15 | + # TODO: Change variable to your image's name. |
| 16 | + IMAGE_NAME: jorgelbg/cloudflare-access-grafana |
| 17 | + |
| 18 | +jobs: |
| 19 | + # Run tests. |
| 20 | + # See also https://docs.docker.com/docker-hub/builds/automated-testing/ |
| 21 | + # test: |
| 22 | + # runs-on: ubuntu-latest |
| 23 | + |
| 24 | + # steps: |
| 25 | + # - uses: actions/checkout@v2 |
| 26 | + |
| 27 | + # - name: Run tests |
| 28 | + # run: | |
| 29 | + # if [ -f docker-compose.test.yml ]; then |
| 30 | + # docker-compose --file docker-compose.test.yml build |
| 31 | + # docker-compose --file docker-compose.test.yml run sut |
| 32 | + # else |
| 33 | + # docker build . --file Dockerfile |
| 34 | + # fi |
| 35 | + |
| 36 | + # Push image to GitHub Package Registry. |
| 37 | + # See also https://docs.docker.com/docker-hub/builds/ |
| 38 | + push: |
| 39 | + # Ensure test job passes before pushing image. |
| 40 | + # needs: test |
| 41 | + if: "!contains(github.event.head_commit.message, 'skip ci')" |
| 42 | + runs-on: ubuntu-latest |
| 43 | + |
| 44 | + steps: |
| 45 | + - uses: actions/checkout@v2 |
| 46 | + |
| 47 | + - name: Build image |
| 48 | + run: docker build --build-arg MOD=readonly . --file Dockerfile --tag image |
| 49 | + |
| 50 | + - name: Log into registry |
| 51 | + run: echo "${{ secrets.DOCKER_HUB_TOKEN }}" | docker login -u ${{ github.actor }} --password-stdin |
| 52 | + |
| 53 | + - name: Push image |
| 54 | + run: | |
| 55 | + # Strip git ref prefix from version |
| 56 | + VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') |
| 57 | +
|
| 58 | + # Strip "v" prefix from tag name |
| 59 | + [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') |
| 60 | +
|
| 61 | + # Use Docker `latest` tag convention |
| 62 | + [ "$VERSION" == "master" ] && VERSION=latest |
| 63 | +
|
| 64 | + echo IMAGE_NAME=$IMAGE_NAME |
| 65 | + echo VERSION=$VERSION |
| 66 | +
|
| 67 | + docker tag image $IMAGE_NAME:$VERSION |
| 68 | + docker push $IMAGE_NAME:$VERSION |
0 commit comments