|
| 1 | +--- |
| 2 | +name: 'build images' |
| 3 | + |
| 4 | +on: |
| 5 | + push: |
| 6 | + tags: |
| 7 | + - '[0-9]+.[0-9]+.[0-9]+' |
| 8 | + |
| 9 | +jobs: |
| 10 | + docker: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - name: Checkout |
| 14 | + uses: actions/checkout@v2 |
| 15 | + |
| 16 | + - name: Prepare |
| 17 | + id: prep |
| 18 | + run: | |
| 19 | + DOCKER_IMAGE=${{ secrets.DOCKER_USERNAME }}/${GITHUB_REPOSITORY#*/} |
| 20 | + VERSION=latest |
| 21 | + SHORTREF=${GITHUB_SHA::8} |
| 22 | +
|
| 23 | + # If this is git tag, use the tag name as a docker tag |
| 24 | + if [[ $GITHUB_REF == refs/tags/* ]]; then |
| 25 | + SEM_TAG=${GITHUB_REF#refs/tags/v} |
| 26 | + VERSION=${SEM_TAG:(-5)} |
| 27 | + fi |
| 28 | + TAGS="${DOCKER_IMAGE}:${VERSION},${DOCKER_IMAGE}:${SHORTREF}" |
| 29 | +
|
| 30 | + # If the VERSION looks like a version number, assume that |
| 31 | + # this is the most recent version of the image and also |
| 32 | + # tag it 'latest'. |
| 33 | + if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then |
| 34 | + TAGS="$TAGS,${DOCKER_IMAGE}:latest" |
| 35 | + fi |
| 36 | +
|
| 37 | + # Set output parameters. |
| 38 | + echo ::set-output name=tags::${TAGS} |
| 39 | + echo ::set-output name=docker_image::${DOCKER_IMAGE} |
| 40 | +
|
| 41 | + - name: Set up QEMU |
| 42 | + uses: docker/setup-qemu-action@master |
| 43 | + with: |
| 44 | + platforms: all |
| 45 | + |
| 46 | + - name: Set up Docker Buildx |
| 47 | + id: buildx |
| 48 | + uses: docker/setup-buildx-action@master |
| 49 | + |
| 50 | + - name: Login to DockerHub |
| 51 | + if: github.event_name != 'pull_request' |
| 52 | + uses: docker/login-action@v1 |
| 53 | + with: |
| 54 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 55 | + password: ${{ secrets.DOCKER_PASSWORD }} |
| 56 | + |
| 57 | + - name: Build |
| 58 | + uses: docker/build-push-action@v2 |
| 59 | + with: |
| 60 | + builder: ${{ steps.buildx.outputs.name }} |
| 61 | + context: . |
| 62 | + file: ./Dockerfile |
| 63 | + platforms: linux/amd64,linux/arm64 |
| 64 | + push: true |
| 65 | + tags: ${{ steps.prep.outputs.tags }} |
0 commit comments