Skip to content

减少layer

减少layer #41

name: Build and Publish Docker Image
# refer to https://github.com/actions/starter-workflows/blob/main/ci/docker-publish.yml
on:
# Trigger the workflow on push or pull request,
# but only for the master branch
push:
branches:
- master
pull_request:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
environment: docker
steps:
- name: Checkout repository
uses: actions/checkout@v4
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry
# if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Get Time
id: time
uses: nanzm/[email protected]
with:
timeZone: 8
format: "YYYYMMDD-HHmmss"
- name: Prepare environment variables
id: env
run: |
IMAGE_NAME=$(echo $GITHUB_REPOSITORY | sed "s#${GITHUB_REPOSITORY_OWNER}/docker-##")
echo "IMAGE_NAME=${IMAGE_NAME}" >> $GITHUB_OUTPUT
# Build and push Docker image with Buildx
# https://github.com/docker/build-push-action
- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
push: true
context: .
tags: ${{ secrets.DOCKER_HUB_USER }}/${{ steps.env.outputs.IMAGE_NAME }}, ${{ secrets.DOCKER_HUB_USER }}/${{ steps.env.outputs.IMAGE_NAME }}:${{ steps.time.outputs.time }}