fix: cdn fix #52
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
# debug locally | |
# act -W ./.github/workflows/deploy.yml --secret-file ./.github/.secrets --var-file ./.github/.vars -P ubuntu-latest=ghcr.io/catthehacker/ubuntu:js-latest | |
name: Deploy | |
on: | |
# release: | |
# types: [published] | |
push: # push 到主分支自动 发布 | |
branches: ['master'] | |
paths-ignore: # 忽略一些不必要的文件 | |
- '.gitignore' | |
- 'nginx.conf' | |
- 'Gruntfile.js' | |
- 'README.md' | |
- '.vscode/**' | |
- '.devcontainer/**' | |
# pull_request: | |
# branches: ['master'] | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_REPOSITORY: $(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]') | |
DOCKER_COMPOSE_DIR: /opt/pomelo | |
permissions: | |
contents: read | |
packages: write | |
jobs: | |
cache: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository and submodules | |
uses: actions/checkout@v3 | |
with: | |
submodules: recursive | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '16.14' | |
- name: Cache main install | |
uses: actions/cache@v3 | |
id: cache | |
with: | |
path: | | |
node_modules | |
.yarn/cache | |
key: ${{ runner.os }}-node-${{ hashFiles('yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-node- | |
- name: Cache submodules | |
uses: actions/cache@v3 | |
id: submodules-cache | |
with: | |
path: .submodules | |
key: ${{ runner.os }}-submodules-${{ hashFiles('.submodules/**/yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-submodules- | |
- name: Install Dependencies | |
if: steps.cache.outputs.cache-hit != 'true' | |
run: yarn install --mode=skip-build && npx vue-demi-fix | |
- name: Build Submodules | |
if: steps.submodules-cache.outputs.cache-hit != 'true' | |
run: yarn build:submodules | |
docker-build: | |
needs: cache | |
runs-on: ubuntu-latest | |
environment: | |
name: 'production' | |
steps: | |
- name: Checkout repository and submodules | |
uses: actions/checkout@v3 | |
with: | |
submodules: recursive | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v1 | |
with: | |
registry: ${{ env.REGISTRY }} # 声明镜像源 | |
username: ${{ github.actor }} # 当前github 用户名 | |
password: ${{ secrets.GITHUB_TOKEN }} # 当前github token | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '16.14' | |
- name: Restore main install cache | |
uses: actions/cache/restore@v3 | |
with: | |
path: | | |
node_modules | |
.yarn/cache | |
key: ${{ runner.os }}-node-${{ hashFiles('yarn.lock') }} | |
- name: Restore submodules cache | |
uses: actions/cache/restore@v3 | |
with: | |
path: .submodules | |
key: ${{ runner.os }}-submodules-${{ hashFiles('.submodules/**/yarn.lock') }} | |
- name: Build | |
run: yarn build:clients && yarn build:servers | |
- name: Show Dir | |
run: ls | |
- name: Build the Docker image | |
run: | |
| # 使用 上一步写的 Dockerfile 构建镜像并发布到私有仓库; 发布完成可以去 https://github.com/aceHubert?tab=packages 查看 | |
docker build . --file Dockerfile --target deploy --cache-from ${{ env.REGISTRY }}/${{ env.IMAGE_REPOSITORY }}:latest --build-arg BUILD_IGNORE=true --build-arg BUILDKIT_INLINE_CACHE=1 --label "build-id=${{ github.run_id }}" --label "build-user=${{ github.actor }}" --tag ${{ env.REGISTRY }}/${{ env.IMAGE_REPOSITORY }}:latest --tag ${{ env.REGISTRY }}/${{ env.IMAGE_REPOSITORY }}:${{ github.run_id }} | |
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_REPOSITORY }}:${{ github.run_id }} | |
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_REPOSITORY }}:latest | |
ssh-deploy: | |
needs: docker-build | |
runs-on: ubuntu-latest | |
environment: | |
name: 'production' | |
steps: | |
- name: Deploy | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.SSH_HOST }} # 服务器ip地址 ; 需要去仓库的 settings/secrets/actions 去创建 | |
username: ${{ secrets.SSH_USERNAME }} # 服务器用户名称;需要去仓库的 settings/secrets/actions 去创建 | |
key: ${{ secrets.SSH_KEY }} # 服务器密码;需要去仓库的 settings/secrets/actions 去创建 | |
port: ${{ secrets.SSH_PORT }} # 服务器端口,默认22;需要去仓库的 settings/secrets/actions 去创建 | |
script: | # 发布镜像并删除之前的镜像 | |
cd ${{ env.DOCKER_COMPOSE_DIR }} | |
echo "IMAGE_REPOSITORY=${{ env.REGISTRY }}/${{ env.IMAGE_REPOSITORY }}:${{ github.run_id }}" > .env.${{ github.run_id }} | |
docker login -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }} https://${{ env.REGISTRY }} | |
docker compose --env-file .env.${{ github.run_id }} up --force-recreate -d | |
docker images -q ${{ env.REGISTRY }}/${{ env.IMAGE_REPOSITORY }} | grep -v $(docker images -q ${{ env.REGISTRY }}/${{ env.IMAGE_REPOSITORY }}:${{ github.run_id }}) | xargs --no-run-if-empty docker rmi | |
rm -f .env.${{ github.run_id }} |