|
1 | 1 | name: docker |
2 | 2 |
|
3 | | -on: [push] |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: master |
| 6 | + push: |
| 7 | + branches: master |
| 8 | + tags: |
| 9 | + - v* |
4 | 10 |
|
5 | 11 | jobs: |
6 | | - push-image: |
| 12 | + buildx: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - |
| 16 | + name: Checkout |
| 17 | + uses: actions/checkout@v2 |
| 18 | + - |
| 19 | + name: Prepare |
| 20 | + id: prepare |
| 21 | + run: | |
| 22 | + DOCKER_IMAGE=storedev/store-bot |
| 23 | + DOCKER_PLATFORMS=linux/amd64,linux/arm/v7,linux/arm64 |
| 24 | + VERSION=edge |
7 | 25 |
|
8 | | - runs-on: windows-latest |
| 26 | + if [[ $GITHUB_REF == refs/tags/* ]]; then |
| 27 | + VERSION=${GITHUB_REF#refs/tags/v} |
| 28 | + fi |
| 29 | + if [ "${{ github.event_name }}" = "schedule" ]; then |
| 30 | + VERSION=nightly |
| 31 | + fi |
9 | 32 |
|
10 | | - steps: |
11 | | - - uses: actions/checkout@v2 |
12 | | - - run: | |
13 | | - docker login --username ${{ secrets.DOCKER_USERNAME }} --password "${{ secrets.DOCKER_PASSWORD }}" |
14 | | - docker build -t storedev/store-bot . |
15 | | - docker tag storedev/store-bot storedev/store-bot:${{ github.sha }} |
16 | | - docker tag storedev/store-bot storedev/store-bot:Latest |
17 | | - docker push storedev/store-bot |
| 33 | + TAGS="--tag ${DOCKER_IMAGE}:${VERSION}" |
| 34 | + if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then |
| 35 | + TAGS="$TAGS --tag ${DOCKER_IMAGE}:latest" |
| 36 | + fi |
| 37 | +
|
| 38 | + echo ::set-output name=docker_image::${DOCKER_IMAGE} |
| 39 | + echo ::set-output name=version::${VERSION} |
| 40 | + echo ::set-output name=buildx_args::--platform ${DOCKER_PLATFORMS} \ |
| 41 | + --build-arg VERSION=${VERSION} \ |
| 42 | + --build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \ |
| 43 | + --build-arg VCS_REF=${GITHUB_SHA::8} \ |
| 44 | + ${TAGS} --file ./Dockerfile . |
| 45 | + - |
| 46 | + name: Set up Docker Buildx |
| 47 | + uses: crazy-max/ghaction-docker-buildx@v3 |
| 48 | + - |
| 49 | + name: Docker Buildx (build) |
| 50 | + run: | |
| 51 | + docker buildx build --output "type=image,push=false" ${{ steps.prepare.outputs.buildx_args }} |
| 52 | + - |
| 53 | + name: Login to DockerHub |
| 54 | + if: success() && github.event_name != 'pull_request' |
| 55 | + uses: docker/login-action@v1 |
| 56 | + with: |
| 57 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 58 | + password: ${{ secrets.DOCKER_PASSWORD }} |
| 59 | + - |
| 60 | + name: Docker Buildx (push) |
| 61 | + if: success() && github.event_name != 'pull_request' |
| 62 | + run: | |
| 63 | + docker buildx build --output "type=image,push=true" ${{ steps.prepare.outputs.buildx_args }} |
| 64 | + - |
| 65 | + name: Inspect image |
| 66 | + if: always() && github.event_name != 'pull_request' |
| 67 | + run: | |
| 68 | + docker buildx imagetools inspect ${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.version }} |
0 commit comments