-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c4666d6
commit 1a4dc27
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: Build and Push Docker Image | ||
|
||
on: | ||
push: | ||
branches: | ||
- main # 你可以根据需要更改触发条件,如 `main` 分支 | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
# 1. 检出代码 | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
# 2. 设置 Docker Buildx | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
# 3. 登录 Docker Hub | ||
- name: Log in to Docker Hub | ||
uses: docker/#-action@v2 | ||
with: | ||
username: ${{ secrets.DOCKER_USERNAME }} # 你的 Docker Hub 用户名 | ||
password: ${{ secrets.DOCKER_PASSWORD }} # 你的 Docker Hub 密码 (存储在 GitHub Secrets) | ||
|
||
# 4. 构建 Docker 镜像 | ||
- name: Build Docker image | ||
run: | | ||
docker build -t ${{ secrets.DOCKER_USERNAME }}/your-image-name:latest . | ||
# 5. 推送 Docker 镜像到 Docker Hub | ||
- name: Push Docker image | ||
run: | | ||
docker push ${{ secrets.DOCKER_USERNAME }}/your-image-name:latest |