Add Docker build multi-platform support
This commit is contained in:
parent
e6c8a1e9e0
commit
cbcd632f4d
|
@ -0,0 +1,54 @@
|
||||||
|
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-openstack # 修改为你的阿里云镜像仓库名称
|
||||||
|
IMAGE_TAG: latest
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
|
id-token: write
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- 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:
|
||||||
|
registry: ${{ env.REGISTRY }}
|
||||||
|
username: ${{ secrets.ALIYUN_USERNAME }}
|
||||||
|
password: ${{ secrets.ALIYUN_PASSWORD }}
|
||||||
|
|
||||||
|
- name: Build and push multi-arch image
|
||||||
|
run: |
|
||||||
|
docker buildx build --platform linux/amd64,linux/arm64 -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} --push .
|
||||||
|
|
||||||
|
- 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
|
||||||
|
if: github.event_name != 'pull_request'
|
||||||
|
run: ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "kubectl rollout restart deployment ${{ secrets.SSH_DEPLOYMENT }} -n ${{ secrets.SSH_NAMESPACE }}"
|
|
@ -0,0 +1,26 @@
|
||||||
|
name: Sync Mirror Repository
|
||||||
|
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
- cron: '0 */8 * * *' # 每小时同步一次
|
||||||
|
workflow_dispatch: # 允许手动触发
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
mirror:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
timeout-minutes: 10 # 设置作业的超时时间为10分钟
|
||||||
|
|
||||||
|
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-openstack.git" # 源仓库的URL
|
||||||
|
destination-repo: "git@github.com:${{ github.repository }}.git" # 目标仓库的URL
|
||||||
|
env:
|
||||||
|
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
33
Dockerfile
33
Dockerfile
|
@ -1,32 +1,29 @@
|
||||||
FROM golang:1.20.2-alpine3.17 AS builder
|
FROM --platform=$BUILDPLATFORM golang:1.22.4-alpine3.20 AS builder
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
LABEL stage=gobuilder
|
|
||||||
ENV CGO_ENABLED 0
|
|
||||||
ENV GOARCH amd64
|
|
||||||
ENV GOPROXY https://goproxy.cn,direct
|
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
COPY etc/ /app/
|
|
||||||
RUN go mod download && go build -o pcm-openstack /app/pcmopenstack.go
|
|
||||||
|
|
||||||
FROM alpine:3.16.2
|
ENV GO111MODULE=on GOPROXY=https://goproxy.cn,direct
|
||||||
|
RUN go mod download
|
||||||
|
|
||||||
|
ARG TARGETOS
|
||||||
|
ARG TARGETARCH
|
||||||
|
# 使用 GOOS 和 GOARCH 环境变量来构建不同架构的二进制文件
|
||||||
|
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -ldflags="-w -s" -o pcm-openstack
|
||||||
|
|
||||||
|
FROM --platform=$TARGETPLATFORM alpine:latest
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
#修改alpine源为上海交通大学
|
#修改alpine源为上海交通大学
|
||||||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.sjtug.sjtu.edu.cn/g' /etc/apk/repositories && \
|
RUN apk add --no-cache ca-certificates && update-ca-certificates && \
|
||||||
apk update && \
|
|
||||||
apk upgrade && \
|
|
||||||
apk add --no-cache ca-certificates && update-ca-certificates && \
|
|
||||||
apk add --update tzdata && \
|
apk add --update tzdata && \
|
||||||
rm -rf /var/cache/apk/*
|
rm -rf /var/cache/apk/*
|
||||||
|
|
||||||
COPY --from=builder /app/pcm-openstack .
|
COPY --from=builder /app/pcm-openstack .
|
||||||
COPY etc/pcmopenstack.yaml .
|
COPY --from=builder /app/etc/pcmopenstack.yaml .
|
||||||
|
|
||||||
ENV TZ=Asia/Shanghai
|
ENV TZ=Asia/Shanghai
|
||||||
|
|
||||||
EXPOSE 2003
|
EXPOSE 2010
|
||||||
|
|
||||||
ENTRYPOINT ./pcm-openstack -f pcmopenstack.yaml
|
ENTRYPOINT ./pcm-openstack --f pcmopenstack.yaml
|
Loading…
Reference in New Issue