diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 00000000..7c226daa --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,49 @@ +name: Docker + +on: + push: + branches: [ "master" ] + tags: [ 'v*.*.*' ] + pull_request: + branches: [ "master" ] + workflow_dispatch: # 允许手动触发 + +env: + REGISTRY: registry.cn-hangzhou.aliyuncs.com # 修改为你的阿里云镜像仓库地址 + IMAGE_NAME: jcce/pcm-core-api # 修改为你的阿里云镜像仓库名称 + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + id-token: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log into Alibaba Cloud Container Registry + if: github.event_name != 'pull_request' + uses: aliyun/acr-login@v1 + with: + username: ${{ secrets.ALIYUN_USERNAME }} + password: ${{ secrets.ALIYUN_PASSWORD }} + login-server: ${{ env.REGISTRY }} + - name: Build and push image + env: + IMAGE_TAG: latest + run: | + docker build -t ${{env.REGISTRY}}/${{env.IMAGE_NAME}}:${{env.IMAGE_TAG}} . + docker push ${{env.REGISTRY}}/${{env.IMAGE_NAME}}:${{env.IMAGE_TAG}} + + - name: Set up SSH key + run: | + mkdir -p ~/.ssh + echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa + chmod 600 ~/.ssh/id_rsa + echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config + + - name: SSH to remote server and restart deployment + run: ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "kubectl rollout restart deployment ${{ secrets.SSH_DEPLOYMENT }} -n ${{ secrets.SSH_NAMESPACE }}" \ No newline at end of file diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml new file mode 100644 index 00000000..8944fda0 --- /dev/null +++ b/.github/workflows/sync.yml @@ -0,0 +1,25 @@ +name: Sync Mirror Repository + +on: + schedule: + - cron: '0 * * * *' # 每小时同步一次 + workflow_dispatch: # 允许手动触发 + +jobs: + mirror: + runs-on: ubuntu-latest + + steps: + - name: Checkout target repository + uses: actions/checkout@v2 + with: + fetch-depth: 1 # 获取完整的提交历史 + + - name: Mirror source repository + uses: wearerequired/git-mirror-action@v1 + with: + source-repo: "https://gitlink.org.cn/JointCloud/pcm-coordinator.git" # 源仓库的URL + destination-repo: "git@github.com:${{ github.repository }}.git" # 目标仓库的URL + ssh: true + env: + SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 81784518..414298e9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM registry.cn-hangzhou.aliyuncs.com/jcce-images/golang:1.22.4-alpine3.20 AS builder +FROM golang:1.22.4-alpine3.20 AS builder WORKDIR /app COPY . . @@ -9,12 +9,11 @@ RUN go mod download RUN CGO_ENABLED=0 go build -ldflags="-w -s" -o pcm-core-api -FROM registry.cn-hangzhou.aliyuncs.com/jcce-images/alpine:3.20 +FROM alpine:latest WORKDIR /app #修改alpine源为上海交通大学 -RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.sjtug.sjtu.edu.cn/g' /etc/apk/repositories && \ - apk add --no-cache ca-certificates && update-ca-certificates && \ +RUN apk add --no-cache ca-certificates && update-ca-certificates && \ apk add --update tzdata && \ rm -rf /var/cache/apk/*