|
| 1 | +name: Deploy to DockerHub |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + |
| 7 | +jobs: |
| 8 | + docker: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + steps: |
| 11 | + - name: Checkout |
| 12 | + |
| 13 | + - name: Prepare |
| 14 | + id: prep |
| 15 | + run: | |
| 16 | + DOCKER_IMAGE=alkemio/virtual-contributor-ingest-space |
| 17 | + VERSION=noop |
| 18 | + if [ "${{ github.event_name }}" = "schedule" ]; then |
| 19 | + VERSION=nightly |
| 20 | + elif [[ $GITHUB_REF == refs/tags/* ]]; then |
| 21 | + VERSION=${GITHUB_REF#refs/tags/} |
| 22 | + elif [[ $GITHUB_REF == refs/heads/* ]]; then |
| 23 | + VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g') |
| 24 | + if [ "${{ github.event.repository.default_branch }}" = "$VERSION" ]; then |
| 25 | + VERSION=edge |
| 26 | + fi |
| 27 | + elif [[ $GITHUB_REF == refs/pull/* ]]; then |
| 28 | + VERSION=pr-${{ github.event.number }} |
| 29 | + fi |
| 30 | + TAGS="${DOCKER_IMAGE}:${VERSION}" |
| 31 | + if [[ $VERSION =~ ^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then |
| 32 | + MINOR=${VERSION%.*} |
| 33 | + MAJOR=${MINOR%.*} |
| 34 | + TAGS="$TAGS,${DOCKER_IMAGE}:${MINOR},${DOCKER_IMAGE}:${MAJOR},${DOCKER_IMAGE}:latest" |
| 35 | + elif [ "${{ github.event_name }}" = "push" ]; then |
| 36 | + TAGS="$TAGS,${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}" |
| 37 | + fi |
| 38 | + echo "version=${VERSION}" >> $GITHUB_OUTPUT |
| 39 | + echo "tags=${TAGS}" >> $GITHUB_OUTPUT |
| 40 | + echo "created={$(date -u +'%Y-%m-%dT%H:%M:%SZ')}" >> $GITHUB_OUTPUT |
| 41 | + - name: Set up QEMU |
| 42 | + |
| 43 | + - name: Set up Docker Buildx |
| 44 | + |
| 45 | + - name: Login to DockerHub |
| 46 | + if: github.event_name != 'pull_request' |
| 47 | + uses: docker/login-action@v1 |
| 48 | + with: |
| 49 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 50 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 51 | + - name: Build and push |
| 52 | + id: docker_build |
| 53 | + |
| 54 | + with: |
| 55 | + context: . |
| 56 | + file: ./Dockerfile |
| 57 | + platforms: linux/amd64 |
| 58 | + push: ${{ github.event_name != 'pull_request' }} |
| 59 | + tags: ${{ steps.prep.outputs.tags }} |
| 60 | + labels: | |
| 61 | + org.opencontainers.image.title=${{ github.event.repository.name }} |
| 62 | + org.opencontainers.image.description=${{ github.event.repository.description }} |
| 63 | + org.opencontainers.image.url=${{ github.event.repository.html_url }} |
| 64 | + org.opencontainers.image.source=${{ github.event.repository.clone_url }} |
| 65 | + org.opencontainers.image.version=${{ steps.prep.outputs.version }} |
| 66 | + org.opencontainers.image.created=${{ steps.prep.outputs.created }} |
| 67 | + org.opencontainers.image.revision=${{ github.sha }} |
| 68 | + org.opencontainers.image.licenses=${{ github.event.repository.license.spdx_id }} |
0 commit comments