diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..383dbda --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,69 @@ +name: Docker + +on: + push: + # Publish `main` as Docker `latest` image. + branches: + - main + + # Publish `v1.2.3` tags as releases. + tags: + - v* + + # Run tests for any PRs. + pull_request: + +env: + # TODO: Change variable to your image's name. + IMAGE_NAME: cea-check-in + +jobs: + # Run tests. + # See also https://docs.docker.com/docker-hub/builds/automated-testing/ + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Run tests + run: | + if [ -f docker-compose.test.yml ]; then + docker-compose --file docker-compose.test.yml build + docker-compose --file docker-compose.test.yml run sut + else + docker build https://github.com/ceajs/cea.git#main:docker + fi + # Push image to GitHub Packages. + # See also https://docs.docker.com/docker-hub/builds/ + push: + # Ensure test job passes before pushing image. + needs: test + + runs-on: ubuntu-latest + if: github.event_name == 'push' + + steps: + - uses: actions/checkout@v2 + + - name: Build image + run: docker build https://github.com/ceajs/cea.git#main:docker --tag $IMAGE_NAME + + - name: Log into registry + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin + + - name: Push image + run: | + IMAGE_ID=ghcr.io/${{ github.repository }}/$IMAGE_NAME + # Change all uppercase to lowercase + IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') + # Strip git ref prefix from version + VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') + # Strip "v" prefix from tag name + [[ "${{ 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 + docker tag $IMAGE_NAME $IMAGE_ID:$VERSION + docker push $IMAGE_ID:$VERSION diff --git a/docs/deploy.md b/docs/deploy.md index f73e320..1d04afa 100644 --- a/docs/deploy.md +++ b/docs/deploy.md @@ -5,18 +5,33 @@ 2. 构建 Image 并运行 Container ```bash + # 在本地构建 Image sudo docker build -t cea-check-in https://github.com/ceajs/cea.git#main:docker - sudo docker run -dv /tmp/conf:/tmp/conf cea-check-in + + # 创建容器 + sudo docker run --name auto-check-in -dv /tmp/conf:/tmp/conf cea-check-in + ``` + + 如果使用境内服务器,由于网络问题,构建可能失败,可以使用本仓库已经构建完成的镜像 + + ```bash + sudo docker run --name auto-check-in -dv /tmp/conf:/tmp/conf ghcr.io/ceajs/cea/cea-check-in:main ``` - 此容器自动设置了 Cron 任务,将会在每天 6:30 触发执行签到,如需自定义触发时间,请 Fork 本仓库,修改 `docker/cea-cron`,并另行构建镜像与容器 + 此容器自动设置了 Cron 任务,将会在每天 6:30 触发执行签到,如需自定义触发时间,请 Fork 本仓库(或者 Clone 本仓库),修改 `docker/cea-cron`,并另行构建镜像与容器 ``` + # 如果你是 Fork 并 Push 了修改 sudo docker build -t cea-check-in Fork仓库的GitURL#main:docker - sudo docker run -dv /tmp/conf:/tmp/conf cea-check-in + + # 如果你是 Clone 并在本地修改,请进入 docker 文件夹 + sudo docker build -t cea-check-in . + + # 创建容器 + sudo docker run --name auto-check-in -dv /tmp/conf:/tmp/conf cea-check-in ``` - +
腾讯云开发一键部署