1. 下载 source-to-image 最新版 解压 配置到path
https://github.com/openshift/source-to-image/releases
2. 创建 S2I Builder镜像
s2i create s2i-tomcat s2i-tomcat
3. 编辑Dockerfile
# s2i-tomcatFROM openshift/base-centos7 MAINTAINER Rabbit <380303318@qq.com> EXPOSE 8080 ENV TOMCAT_VERSION=8.5.24 \ MAVEN_VERSION=3.5.2 LABEL io.k8s.description="Platform for building and running JEE applications on Tomcat" \ io.k8s.display-name="Tomcat Builder" \ io.openshift.expose-services="8080:http" \ io.openshift.tags="builder,tomcat" \ io.openshift.s2i.destination="/opt/s2i/destination"# Install Maven, Tomcat 8.5.24RUN INSTALL_PKGS="tar java-1.8.0-openjdk java-1.8.0-openjdk-devel" && \ yum install -y --enablerepo=centosplus $INSTALL_PKGS && \ rpm -V $INSTALL_PKGS && \ yum clean all -y && \ (curl -v http://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/$MAVEN_VERSION/binaries/apache-maven-$MAVEN_VERSION-bin.tar.gz | \ tar -zx -C /usr/local) && \ ln -sf /usr/local/apache-maven-$MAVEN_VERSION/bin/mvn /usr/local/bin/mvn && \ mkdir -p $HOME/.m2 && \ mkdir -p /tomcat && \ (curl -v http://mirrors.hust.edu.cn/apache/tomcat/tomcat-8/v$TOMCAT_VERSION/bin/apache-tomcat-$TOMCAT_VERSION.tar.gz | tar -zx --strip-components=1 -C /tomcat) && \ rm -rf /tomcat/webapps/* && \ mkdir -p /opt/s2i/destination# Add s2i customizationsADD ./contrib/settings.xml $HOME/.m2/# Copy the S2I scripts from the specific language image to $STI_SCRIPTS_PATHCOPY ./s2i/bin/ $STI_SCRIPTS_PATHRUN chmod -R a+rw /tomcat && \ chmod a+rwx /tomcat/* && \ chmod +x /tomcat/bin/*.sh && \ chmod -R a+rw $HOME && \ chmod -R +x $STI_SCRIPTS_PATH && \ chmod -R g+rw /opt/s2i/destination USER 1001 CMD $STI_SCRIPTS_PATH/usage
4. 在assemble 最后面添加
mvn -Dmaven.test.skip=true clean packagemv ./target/*.war /tomcat/webapps/
5. 在run 最后面添加
bash -c "/tomcat/bin/catalina.sh run"
6. 把项目代码上传到git
https://github.com/silentwu/s2i-tomcat
在阿里云镜像仓库中配置 代码地址构建镜像
7. 导入镜像到openshift
oc import-image registry.cn-hangzhou.aliyuncs.com/monkeyk/s2i-tomcat:8.5.24 -n openshift --confirm --insecure
为了让OpenShift识别出这个镜像是S2I的Builder镜像,需要编辑刚导入的Image Stream,添加注解“tags”
# oc edit is/s2i-tomcat -n openshift
添加如下内容:
tags: - annotations: description: 'Build and run Tomcat applications on CentOS 7. For more information about using this builder image, including OpenShift considerations, see https://github.com/silentwu/s2i-tomcat.git.' iconClass: icon-wildfly openshift.io/display-name: Tomcat 8.5.24 openshift.io/provider-display-name: 'Rabbit blog, http://blog.xianshiyue.com' sampleRepo: 'https://gitee.com/silentwu/openshift-tomcat.git' supports: 'tomcat:8.5.24,jee,java' tags: 'builder,tomcat,java' version: 8.5.24
作者:9527华安
链接:https://www.jianshu.com/p/fd3e62263046
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦