2020-10-12 20:51:13 +08:00
|
|
|
name: Build Docker Image
|
|
|
|
on: [push]
|
2019-11-09 14:52:28 +08:00
|
|
|
jobs:
|
2020-10-12 20:51:13 +08:00
|
|
|
build:
|
2019-11-09 14:52:28 +08:00
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
2020-08-29 04:58:46 +08:00
|
|
|
- name: Set up Checkout
|
|
|
|
uses: actions/checkout@v2
|
2020-10-12 20:51:13 +08:00
|
|
|
- name: Set up QEMU
|
|
|
|
uses: docker/setup-qemu-action@v1
|
|
|
|
with:
|
|
|
|
platforms: linux/amd64,linux/arm/v7,linux/arm64
|
|
|
|
- name: Set up Docker Buildx
|
|
|
|
id: buildx
|
|
|
|
uses: docker/setup-buildx-action@v1
|
|
|
|
with:
|
|
|
|
version: latest
|
|
|
|
- name: Builder instance name
|
|
|
|
run: echo ${{ steps.buildx.outputs.name }}
|
|
|
|
- name: Available platforms
|
|
|
|
run: echo ${{ steps.buildx.outputs.platforms }}
|
|
|
|
|
2020-08-29 04:58:46 +08:00
|
|
|
- name: Log in to Docker Hub
|
2020-10-12 20:51:13 +08:00
|
|
|
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/')
|
2020-08-29 04:58:46 +08:00
|
|
|
env:
|
|
|
|
DOCKER_USERNAME: ${{ github.actor }}
|
|
|
|
DOCKER_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }}
|
|
|
|
run: |
|
|
|
|
echo "${DOCKER_PASSWORD}" | docker login --username ${DOCKER_USERNAME} --password-stdin
|
2020-10-12 20:51:13 +08:00
|
|
|
|
2020-08-29 04:58:46 +08:00
|
|
|
- name: Build and push Docker image
|
2020-10-12 20:51:13 +08:00
|
|
|
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/')
|
2020-08-29 04:58:46 +08:00
|
|
|
env:
|
|
|
|
DOCKER_USERNAME: ${{ github.actor }}
|
|
|
|
DOCKER_IMAGE_PLATFORM: linux/amd64,linux/arm/v7,linux/arm64
|
|
|
|
REPOSITORY_NAME: ${{ github.repository }}
|
2019-11-09 14:52:28 +08:00
|
|
|
run: |
|
2020-08-29 04:58:46 +08:00
|
|
|
IFS='/' read -ra repository_name_array <<<"$REPOSITORY_NAME"
|
|
|
|
DOCKER_IMAGE_NAME=$(echo $DOCKER_USERNAME/${repository_name_array[1]} | tr '[:upper:]' '[:lower:]')
|
|
|
|
DOCKER_IMAGE_VERSION=${GITHUB_REF#refs/*/}
|
|
|
|
docker buildx build \
|
|
|
|
--platform "$DOCKER_IMAGE_PLATFORM" \
|
|
|
|
--output "type=image,push=true" \
|
|
|
|
--tag "$DOCKER_IMAGE_NAME":"$DOCKER_IMAGE_VERSION" \
|
|
|
|
--tag "$DOCKER_IMAGE_NAME":latest \
|
|
|
|
--file ./Dockerfile .
|
2020-10-12 20:51:13 +08:00
|
|
|
|
|
|
|
- name: Send Notification
|
|
|
|
uses: haishanh/actions-telegram-notification@v1
|
|
|
|
if: ${{ always() }}
|
|
|
|
with:
|
|
|
|
notification-token: ${{ secrets.TG_NOTIFICATION_TOKEN }}
|
|
|
|
job-status: ${{ job.status }}
|