mirror of
https://gitee.com/Doocs/md
synced 2025-04-29 09:32:27 +08:00
feat: support multi-arch docker images (#623)
This commit is contained in:
parent
5e2b27f506
commit
4eea688cb0
23
.github/workflows/docker.yml
vendored
23
.github/workflows/docker.yml
vendored
@ -19,11 +19,6 @@ jobs:
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
with:
|
||||
config-inline: |
|
||||
[worker.oci]
|
||||
enabled = true
|
||||
platforms = [ "linux/amd64", "linux/arm64" ]
|
||||
|
||||
- name: Log in to Docker Hub
|
||||
uses: docker/login-action@v3
|
||||
@ -31,17 +26,7 @@ jobs:
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
|
||||
- name: Build base image
|
||||
run: bash scripts/build-base-image.sh
|
||||
|
||||
- name: Build nginx image
|
||||
run: bash scripts/build-nginx.sh
|
||||
|
||||
- name: Build standalone image
|
||||
run: bash scripts/build-standalone.sh
|
||||
|
||||
- name: Build static image
|
||||
run: bash scripts/build-static.sh
|
||||
|
||||
- name: Push images to Docker Hub
|
||||
run: bash scripts/push-images.sh
|
||||
- name: Build and push multi-arch images
|
||||
run: |
|
||||
chmod +x scripts/build-multiarch.sh
|
||||
bash scripts/build-multiarch.sh
|
||||
|
@ -1,8 +1,8 @@
|
||||
FROM node:20-alpine3.19 AS builder
|
||||
FROM --platform=$BUILDPLATFORM node:20-alpine3.19 AS builder
|
||||
ENV LANG="en_US.UTF-8"
|
||||
ENV LANGUAGE="en_US.UTF-8"
|
||||
ENV LC_ALL="en_US.UTF-8"
|
||||
RUN apk add curl
|
||||
RUN apk add --no-cache curl unzip
|
||||
RUN curl -L "https://github.com/doocs/md/archive/refs/heads/main.zip" -o "main.zip" && unzip "main.zip" && mv "md-main" /app
|
||||
WORKDIR /app
|
||||
COPY ./patch/vite.config.ts /app/vite.config.ts
|
||||
|
@ -1,6 +1,6 @@
|
||||
ARG VER_NGX="1.21.6-alpine"
|
||||
|
||||
FROM "doocs/md:latest-assets" AS assets
|
||||
FROM "nginx:$VER_NGX"
|
||||
FROM --platform=$BUILDPLATFORM doocs/md:latest-assets AS assets
|
||||
FROM --platform=$TARGETPLATFORM nginx:${VER_NGX}
|
||||
LABEL MAINTAINER="ylb<contact@yanglibin.info>"
|
||||
COPY --from=assets /app/* /usr/share/nginx/html
|
||||
COPY --from=assets /app /usr/share/nginx/html
|
||||
|
@ -1,11 +1,11 @@
|
||||
FROM doocs/md:latest-assets AS assets
|
||||
FROM --platform=$BUILDPLATFORM doocs/md:latest-assets AS assets
|
||||
|
||||
# detail https://github.com/lipanski/docker-static-website/blob/master/Dockerfile
|
||||
FROM lipanski/docker-static-website
|
||||
FROM --platform=$TARGETPLATFORM lipanski/docker-static-website
|
||||
|
||||
WORKDIR /home/static
|
||||
|
||||
COPY --from=assets /app/* /home/static
|
||||
COPY --from=assets /app /home/static
|
||||
|
||||
EXPOSE 80
|
||||
|
||||
|
87
scripts/build-multiarch.sh
Normal file
87
scripts/build-multiarch.sh
Normal file
@ -0,0 +1,87 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
RELEASE_DIR="./docker"
|
||||
REPO_NAME="doocs/md"
|
||||
PLATFORMS="linux/amd64,linux/arm64"
|
||||
|
||||
echo "🔧 Multi-arch Docker build started..."
|
||||
echo "📁 Scanning directory: $RELEASE_DIR"
|
||||
|
||||
for app_ver in "$RELEASE_DIR"/*; do
|
||||
[ -d "$app_ver" ] || continue
|
||||
|
||||
tag=$(basename "$app_ver")
|
||||
env_file="$app_ver/.env"
|
||||
|
||||
if [ ! -f "$env_file" ]; then
|
||||
echo "⚠️ Skipping $tag - missing .env file"
|
||||
continue
|
||||
fi
|
||||
|
||||
set -a
|
||||
. "$env_file"
|
||||
set +a
|
||||
|
||||
echo "🚀 Building images for version: $tag"
|
||||
echo " VER_APP: $VER_APP"
|
||||
echo " VER_NGX: $VER_NGX"
|
||||
echo " VER_GOLANG: $VER_GOLANG"
|
||||
echo " VER_ALPINE: $VER_ALPINE"
|
||||
|
||||
# 构建 base 镜像
|
||||
if [ -f "$app_ver/Dockerfile.base" ]; then
|
||||
echo "📦 Building base image: $REPO_NAME:${VER_APP}-assets"
|
||||
docker buildx build \
|
||||
--platform "$PLATFORMS" \
|
||||
--build-arg VER_APP="$VER_APP" \
|
||||
-f "$app_ver/Dockerfile.base" \
|
||||
-t "$REPO_NAME:${VER_APP}-assets" \
|
||||
--push \
|
||||
"$app_ver"
|
||||
fi
|
||||
|
||||
# 构建 nginx 镜像
|
||||
if [ -f "$app_ver/Dockerfile.nginx" ]; then
|
||||
echo "📦 Building nginx image: $REPO_NAME:${VER_APP}-nginx"
|
||||
docker buildx build \
|
||||
--platform "$PLATFORMS" \
|
||||
--build-arg VER_APP="$VER_APP" \
|
||||
--build-arg VER_NGX="$VER_NGX" \
|
||||
-f "$app_ver/Dockerfile.nginx" \
|
||||
-t "$REPO_NAME:${VER_APP}-nginx" \
|
||||
--push \
|
||||
"$app_ver"
|
||||
fi
|
||||
|
||||
# 构建 standalone 镜像
|
||||
if [ -f "$app_ver/Dockerfile.standalone" ]; then
|
||||
echo "📦 Building standalone image: $REPO_NAME:${VER_APP}"
|
||||
docker buildx build \
|
||||
--platform "$PLATFORMS" \
|
||||
--build-arg VER_APP="$VER_APP" \
|
||||
--build-arg VER_NGX="$VER_NGX" \
|
||||
-f "$app_ver/Dockerfile.standalone" \
|
||||
-t "$REPO_NAME:${VER_APP}" \
|
||||
--push \
|
||||
"$app_ver"
|
||||
fi
|
||||
|
||||
# 构建 static 镜像
|
||||
if [ -f "$app_ver/Dockerfile.static" ]; then
|
||||
echo "📦 Building static image: $REPO_NAME:${VER_APP}-static"
|
||||
docker buildx build \
|
||||
--platform "$PLATFORMS" \
|
||||
--build-arg VER_APP="$VER_APP" \
|
||||
--build-arg VER_NGX="$VER_NGX" \
|
||||
-f "$app_ver/Dockerfile.static" \
|
||||
-t "$REPO_NAME:${VER_APP}-static" \
|
||||
--push \
|
||||
"$app_ver"
|
||||
fi
|
||||
|
||||
echo "✅ Completed version: $tag"
|
||||
done
|
||||
|
||||
echo "🎉 All images built and pushed successfully."
|
Loading…
x
Reference in New Issue
Block a user