ci: simplify docker push action steps

This commit is contained in:
Haishan 2020-11-14 14:57:49 +08:00
parent d0be66d696
commit a2bcffe7fb

View file

@ -64,40 +64,43 @@ jobs:
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/') if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/')
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Docker meta
id: docker_meta
uses: crazy-max/ghaction-docker-meta@v1
with:
images: haishanh/yacd
- name: Set up QEMU - name: Set up QEMU
uses: docker/setup-qemu-action@v1 uses: docker/setup-qemu-action@v1
with:
platforms: linux/amd64,linux/arm/v7,linux/arm64
- name: Set up Docker Buildx - name: Set up Docker Buildx
id: buildx id: buildx
uses: docker/setup-buildx-action@v1 uses: docker/setup-buildx-action@v1
with: with:
version: latest version: latest
- name: Builder instance name - name: Builder instance name
run: echo ${{ steps.buildx.outputs.name }} run: echo ${{ steps.buildx.outputs.name }}
- name: Available platforms - name: Available platforms
run: echo ${{ steps.buildx.outputs.platforms }} run: echo ${{ steps.buildx.outputs.platforms }}
- name: Log in to Docker Hub
env: - name: Login to Docker Hub
DOCKER_USERNAME: ${{ github.actor }} uses: docker/login-action@v1
DOCKER_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }} with:
run: | username: ${{ github.actor }}
echo "${DOCKER_PASSWORD}" | docker login --username ${DOCKER_USERNAME} --password-stdin password: ${{ secrets.DOCKER_HUB_PASSWORD }}
- name: Build and push Docker image
env: - name: Build and push
DOCKER_USERNAME: ${{ github.actor }} uses: docker/build-push-action@v2
DOCKER_IMAGE_PLATFORM: linux/amd64,linux/arm/v7,linux/arm64 with:
REPOSITORY_NAME: ${{ github.repository }} context: .
run: | file: ./Dockerfile
IFS='/' read -ra repository_name_array <<<"$REPOSITORY_NAME" platforms: linux/amd64,linux/arm/v7,linux/arm64
DOCKER_IMAGE_NAME=$(echo $DOCKER_USERNAME/${repository_name_array[1]} | tr '[:upper:]' '[:lower:]') push: true
DOCKER_IMAGE_VERSION=${GITHUB_REF#refs/*/} tags: ${{ steps.docker_meta.outputs.tags }}
docker buildx build \ labels: ${{ steps.docker_meta.outputs.labels }}
--platform "$DOCKER_IMAGE_PLATFORM" \
--output "type=image,push=true" \
--tag "$DOCKER_IMAGE_NAME":"$DOCKER_IMAGE_VERSION" \
--tag "$DOCKER_IMAGE_NAME":latest \
--file ./Dockerfile .
- name: Send Notification - name: Send Notification
uses: haishanh/actions-telegram-notification@v1 uses: haishanh/actions-telegram-notification@v1
if: ${{ always() }} if: ${{ always() }}