|
| 1 | +name: Docker Image Push (on commit and base image update) |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ "master" ] |
| 6 | + schedule: |
| 7 | + - cron: "15 */8 * * *" |
| 8 | + |
| 9 | +env: |
| 10 | + IMAGE_OWNER: kimbtechnologies |
| 11 | + IMAGE_NAME: php_nginx |
| 12 | + BASE_IMAGE: library/php:fpm-alpine |
| 13 | + |
| 14 | +jobs: |
| 15 | + build: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + |
| 19 | + # check if update needed |
| 20 | + - name: Check for new baseimage |
| 21 | + id: check |
| 22 | + uses: lucacome/docker-image-update-checker@v1 |
| 23 | + with: |
| 24 | + base-image: "${{env.BASE_IMAGE}}" |
| 25 | + image: "${{env.IMAGE_OWNER}}/${{env.IMAGE_NAME}}:latest" |
| 26 | + #env: |
| 27 | + # DEBUG: true |
| 28 | + if: github.event_name != 'push' |
| 29 | + |
| 30 | + # setup build env. |
| 31 | + - name: Access repository contents |
| 32 | + uses: actions/checkout@v4 |
| 33 | + if: ${{ (github.event_name == 'push') || (steps.check.outputs.needs-updating == 'true') }} |
| 34 | + - name: Login to DockerHub |
| 35 | + uses: docker/login-action@v3 |
| 36 | + with: |
| 37 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 38 | + password: ${{ secrets.DOCKER_TOKEN }} |
| 39 | + if: ${{ (github.event_name == 'push') || (steps.check.outputs.needs-updating == 'true') }} |
| 40 | + |
| 41 | + # build local AMD image |
| 42 | + - name: Build the AMD image |
| 43 | + run: docker build . --file "Dockerfile" --tag "$IMAGE_OWNER/$IMAGE_NAME:latest" |
| 44 | + if: ${{ (github.event_name == 'push') || (steps.check.outputs.needs-updating == 'true') }} |
| 45 | + - name: Push tag 8-latest |
| 46 | + run: docker tag "$IMAGE_OWNER/$IMAGE_NAME:latest" "$IMAGE_OWNER/$IMAGE_NAME:8-latest"; docker push "$IMAGE_OWNER/$IMAGE_NAME:8-latest"; |
| 47 | + if: ${{ (github.event_name == 'push') || (steps.check.outputs.needs-updating == 'true') }} |
| 48 | + |
| 49 | + # Multi platform support |
| 50 | + - name: Set up QEMU for Docker Buildx |
| 51 | + uses: docker/setup-qemu-action@v3 |
| 52 | + if: ${{ (github.event_name == 'push') || (steps.check.outputs.needs-updating == 'true') }} |
| 53 | + - name: Set up Docker Buildx |
| 54 | + uses: docker/setup-buildx-action@v3 |
| 55 | + if: ${{ (github.event_name == 'push') || (steps.check.outputs.needs-updating == 'true') }} |
| 56 | + |
| 57 | + # Multi platform image build and push |
| 58 | + - name: Build and push the ARM Docker images |
| 59 | + run: php_v=$(docker run --rm "$IMAGE_OWNER/$IMAGE_NAME:latest" sh -c 'echo "$PHP_VERSION"'); php_v=$(echo $php_v | grep -o '[0-9\.]*'); docker buildx build --platform linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/arm64 . --file "Dockerfile" --tag "$IMAGE_OWNER/$IMAGE_NAME:latest" --tag "$IMAGE_OWNER/$IMAGE_NAME:php-$php_v" --push |
| 60 | + if: ${{ (github.event_name == 'push') || (steps.check.outputs.needs-updating == 'true') }} |
| 61 | + |
0 commit comments