|
| 1 | +name: Publish docker images |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - main |
| 6 | + release: |
| 7 | + types: [published] |
| 8 | +jobs: |
| 9 | + publish-pypi: |
| 10 | + name: Publish script-runner to pypi |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - name: Publish a Python distribution to PyPI |
| 14 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 15 | + with: |
| 16 | + user: __token__ |
| 17 | + password: ${{ secrets.PYPI_API_TOKEN }} |
| 18 | + |
| 19 | + publish-docker: |
| 20 | + name: Publish script-runner to dockerhub |
| 21 | + runs-on: ubuntu-latest |
| 22 | + steps: |
| 23 | + - name: Check out the repo |
| 24 | + uses: actions/checkout@v2 |
| 25 | + - name: Prepare |
| 26 | + id: prep |
| 27 | + run: | |
| 28 | + PYTHON_IMAGE_TAG=alpine |
| 29 | + DOCKER_IMAGE=labflow/swabseq-analysis-server |
| 30 | + VERSION=latest |
| 31 | + if [[ $GITHUB_REF == refs/tags/* ]]; then |
| 32 | + VERSION=${GITHUB_REF#refs/tags/} |
| 33 | + elif [[ $GITHUB_REF == refs/heads/* ]]; then |
| 34 | + VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g') |
| 35 | + elif [[ $GITHUB_REF == refs/pull/* ]]; then |
| 36 | + VERSION=pr-${{ github.event.number }} |
| 37 | + fi |
| 38 | + TAGS="${DOCKER_IMAGE}:${PYTHON_IMAGE_TAG}-latest,${DOCKER_IMAGE}:${PYTHON_IMAGE_TAG}-${VERSION}" |
| 39 | + if [ "${{ github.event_name }}" = "push" ]; then |
| 40 | + TAGS="$TAGS,${DOCKER_IMAGE}:${PYTHON_IMAGE_TAG}-sha-${GITHUB_SHA::8}" |
| 41 | + fi |
| 42 | + echo ::set-output name=version::${VERSION} |
| 43 | + echo ::set-output name=tags::${TAGS} |
| 44 | + echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ') |
| 45 | + echo ::set-output name=hashtag::"sha-${GITHUB_SHA::8}" |
| 46 | + echo ::set-output name=pyversion::"${PYTHON_IMAGE_TAG}" |
| 47 | + - name: Set up Docker Buildx |
| 48 | + id: buildx |
| 49 | + uses: docker/setup-buildx-action@v1 |
| 50 | + - name: Cache Docker layers |
| 51 | + uses: actions/cache@v2.1.4 |
| 52 | + with: |
| 53 | + path: /tmp/.buildx-cache |
| 54 | + key: ${{ runner.os }}-buildx-${{ github.sha }} |
| 55 | + restore-keys: | |
| 56 | + ${{ runner.os }}-buildx- |
| 57 | + - name: Login to DockerHub |
| 58 | + if: github.event_name != 'pull_request' |
| 59 | + uses: docker/login-action@v1 |
| 60 | + with: |
| 61 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 62 | + password: ${{ secrets.DOCKER_PASSWORD }} |
| 63 | + - name: Push to Docker Hub |
| 64 | + uses: docker/build-push-action@v2 |
| 65 | + with: |
| 66 | + context: ./docker |
| 67 | + file: ./Dockerfile |
| 68 | + builder: ${{ steps.buildx.outputs.name }} |
| 69 | + push: ${{ github.event_name != 'pull_request' }} |
| 70 | + tags: ${{ steps.prep.outputs.tags }} |
| 71 | + cache-from: type=local,src=/tmp/.buildx-cache |
| 72 | + cache-to: type=local,dest=/tmp/.buildx-cache |
| 73 | + labels: | |
| 74 | + org.opencontainers.image.source=${{ github.event.repository.clone_url }} |
| 75 | + org.opencontainers.image.created=${{ steps.prep.outputs.created }} |
| 76 | + org.opencontainers.image.revision=${{ github.sha }} |
| 77 | + build-args: | |
| 78 | + SCRIPT_RUNNER_VERSION=${{ steps.prep.outputs.version }} |
| 79 | + PYTHON_IMAGE_TAG=${{ steps.prep.outputs.pyversion }} |
0 commit comments