为了构建一个Spring Boot项目并将其部署到Google Cloud Build的Google App Engine上,我最终需要使用以下镜像构建“构建器”镜像,并在执行实际应用程序构建时引用该镜像。
Dockerfile
FROM debian:stretch
RUN apt-get update -y && \
apt-get install \
apt-utils \
dialog \
gnupg \
lsb-release \
curl -y && \
export CLOUD_SDK_REPO="cloud-sdk-$(lsb_release -c -s)" && \
echo "deb http://packages.cloud.google.com/apt $CLOUD_SDK_REPO main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list && \
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - && \
apt-get update -y && \
apt-get install google-cloud-sdk -y
RUN apt-get install google-cloud-sdk \
google-cloud-sdk \
google-cloud-sdk-app-engine-go \
google-cloud-sdk-app-engine-java \
google-cloud-sdk-app-engine-python \
google-cloud-sdk-app-engine-python-extras \
google-cloud-sdk-bigtable-emulator \
google-cloud-sdk-cbt \
google-cloud-sdk-datastore-emulator \
google-cloud-sdk-cloud-build-local \
google-cloud-sdk-datalab \
kubectl \
google-cloud-sdk-pubsub-emulator -y
RUN apt-get install openjdk-8-jdk -y
ARG MAVEN_VERSION=3.5.4
ARG USER_HOME_DIR="/root"
ARG SHA=ce50b1c91364cb77efe3776f756a6d92b76d9038b0a0782f7d53acf1e997a14d
ARG BASE_URL=https://apache.osuosl.org/maven/maven-3/${MAVEN_VERSION}/binaries
RUN mkdir -p /usr/share/maven /usr/share/maven/ref \
&& curl -fsSL -o /tmp/apache-maven.tar.gz ${BASE_URL}/apache-maven-${MAVEN_VERSION}-bin.tar.gz \
&& echo "${SHA} /tmp/apache-maven.tar.gz" | sha256sum -c - \
&& tar -xzf /tmp/apache-maven.tar.gz -C /usr/share/maven --strip-components=1 \
&& rm -f /tmp/apache-maven.tar.gz \
&& ln -s /usr/share/maven/bin/mvn /usr/bin/mvn
ENV MAVEN_HOME /usr/share/maven
ENV MAVEN_CONFIG "$USER_HOME_DIR/.m2"
WORKDIR /workspace
cloudbuild.yaml
steps:
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '--tag=gcr.io/$PROJECT_ID/gcloud-maven', '.']
- name: 'gcr.io/$PROJECT_ID/gcloud-maven'
args: ['java', '-version']
- name: 'gcr.io/$PROJECT_ID/gcloud-maven'
args: ['gcloud', 'projects', 'list']
- name: 'gcr.io/$PROJECT_ID/gcloud-maven'
args: ['mvn', '--version']
images: ['gcr.io/$PROJECT_ID/gcloud-maven']
timeout: 1200s
我的Spring Boot项目的
cloudbuild.yaml
文件现在引用了这个镜像:
steps:
- name: 'gcr.io/$PROJECT_ID/gcloud-maven'
args: ['mvn', 'appengine:deploy']
我将尝试将此Docker镜像放置在Dockerhub和Github上供其他人查找。我也会感激那些更熟悉Docker和Linux的人帮助改进此镜像,以减少其大小(例如,使用Alpine而不是Debian或Debian Stretch Slim)。同时,我希望这可以帮助像我这样的其他人。
args:['install']
与maven一起使用,在这个示例中在['package']
之前。你已经尝试过了吗? - A.Queue