Deploy and Build Docker #285
This file contains hidden or 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: Deploy and Build Docker | |
| on: | |
| push: | |
| branches: [ main ] | |
| schedule: | |
| - cron: '0 0 * * *' # 每天凌晨运行 | |
| workflow_dispatch: # 手动触发 | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| with: | |
| submodules: true # 获取子模块(如果有的话) | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: '18' | |
| - name: Cache dependencies | |
| uses: actions/cache@v3 | |
| with: | |
| path: ~/.npm | |
| key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | |
| restore-keys: | | |
| ${{ runner.os }}-node- | |
| - name: Install dependencies | |
| run: npm install | |
| - name: Setup Deploy Key | |
| env: | |
| DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }} | |
| run: | | |
| mkdir -p ~/.ssh/ | |
| echo "$DEPLOY_KEY" > ~/.ssh/id_rsa | |
| chmod 600 ~/.ssh/id_rsa | |
| ssh-keyscan github.com >> ~/.ssh/known_hosts | |
| - name: Deploy to GitHub Pages | |
| env: | |
| GIT_NAME: FreemanKevin | |
| GIT_EMAIL: ${{ secrets.GIT_EMAIL }} | |
| run: | | |
| git config --global user.name "$GIT_NAME" | |
| git config --global user.email "$GIT_EMAIL" | |
| npm run deploy | |
| docker: | |
| needs: deploy | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Build and push | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| platforms: linux/amd64,linux/arm64 | |
| push: true | |
| tags: | | |
| ${{ secrets.DOCKERHUB_USERNAME }}/freemankevin:latest | |
| ${{ secrets.DOCKERHUB_USERNAME }}/freemankevin:${{ github.sha }} | |
| cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/freemankevin:buildcache | |
| cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/freemankevin:buildcache,mode=max |