80 lines
2.5 KiB
YAML
80 lines
2.5 KiB
YAML
name: Build and Push Docker Image
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
|
|
env:
|
|
IMAGE_NAME: ''
|
|
REPO_NAME: ''
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
container:
|
|
image: zuogeus/act-ubuntu:node18
|
|
options: --add-host nexus.zzwb.cc:192.168.2.7
|
|
|
|
steps:
|
|
- name: Setup Environments
|
|
shell: bash
|
|
run: |
|
|
IFS="/" read -r OWNER REPO <<< "$GITHUB_REPOSITORY"
|
|
echo "REPO_NAME=$REPO" >> $GITHUB_ENV
|
|
echo "IMAGE_NAME=${{ vars.REGISTRY_URL }}/${{ vars.REGISTRY_NAMESPACE }}/$REPO:$GITHUB_REF_NAME" >> $GITHUB_ENV
|
|
|
|
- name: Checkout
|
|
uses: https://gitee.com/zuowenbo/checkout@v4.1.1
|
|
|
|
- name: Get npm cache directory
|
|
id: npm-cache-dir
|
|
shell: bash
|
|
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
|
|
|
|
- name: Set node_modules cache
|
|
uses: https://gitee.com/zuowenbo/cache@v4.0.0
|
|
id: npm-cache
|
|
with:
|
|
path: ${{ steps.npm-cache-dir.outputs.dir }}
|
|
key: ${{ runner.os }}-node-umi4-${{ hashFiles('**/package-lock.json') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-node-umi4-
|
|
|
|
- run: npm install --registry=https://registry.npmmirror.com
|
|
- run: npm run build
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: https://gitee.com/zuowenbo/setup-buildx-action@v3.0.0
|
|
with:
|
|
driver-opts: network=host
|
|
|
|
- name: Login to Docker Hub
|
|
uses: https://gitee.com/zuowenbo/login-action@v3.0.0
|
|
with:
|
|
registry: ${{ vars.REGISTRY_URL }}
|
|
username: ${{ vars.REGISTRY_USERNAME }}
|
|
password: ${{ secrets.REGISTRY_PASSWORD }}
|
|
|
|
- name: Build and push final image
|
|
uses: https://gitee.com/zuowenbo/build-push-action@v5.1.0
|
|
with:
|
|
context: .
|
|
tags: ${{ env.IMAGE_NAME }}
|
|
push: true
|
|
build-args: BRANCH=${{ env.GITHUB_REF_NAME }}
|
|
|
|
- name: Deploy to remote
|
|
uses: https://gitee.com/zuowenbo/ssh-action@v1.0.3
|
|
with:
|
|
host: ${{ vars.LOAN_MAIN_HOST_IP_PHP }}
|
|
port: 22
|
|
username: 'ubuntu'
|
|
password: ${{ secrets.LOAN_MAIN_HOST_PASSWORD }}
|
|
script: |
|
|
docker login -u ${{ vars.REGISTRY_USERNAME }} -p ${{ secrets.REGISTRY_PASSWORD }} ${{ vars.REGISTRY_URL}}
|
|
docker pull ${{ env.IMAGE_NAME }}
|
|
docker stop ${{ env.REPO_NAME }} || true
|
|
docker rm ${{ env.REPO_NAME }} || true
|
|
docker run -d --restart always --network my_network --name ${{ env.REPO_NAME }} ${{ env.IMAGE_NAME }}
|