-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: build and deploy docker image (#495)
- Loading branch information
Showing
17 changed files
with
314 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: Build and Push Docker Images | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Log in to Docker Hub | ||
uses: docker/login-action@v3 | ||
with: | ||
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 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
VER_APP=latest | ||
VER_NGX=1.21.6-alpine | ||
VER_GOLANG=1.17.6-alpine3.15 | ||
VER_ALPINE=3.15 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
FROM 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 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 | ||
ENV NODE_OPTIONS="--openssl-legacy-provider" | ||
RUN npm i && npm run build | ||
|
||
FROM scratch | ||
LABEL MAINTAINER="ylb<contact@yanglibin.info>" | ||
COPY --from=builder /app/dist /app/assets |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
ARG VER_NGX="1.21.6-alpine" | ||
|
||
FROM "doocs/md:latest-assets" AS assets | ||
FROM "nginx:$VER_NGX" | ||
LABEL MAINTAINER="ylb<contact@yanglibin.info>" | ||
COPY --from=assets /app/* /usr/share/nginx/html |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
ARG VER_GOLANG=1.17.6-alpine3.15 | ||
ARG VER_ALPINE=3.15 | ||
|
||
FROM "doocs/md:latest-assets" AS assets | ||
|
||
FROM "golang:$VER_GOLANG" AS gobuilder | ||
COPY --from=assets /app/* /app/assets/ | ||
COPY server/main.go /app | ||
RUN apk add git bash gcc musl-dev upx | ||
WORKDIR /app | ||
RUN go build -ldflags "-w -s" -o md main.go && \ | ||
apk add upx && \ | ||
upx -9 -o md.minify md | ||
|
||
FROM "alpine:$VER_ALPINE" | ||
LABEL MAINTAINER="ylb<contact@yanglibin.info>" | ||
COPY --from=gobuilder /app/md.minify /bin/md | ||
EXPOSE 80 | ||
CMD ["md"] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM doocs/md:latest-assets AS assets | ||
|
||
# detail https://github.com/lipanski/docker-static-website/blob/master/Dockerfile | ||
FROM lipanski/docker-static-website | ||
|
||
WORKDIR /home/static | ||
|
||
COPY --from=assets /app/* /home/static | ||
|
||
EXPOSE 80 | ||
|
||
CMD ["/busybox-httpd", "-f", "-v", "-p", "80", "-c", "httpd.conf"] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import path from 'node:path' | ||
import process from 'node:process' | ||
|
||
import vue from '@vitejs/plugin-vue' | ||
import { visualizer } from 'rollup-plugin-visualizer' | ||
import UnoCSS from 'unocss/vite' | ||
import AutoImport from 'unplugin-auto-import/vite' | ||
import Components from 'unplugin-vue-components/vite' | ||
import { defineConfig } from 'vite' | ||
import { nodePolyfills } from 'vite-plugin-node-polyfills' | ||
import vueDevTools from 'vite-plugin-vue-devtools' | ||
|
||
// https://vitejs.dev/config/ | ||
export default defineConfig({ | ||
base: `/`, // 基本路径, 建议以绝对路径跟随访问目录 | ||
define: { | ||
process, | ||
}, | ||
plugins: [ | ||
vue(), | ||
UnoCSS(), | ||
vueDevTools(), | ||
nodePolyfills({ | ||
include: [`path`, `util`, `timers`, `stream`, `fs`], | ||
overrides: { | ||
// Since `fs` is not supported in browsers, we can use the `memfs` package to polyfill it. | ||
// fs: 'memfs', | ||
}, | ||
}), | ||
process.env.ANALYZE === `true` && visualizer({ | ||
emitFile: true, | ||
filename: `stats.html`, | ||
}), | ||
AutoImport({ | ||
imports: [ | ||
`vue`, | ||
`pinia`, | ||
`@vueuse/core`, | ||
], | ||
dirs: [ | ||
`./src/stores`, | ||
`./src/utils/toast`, | ||
], | ||
}), | ||
Components({ | ||
resolvers: [], | ||
}), | ||
], | ||
resolve: { | ||
alias: { | ||
'@': path.resolve(__dirname, `./src`), | ||
}, | ||
}, | ||
css: { | ||
devSourcemap: true, | ||
}, | ||
build: { | ||
rollupOptions: { | ||
output: { | ||
chunkFileNames: `static/js/md-[name]-[hash].js`, | ||
entryFileNames: `static/js/md-[name]-[hash].js`, | ||
assetFileNames: `static/[ext]/md-[name]-[hash].[ext]`, | ||
}, | ||
}, | ||
}, | ||
}) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package main | ||
|
||
import ( | ||
"embed" | ||
"io/fs" | ||
"log" | ||
"net/http" | ||
) | ||
|
||
//go:embed assets | ||
var assets embed.FS | ||
|
||
func main() { | ||
mutex := http.NewServeMux() | ||
md, _ := fs.Sub(assets, "assets") | ||
mutex.Handle("/", http.FileServer(http.FS(md))) | ||
err := http.ListenAndServe(":80", mutex) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/bash | ||
|
||
RELEASE_DIR='./docker'; | ||
REPO_NAME='doocs/md' | ||
|
||
for app_ver in $RELEASE_DIR/*; do | ||
|
||
if [ -f "$app_ver/Dockerfile.base" ]; then | ||
|
||
tag=$(echo $app_ver | cut -b 10-); | ||
echo "Build: $tag"; | ||
set -a | ||
. "$app_ver/.env" | ||
set +a | ||
|
||
echo $app_ver | ||
echo "VER_APP: $VER_APP" | ||
echo "VER_NGX: $VER_NGX" | ||
echo "VER_GOLANG: $VER_GOLANG" | ||
echo "VER_ALPINE: $VER_ALPINE" | ||
|
||
docker build --build-arg VER_APP=$VER_APP -f "$app_ver/Dockerfile.base" -t "$REPO_NAME:${VER_APP}-assets" "$app_ver" | ||
fi | ||
|
||
done |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/bash | ||
|
||
RELEASE_DIR='./docker'; | ||
REPO_NAME='doocs/md' | ||
|
||
for app_ver in $RELEASE_DIR/*; do | ||
|
||
if [ -f "$app_ver/Dockerfile.nginx" ]; then | ||
|
||
tag=$(echo $app_ver | cut -b 10-); | ||
echo "Build: $tag"; | ||
set -a | ||
. "$app_ver/.env" | ||
set +a | ||
|
||
echo $app_ver | ||
echo "VER_APP: $VER_APP" | ||
echo "VER_NGX: $VER_NGX" | ||
echo "VER_GOLANG: $VER_GOLANG" | ||
echo "VER_ALPINE: $VER_ALPINE" | ||
|
||
docker build --build-arg VER_APP=$VER_APP --build-arg VER_NGX=$VER_NGX -f "$app_ver/Dockerfile.nginx" -t "$REPO_NAME:${VER_APP}-nginx" "$app_ver" | ||
fi | ||
|
||
done |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/bash | ||
|
||
RELEASE_DIR='./docker'; | ||
REPO_NAME='doocs/md' | ||
|
||
for app_ver in $RELEASE_DIR/*; do | ||
|
||
if [ -f "$app_ver/Dockerfile.standalone" ]; then | ||
|
||
tag=$(echo $app_ver | cut -b 10-); | ||
echo "Build: $tag"; | ||
set -a | ||
. "$app_ver/.env" | ||
set +a | ||
|
||
echo $app_ver | ||
echo "VER_APP: $VER_APP" | ||
echo "VER_NGX: $VER_NGX" | ||
echo "VER_GOLANG: $VER_GOLANG" | ||
echo "VER_ALPINE: $VER_ALPINE" | ||
|
||
docker build --build-arg VER_APP=$VER_APP --build-arg VER_NGX=$VER_NGX -f "$app_ver/Dockerfile.standalone" -t "$REPO_NAME:${VER_APP}" "$app_ver" | ||
fi | ||
|
||
done |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/bash | ||
|
||
RELEASE_DIR='./docker'; | ||
REPO_NAME='doocs/md' | ||
|
||
for app_ver in $RELEASE_DIR/*; do | ||
|
||
if [ -f "$app_ver/Dockerfile.static" ]; then | ||
|
||
tag=$(echo $app_ver | cut -b 10-); | ||
echo "Build: $tag"; | ||
set -a | ||
. "$app_ver/.env" | ||
set +a | ||
|
||
echo $app_ver | ||
echo "VER_APP: $VER_APP" | ||
echo "VER_NGX: $VER_NGX" | ||
echo "VER_GOLANG: $VER_GOLANG" | ||
echo "VER_ALPINE: $VER_ALPINE" | ||
|
||
docker build --build-arg VER_APP=$VER_APP --build-arg VER_NGX=$VER_NGX -f "$app_ver/Dockerfile.static" -t "$REPO_NAME:${VER_APP}-static" "$app_ver" | ||
fi | ||
|
||
done |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/bin/bash | ||
|
||
RELEASE_DIR='./docker'; | ||
REPO_NAME='doocs/md' | ||
|
||
for app_ver in $RELEASE_DIR/*; do | ||
|
||
tag=$(echo $app_ver | cut -b 10-); | ||
|
||
if [ -f "$app_ver/Dockerfile.base" ]; then | ||
# 推送构建产物,方便其他的用户和爱好者进行二次封装 | ||
docker push $REPO_NAME:$tag-assets | ||
fi | ||
|
||
if [ -f "$app_ver/Dockerfile.standalone" ]; then | ||
# 推送单个二进制的镜像 | ||
docker push $REPO_NAME:$tag | ||
fi | ||
|
||
if [ -f "$app_ver/Dockerfile.nginx" ]; then | ||
# 推送使用 Nginx 的镜像 | ||
docker push $REPO_NAME:$tag-nginx | ||
fi | ||
|
||
if [ -f "$app_ver/Dockerfile.static" ]; then | ||
# 推送使用 lipanski/docker-static-website 的镜像 | ||
docker push $REPO_NAME:$tag-static | ||
fi | ||
|
||
done |
File renamed without changes.
This file contains 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