This repository has been archived by the owner on Jun 6, 2024. It is now read-only.
fix: cannot login admin #12
Workflow file for this run
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
name: Build Docker Image | |
on: | |
workflow_dispatch: | |
push: | |
# 每次 push tag 时进行构建,不需要每次 push 都构建。使用通配符匹配每次 tag 的提交,记得 tag 名一定要以 v 开头 | |
tags: | |
- v* | |
env: | |
# 设置 docker 镜像名 | |
IMAGE_NAME: baiduwp-php | |
jobs: | |
# Push image to GitHub Packages. | |
# See also https://docs.docker.com/docker-hub/builds/ | |
push: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
# 构建镜像,指定镜像名 | |
- name: Build image | |
run: docker build . --file Dockerfile --tag $IMAGE_NAME | |
# 登录到 dockerhub,使用 GitHub secrets 传入账号密码,密码被加密存储在 GitHub 服务器 | |
- name: Log into registry | |
run: echo "${{ secrets.DOCKER_ACCESS_TOKEN }}" | docker login -u yuantuo666 --password-stdin | |
- name: Push image | |
run: | | |
# 拼接镜像 id,这个镜像 id 就是在使用 docker 镜像时 pull 后面的名字。 | |
IMAGE_ID=yuantuo666/$IMAGE_NAME | |
# 将所有的大写字母转为小写 | |
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') | |
# 从 GitHub.ref 中取出版本 | |
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') | |
# 从 tag 名字中替换 v 字符 | |
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') | |
# Use Docker `latest` tag convention | |
[ "$VERSION" == "master" ] && VERSION=latest | |
echo IMAGE_ID=$IMAGE_ID | |
echo VERSION=$VERSION | |
# 设置镜像 id 和版本号 | |
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION | |
# 进行 push | |
docker push $IMAGE_ID:$VERSION | |
# push 到 latest | |
[ "$VERSION" != "latest" ] && docker tag $IMAGE_NAME $IMAGE_ID:latest | |
[ "$VERSION" != "latest" ] && docker push $IMAGE_ID:latest | |