|
1 | | -name: Create a release on pypi.org |
| 1 | +name: Publish |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
|
32 | 32 | uses: pypa/gh-action-pypi-publish@master |
33 | 33 | with: |
34 | 34 | password: ${{ secrets.PYPI_API_TOKEN }} |
| 35 | + |
| 36 | + publish-docker: |
| 37 | + runs-on: ubuntu-20.04 |
| 38 | + env: |
| 39 | + DEFAULT_REGISTRY: quay.io |
| 40 | + IMAGE_NAME: jupyterhub/repo2docker |
| 41 | + |
| 42 | + services: |
| 43 | + # So that we can test this in PRs/branches |
| 44 | + local-registry: |
| 45 | + image: registry:2 |
| 46 | + ports: |
| 47 | + - 5000:5000 |
| 48 | + |
| 49 | + steps: |
| 50 | + - name: Should we push this image to a public registry? |
| 51 | + run: | |
| 52 | + if [ "${{ startsWith(github.ref, 'refs/tags/') || (github.ref == 'refs/heads/main') }}" = "true" ]; then |
| 53 | + REGISTRY=$DEFAULT_REGISTRY |
| 54 | + else |
| 55 | + REGISTRY=localhost:5000 |
| 56 | + fi |
| 57 | + echo "REGISTRY=$REGISTRY" >> $GITHUB_ENV |
| 58 | + echo "Publishing to $REGISTRY" |
| 59 | +
|
| 60 | + # versioneer requires the full git history for non-tags |
| 61 | + - uses: actions/checkout@v2 |
| 62 | + with: |
| 63 | + fetch-depth: 0 |
| 64 | + |
| 65 | + # Setup docker to build for multiple platforms, see: |
| 66 | + # https://github.com/docker/build-push-action/tree/v2.4.0#usage |
| 67 | + # https://github.com/docker/build-push-action/blob/v2.4.0/docs/advanced/multi-platform.md |
| 68 | + |
| 69 | + - name: Set up QEMU (for docker buildx) |
| 70 | + uses: docker/setup-qemu-action@25f0500ff22e406f7191a2a8ba8cda16901ca018 |
| 71 | + |
| 72 | + - name: Set up Docker Buildx (for multi-arch builds) |
| 73 | + uses: docker/setup-buildx-action@2a4b53665e15ce7d7049afb11ff1f70ff1610609 |
| 74 | + with: |
| 75 | + # Allows pushing to registry on localhost:5000 |
| 76 | + driver-opts: network=host |
| 77 | + |
| 78 | + - name: Setup push rights to Docker Hub |
| 79 | + if: env.REGISTRY != 'localhost:5000' |
| 80 | + run: | |
| 81 | + docker login -u "${{ secrets.DOCKER_REGISTRY_USERNAME }}" -p "${{ secrets.DOCKER_REGISTRY_TOKEN }}" "${{ env.REGISTRY }}" |
| 82 | +
|
| 83 | + # when building jupyter/repo2docker:master |
| 84 | + # also push jupyter/repo2docker:1.2.3-3.abcd1234 (replace + with -) |
| 85 | + - name: Get list of repo2docker docker tags |
| 86 | + run: | |
| 87 | + VERSION=$(python3 -c 'import versioneer; print(versioneer.get_version().replace("+", "-"))') |
| 88 | + TAGS="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:$VERSION" |
| 89 | + if [ "${{ github.ref }}" == "refs/heads/main" ]; then |
| 90 | + TAGS="$TAGS,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:main" |
| 91 | + fi |
| 92 | + echo "TAGS=$TAGS" |
| 93 | + echo "TAGS=$TAGS" >> $GITHUB_ENV |
| 94 | +
|
| 95 | + - name: Build and push repo2docker |
| 96 | + uses: docker/build-push-action@e1b7f96249f2e4c8e4ac1519b9608c0d48944a1f |
| 97 | + with: |
| 98 | + context: . |
| 99 | + platforms: linux/amd64 |
| 100 | + push: true |
| 101 | + tags: ${{ env.TAGS }} |
0 commit comments