Browse Source

add build web dockerfile

lqg 2 years ago
parent
commit
68d0afb400

+ 13 - 0
ai/.devcontainer/devcontainer.json

@@ -1,4 +1,17 @@
 {
+	"name": "AI",
+	"build": {
+		"dockerfile": "Dockerfile",
+		"args": {
+			// Use the VARIANT arg to pick a Debian OS version: buster, bullseye
+			// Use bullseye when running on local arm64/Apple Silicon.
+			"VARIANT": "buster",
+			// Options
+			"INSTALL_MAVEN": "true",
+			"INSTALL_GRADLE": "true",
+			"NODE_VERSION": "lts/*"
+		}
+	},
 	"customizations": {
 		"vscode": {
 			"extensions": [

+ 37 - 1
android-studio/.devcontainer/Dockerfile

@@ -1,2 +1,38 @@
+# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.233.0/containers/java-8/.devcontainer/base.Dockerfile
 
-FROM jianboy/android-dev-container:2.10.5
+# [Choice] Debian OS version (use bullseye on local arm64/Apple Silicon): buster, bullseye
+ARG VARIANT="bullseye"
+FROM mcr.microsoft.com/vscode/devcontainers/java:0-16-${VARIANT}
+
+# [Option] Install Maven
+ARG INSTALL_MAVEN="false"
+ARG MAVEN_VERSION=""
+# [Option] Install Gradle
+ARG INSTALL_GRADLE="false"
+ARG GRADLE_VERSION=""
+RUN if [ "${INSTALL_MAVEN}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/sdkman/bin/sdkman-init.sh && sdk install maven \"${MAVEN_VERSION}\""; fi \
+    && if [ "${INSTALL_GRADLE}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/sdkman/bin/sdkman-init.sh && sdk install gradle \"${GRADLE_VERSION}\""; fi
+
+USER vscode
+WORKDIR /home/vscode
+ENV ANDROID_HOME=/home/vscode/androidsdk \
+    FLUTTER_HOME=/home/vscode/flutter
+
+RUN wget https://dl.google.com/android/repository/commandlinetools-linux-7583922_latest.zip \
+    && mkdir -p $ANDROID_HOME/cmdline-tools/latest \
+    && unzip commandlinetools-linux-*.zip -d $ANDROID_HOME \
+    && rm -f commandlinetools-linux-*.zip \
+    && mv $ANDROID_HOME/cmdline-tools/bin $ANDROID_HOME/cmdline-tools/latest \
+    && mv $ANDROID_HOME/cmdline-tools/lib $ANDROID_HOME/cmdline-tools/latest
+
+RUN echo "export ANDROID_HOME=$ANDROID_HOME" >> /home/vscode/.bashrc \
+    && echo 'export PATH=$ANDROID_HOME/emulator:$ANDROID_HOME/tools:$ANDROID_HOME/cmdline-tools/bin:$ANDROID_HOME/platform-tools:$PATH' >> /home/vscode/.bashrc
+
+# Install Android Image version 33
+RUN yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager "platform-tools" "platforms;android-33"
+RUN yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager "system-images;android-33;google_apis;x86_64"
+# RUN echo no | $ANDROID_HOME/cmdline-tools/latest/bin/avdmanager create avd -n avd28 -k "system-images;android-30;google_apis;x86_64"
+
+# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10
+ARG NODE_VERSION="lts/*"
+RUN if [ "${NODE_VERSION}" != "none" ]; then umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1; fi

+ 0 - 45
android-studio/.devcontainer/Dockerfile2

@@ -1,45 +0,0 @@
-# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.233.0/containers/java-8/.devcontainer/base.Dockerfile
-
-# [Choice] Debian OS version (use bullseye on local arm64/Apple Silicon): buster, bullseye
-ARG VARIANT="bullseye"
-FROM mcr.microsoft.com/vscode/devcontainers/java:0-8-${VARIANT}
-
-# [Option] Install Maven
-ARG INSTALL_MAVEN="false"
-ARG MAVEN_VERSION=""
-# [Option] Install Gradle
-ARG INSTALL_GRADLE="false"
-ARG GRADLE_VERSION=""
-RUN if [ "${INSTALL_MAVEN}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/sdkman/bin/sdkman-init.sh && sdk install maven \"${MAVEN_VERSION}\""; fi \
-    && if [ "${INSTALL_GRADLE}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/sdkman/bin/sdkman-init.sh && sdk install gradle \"${GRADLE_VERSION}\""; fi
-
-USER vscode
-WORKDIR /home/vscode
-ARG FLUTTER_VERSION="2.10.5"
-ENV ANDROID_HOME=/home/vscode/androidsdk \
-    FLUTTER_HOME=/home/vscode/flutter
-
-RUN wget https://dl.google.com/android/repository/commandlinetools-linux-7583922_latest.zip \
-    && mkdir -p $ANDROID_HOME/cmdline-tools/latest \
-    && unzip commandlinetools-linux-*.zip -d $ANDROID_HOME \
-    && rm -f commandlinetools-linux-*.zip \
-    && mv $ANDROID_HOME/cmdline-tools/bin $ANDROID_HOME/cmdline-tools/latest \
-    && mv $ANDROID_HOME/cmdline-tools/lib $ANDROID_HOME/cmdline-tools/latest
-
-RUN echo "export ANDROID_HOME=$ANDROID_HOME" >> /home/vscode/.bashrc \
-    && echo 'export PATH=$ANDROID_HOME/emulator:$ANDROID_HOME/tools:$ANDROID_HOME/cmdline-tools/bin:$ANDROID_HOME/platform-tools:$PATH' >> /home/vscode/.bashrc
-
-# Install Android Image version 30
-RUN yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager "platform-tools" "platforms;android-30"
-RUN yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager "system-images;android-30;google_apis;x86_64"
-# RUN echo no | $ANDROID_HOME/cmdline-tools/latest/bin/avdmanager create avd -n avd28 -k "system-images;android-30;google_apis;x86_64"
-
-# Install flutter
-RUN git clone -tag {FLUTTER_VERSION} https://github.com/flutter/flutter.git ${FLUTTER_HOME} \
-    && cd ${FLUTTER_HOME} \
-    && ./bin/flutter precache \
-    && ./bin/flutter doctor
-
-# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10
-ARG NODE_VERSION="lts/*"
-RUN if [ "${NODE_VERSION}" != "none" ]; then umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1; fi

+ 4 - 15
android-studio/.devcontainer/devcontainer.json

@@ -2,27 +2,16 @@
 // For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
 // https://github.com/microsoft/vscode-dev-containers/tree/v0.233.0/containers/java-8
 {
-	"name": "Java 8",
-	"build": {
-		"dockerfile": "Dockerfile",
-		"args": {
-			// Use the VARIANT arg to pick a Debian OS version: buster, bullseye
-			// Use bullseye when running on local arm64/Apple Silicon.
-			"VARIANT": "buster",
-			// Options
-			"INSTALL_MAVEN": "true",
-			"INSTALL_GRADLE": "true",
-			"NODE_VERSION": "lts/*"
-		}
-	},
-
+	"name": "Java 16",
+	"image": "jianboy/android-dev-container:2.10.5",
+	
 	// Set *default* container specific settings.json values on container create.
 	"settings": {
 		"java.home": "/docker-java-home",
 		"java.import.gradle.java.home": "/usr/local/sdkman/candidates/java/current",
 		"java.configuration.runtimes": [{
 			"default": true,
-			"name": "JavaSE-1.8",
+			"name": "JavaSE-16",
 			"path": "/usr/local/sdkman/candidates/java/current"
 		}]
 	},

+ 0 - 16
docker/Dockerfile

@@ -1,16 +0,0 @@
-FROM maven
-LABEL email="liuyuqi<liuyuqi.gov@msn.cn>"
-
-ENV CODE /code
-ENV WORK /code/work
-RUN mkdir -p $CODE \
-    && mkdir -p $WORK
-
-WORKDIR $WORK
-
-# 这里将项目中./target/*.jar 复制到了 镜像里并命名为app.jar,  为什么是 ./target/*.jar , 因为 maven 打包后的文件就是在该路径, 如果是其他项目,填写对应路径 和名称就行了  
-COPY ./target/*.jar app.jar
-# 暴露出项目的 8060端口, 填你项目端口即可 (没有端口可忽略)
-EXPOSE 8060
-# 这是运行jar的命令,  如果是其他项目, 填写对应命令就行了
-CMD java -jar app.jar

+ 17 - 0
dotnet/Dockerfile

@@ -0,0 +1,17 @@
+FROM node:lts-alpine as base
+RUN apk add --no-cache tini
+ENV NODE_ENV=production
+USER  node
+WORKDIR /app
+COPY package*.json ./
+RUN npm install
+COPY . .
+RUN chown -R appuser:appgroup /app
+EXPOSE 8080
+
+FROM base as builder
+
+
+FROM base as runner
+
+CMD [ "npm", "start" ]

+ 45 - 1
flutter/.devcontainer/Dockerfile

@@ -1,2 +1,46 @@
+# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.233.0/containers/java-8/.devcontainer/base.Dockerfile
 
-FROM jianboy/flutter-dev-container:3.7.7
+# [Choice] Java version: 11, 16
+ARG VARIANT="16"
+FROM mcr.microsoft.com/vscode/devcontainers/java:0-${VARIANT}
+
+# [Option] Install Maven
+ARG INSTALL_MAVEN="false"
+ARG MAVEN_VERSION=""
+# [Option] Install Gradle
+ARG INSTALL_GRADLE="false"
+ARG GRADLE_VERSION="7.2.2"
+RUN if [ "${INSTALL_MAVEN}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/sdkman/bin/sdkman-init.sh && sdk install maven \"${MAVEN_VERSION}\""; fi \
+    && if [ "${INSTALL_GRADLE}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/sdkman/bin/sdkman-init.sh && sdk install gradle \"${GRADLE_VERSION}\""; fi
+
+USER vscode
+WORKDIR /home/vscode
+ARG FLUTTER_VERSION="3.7.7"
+ENV ANDROID_HOME=/home/vscode/androidsdk \
+    FLUTTER_HOME=/home/vscode/flutter
+
+RUN wget https://dl.google.com/android/repository/commandlinetools-linux-9477386_latest.zip \
+    && mkdir -p $ANDROID_HOME/cmdline-tools/latest \
+    && unzip commandlinetools-linux-*.zip -d $ANDROID_HOME \
+    && rm -f commandlinetools-linux-*.zip \
+    && mv $ANDROID_HOME/cmdline-tools/bin $ANDROID_HOME/cmdline-tools/latest \
+    && mv $ANDROID_HOME/cmdline-tools/lib $ANDROID_HOME/cmdline-tools/latest
+
+RUN echo "export ANDROID_HOME=$ANDROID_HOME" >> /home/vscode/.bashrc \
+    && echo 'export PATH=$ANDROID_HOME/emulator:$ANDROID_HOME/tools:$ANDROID_HOME/cmdline-tools/bin:$ANDROID_HOME/platform-tools:$PATH' >> /home/vscode/.bashrc
+
+ENV PATH=$PATH:$FLUTTER_HOME/bin
+# Install Android Image version 30
+RUN yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager "platform-tools" "platforms;android-33"
+# RUN yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager "system-images;android-30;google_apis;x86_64"
+# RUN echo no | $ANDROID_HOME/cmdline-tools/latest/bin/avdmanager create avd -n avd28 -k "system-images;android-30;google_apis;x86_64"
+
+# Install flutter
+RUN git clone --branch ${FLUTTER_VERSION} https://github.com/flutter/flutter.git ${FLUTTER_HOME} \
+    && cd ${FLUTTER_HOME} \
+    && ./bin/flutter precache \
+    && ./bin/flutter doctor
+
+# # [Choice] Node.js version: none, lts/*, 16, 14, 12, 10
+# ARG NODE_VERSION="lts/*"
+# RUN if [ "${NODE_VERSION}" != "none" ]; then umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1; fi

+ 0 - 46
flutter/.devcontainer/Dockerfile2

@@ -1,46 +0,0 @@
-# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.233.0/containers/java-8/.devcontainer/base.Dockerfile
-
-# [Choice] Java version: 11, 16
-ARG VARIANT="16"
-FROM mcr.microsoft.com/vscode/devcontainers/java:0-${VARIANT}
-
-# [Option] Install Maven
-ARG INSTALL_MAVEN="false"
-ARG MAVEN_VERSION=""
-# [Option] Install Gradle
-ARG INSTALL_GRADLE="false"
-ARG GRADLE_VERSION="7.2.2"
-RUN if [ "${INSTALL_MAVEN}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/sdkman/bin/sdkman-init.sh && sdk install maven \"${MAVEN_VERSION}\""; fi \
-    && if [ "${INSTALL_GRADLE}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/sdkman/bin/sdkman-init.sh && sdk install gradle \"${GRADLE_VERSION}\""; fi
-
-USER vscode
-WORKDIR /home/vscode
-ARG FLUTTER_VERSION="3.7.7"
-ENV ANDROID_HOME=/home/vscode/androidsdk \
-    FLUTTER_HOME=/home/vscode/flutter
-
-RUN wget https://dl.google.com/android/repository/commandlinetools-linux-9477386_latest.zip \
-    && mkdir -p $ANDROID_HOME/cmdline-tools/latest \
-    && unzip commandlinetools-linux-*.zip -d $ANDROID_HOME \
-    && rm -f commandlinetools-linux-*.zip \
-    && mv $ANDROID_HOME/cmdline-tools/bin $ANDROID_HOME/cmdline-tools/latest \
-    && mv $ANDROID_HOME/cmdline-tools/lib $ANDROID_HOME/cmdline-tools/latest
-
-RUN echo "export ANDROID_HOME=$ANDROID_HOME" >> /home/vscode/.bashrc \
-    && echo 'export PATH=$ANDROID_HOME/emulator:$ANDROID_HOME/tools:$ANDROID_HOME/cmdline-tools/bin:$ANDROID_HOME/platform-tools:$PATH' >> /home/vscode/.bashrc
-
-ENV PATH=$PATH:$FLUTTER_HOME/bin
-# Install Android Image version 30
-RUN yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager "platform-tools" "platforms;android-33"
-# RUN yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager "system-images;android-30;google_apis;x86_64"
-# RUN echo no | $ANDROID_HOME/cmdline-tools/latest/bin/avdmanager create avd -n avd28 -k "system-images;android-30;google_apis;x86_64"
-
-# Install flutter
-RUN git clone --branch ${FLUTTER_VERSION} https://github.com/flutter/flutter.git ${FLUTTER_HOME} \
-    && cd ${FLUTTER_HOME} \
-    && ./bin/flutter precache \
-    && ./bin/flutter doctor
-
-# # [Choice] Node.js version: none, lts/*, 16, 14, 12, 10
-# ARG NODE_VERSION="lts/*"
-# RUN if [ "${NODE_VERSION}" != "none" ]; then umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1; fi

+ 13 - 12
flutter/.devcontainer/devcontainer.json

@@ -3,18 +3,19 @@
 // https://github.com/microsoft/vscode-dev-containers/tree/v0.233.0/containers/java-8
 {
 	"name": "Java 16",
-	"build": {
-		"dockerfile": "Dockerfile",
-		"args": {
-			// Use the VARIANT arg to pick a Debian OS version: buster, bullseye
-			// Use bullseye when running on local arm64/Apple Silicon.
-			"VARIANT": "buster",
-			// Options
-			"INSTALL_MAVEN": "true",
-			"INSTALL_GRADLE": "true",
-			"NODE_VERSION": "lts/*"
-		}
-	},
+	"image": "jianboy/flutter-dev-container:3.7.7",
+	// "build": {
+	// 	"dockerfile": "Dockerfile",
+	// 	"args": {
+	// 		// Use the VARIANT arg to pick a Debian OS version: buster, bullseye
+	// 		// Use bullseye when running on local arm64/Apple Silicon.
+	// 		"VARIANT": "buster",
+	// 		// Options
+	// 		"INSTALL_MAVEN": "true",
+	// 		"INSTALL_GRADLE": "true",
+	// 		"NODE_VERSION": "lts/*"
+	// 	}
+	// },
 
 	// Set *default* container specific settings.json values on container create.
 	"settings": {

+ 11 - 9
go/Dockerfile

@@ -1,13 +1,14 @@
-FROM golang:alpine as builder
+FROM golang:1.19 as builder
 WORKDIR /workspaces
-COPY . /workspaces/
+COPY . ./
 ENV GOPROXY=https://goproxy.cn,direct
-RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="-w -s" main.go
+RUN go get -d -v ./
+RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -a -installsuffix cgo -o demo -ldflags="-w -s" main.go
 
-FROM alpine as runner
-WORKDIR /workspaces
-COPY --from=builder /workspaces/main .
-COPY --from=builder /workspaces/config ./config
+FROM alpine:latest as runner
+WORKDIR /app
+COPY --from=builder /app/main .
+COPY --from=builder /app/config ./config
 
 RUN echo "https://mirrors.aliyun.com/alpine/v3.8/main/" > /etc/apk/repositories \
     && echo "https://mirrors.aliyun.com/alpine/v3.8/community/" >> /etc/apk/repositories \
@@ -17,5 +18,6 @@ RUN echo "https://mirrors.aliyun.com/alpine/v3.8/main/" > /etc/apk/repositories
     && apk del tzdata
 
 EXPOSE 8888
-VOLUME ["/workspaces/config","/workspaces/log"]
-ENTRYPOINT ["./main"]
+VOLUME ["/app/config","/app/log"]
+ENTRYPOINT ["./main"]
+CMD [ "/app/demo" ]

+ 16 - 0
java/Dockerfile

@@ -0,0 +1,16 @@
+FROM openjdk:8 as base
+LABEL email="liuyuqi<liuyuqi.gov@msn.cn>"
+WORKDIR /app
+COPY . /app
+ENV JAVA_HOME=xx
+
+FROM base as builder
+RUN mvn package
+
+FROM base as runner
+WORKDIR /app
+COPY --from=builder ./target/*.jar app.jar
+
+EXPOSE 8080
+VOLUME [ "/data" ]
+ENTRYPOINT ["java", "-jar", "/app.war"]

+ 17 - 0
nodejs/Dockerfile

@@ -0,0 +1,17 @@
+FROM node:lts-alpine as base
+RUN apk add --no-cache tini
+ENV NODE_ENV=production
+USER  node
+WORKDIR /app
+COPY package*.json ./
+RUN npm install
+COPY . .
+RUN chown -R appuser:appgroup /app
+EXPOSE 8080
+
+FROM base as builder
+
+
+FROM base as runner
+
+CMD [ "npm", "start" ]

+ 32 - 0
nodejs/Dockerfile-front-backend

@@ -0,0 +1,32 @@
+# build front-end
+FROM node:lts-alpine AS frontend
+RUN npm install pnpm -g
+WORKDIR /app
+COPY ./package.json /app
+COPY ./pnpm-lock.yaml /app
+RUN pnpm install
+COPY . /app
+RUN pnpm run build
+
+# build backend
+FROM node:lts-alpine as backend
+RUN npm install pnpm -g
+WORKDIR /app
+COPY /service/package.json /app
+COPY /service/pnpm-lock.yaml /app
+RUN pnpm install
+COPY /service /app
+RUN pnpm build
+
+# service
+FROM node:lts-alpine as runner
+RUN npm install pnpm -g
+WORKDIR /app
+COPY /service/package.json /app
+COPY /service/pnpm-lock.yaml /app
+RUN pnpm install --production && rm -rf /root/.npm /root/.pnpm-store /usr/local/share/.cache /tmp/*
+COPY /service /app
+COPY --from=frontend /app/dist /app/public
+COPY --from=backend /app/build /app/build
+EXPOSE 3002
+CMD ["pnpm", "run", "prod"]

+ 14 - 0
nodejs/README.md

@@ -0,0 +1,14 @@
+# nodejs
+
+## Dockerfile
+
+常见的vue等前后端分离项目,buider层构建,再用base层运行。排除不必要的构建环境。
+
+## Dockerfile-front-backend
+
+前后端都是nodejs项目,且前后端都编译运行。
+
+* 前端编译生成放入./public目录
+* 后端tsup编译生成放入./build目录
+* 运行 esno ./build/index.js启动nodejs项目
+

+ 6 - 0
php/Dockerfile

@@ -0,0 +1,6 @@
+FROM php:7.1-alpine as runner
+WORKDIR /app
+COPY . /app
+
+EXPOSE 8080
+CMD [ "php","index.php" ]

+ 7 - 0
python/Dockerfile

@@ -0,0 +1,7 @@
+FROM python:3.8
+WORKDIR /app
+ADD . ./app
+RUN pip install -r requirements.txt
+
+
+CMD [ "python","main.py" ]

+ 13 - 0
python/Dockerfile-pyinstall

@@ -0,0 +1,13 @@
+FROM python:3.8 as base
+WORKDIR /app
+ADD . ./app
+RUN pip install -r requirements.txt
+
+
+FROM base as builder
+RUN pip install pyinstaller
+RUN pyinstaller -F -c demo.py
+
+FROM base as runner
+COPY --from=builder . /app/
+CMD [ "python", "main.py" ]

+ 17 - 0
ruby/Dockerfile

@@ -0,0 +1,17 @@
+FROM node:lts-alpine as base
+RUN apk add --no-cache tini
+ENV NODE_ENV=production
+USER  node
+WORKDIR /app
+COPY package*.json ./
+RUN npm install
+COPY . .
+RUN chown -R appuser:appgroup /app
+EXPOSE 8080
+
+FROM base as builder
+
+
+FROM base as runner
+
+CMD [ "npm", "start" ]