|
| 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 | + |
| 13 | + # Run tests for any PRs. |
| 14 | + pull_request: |
| 15 | + |
| 16 | +env: |
| 17 | + # TODO: Change variable to your image's name. |
| 18 | + IMAGE_NAME: image |
| 19 | + |
| 20 | +jobs: |
| 21 | + # Run tests. |
| 22 | + # See also https://docs.docker.com/docker-hub/builds/automated-testing/ |
| 23 | + test: |
| 24 | + runs-on: ubuntu-latest |
| 25 | + |
| 26 | + steps: |
| 27 | + - uses: actions/checkout@v2 |
| 28 | + |
| 29 | + - name: Run tests |
| 30 | + run: | |
| 31 | + if [ -f docker-compose.test.yml ]; then |
| 32 | + docker-compose --file docker-compose.test.yml build |
| 33 | + docker-compose --file docker-compose.test.yml run sut |
| 34 | + else |
| 35 | + docker build . --file Dockerfile |
| 36 | + fi |
| 37 | +
|
| 38 | + # Push image to GitHub Packages. |
| 39 | + # See also https://docs.docker.com/docker-hub/builds/ |
| 40 | +# push: |
| 41 | +# # Ensure test job passes before pushing image. |
| 42 | +# needs: test |
| 43 | + |
| 44 | +# runs-on: ubuntu-latest |
| 45 | +# if: github.event_name == 'push' |
| 46 | + |
| 47 | +# steps: |
| 48 | +# - uses: actions/checkout@v2 |
| 49 | + |
| 50 | +# - name: Build image |
| 51 | +# run: docker build . --file Dockerfile --tag $IMAGE_NAME |
| 52 | + |
| 53 | +# - name: Log into GitHub Container Registry |
| 54 | +# # TODO: Create a PAT with `read:packages` and `write:packages` scopes and save it as an Actions secret `CR_PAT` |
| 55 | +# run: echo "${{ secrets.CR_PAT }}" | docker login https://ghcr.io -u ${{ github.actor }} --password-stdin |
| 56 | + |
| 57 | +# - name: Push image to GitHub Container Registry |
| 58 | +# run: | |
| 59 | +# IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME |
| 60 | + |
| 61 | +# # Change all uppercase to lowercase |
| 62 | +# IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') |
| 63 | + |
| 64 | +# # Strip git ref prefix from version |
| 65 | +# VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') |
| 66 | + |
| 67 | +# # Strip "v" prefix from tag name |
| 68 | +# [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') |
| 69 | + |
| 70 | +# # Use Docker `latest` tag convention |
| 71 | +# [ "$VERSION" == "master" ] && VERSION=latest |
| 72 | + |
| 73 | +# echo IMAGE_ID=$IMAGE_ID |
| 74 | +# echo VERSION=$VERSION |
| 75 | + |
| 76 | +# docker tag $IMAGE_NAME $IMAGE_ID:$VERSION |
| 77 | +# docker push $IMAGE_ID:$VERSION |
0 commit comments