Skip to content

Commit

Permalink
chore: 自动构建镜像并推送到 docker hub
Browse files Browse the repository at this point in the history
  • Loading branch information
Dedicatus546 committed Feb 21, 2024
1 parent 7df6fb0 commit aa376a7
Showing 1 changed file with 14 additions and 21 deletions.
35 changes: 14 additions & 21 deletions .github/workflows/dockerbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,34 @@ name: Create and publish a Docker image

on:
push:
tags:
- '*'

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
branches: ["master"]

jobs:
build-and-push-image:
push_to_registry:
name: Push Docker image to Docker Hub
environment: production
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Check out the repo
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
- name: Login to Docker Hub
uses: docker/login-action@v3.0.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
uses: docker/metadata-action@v5.5.1
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
images: dedicatus545/github-cors-server

- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

0 comments on commit aa376a7

Please sign in to comment.