Commit 55eafc07 by Benedikt

Use s2i best practices adopted from openshift/sti-base and openshift/sti-ruby

parent 06bdfd92
...@@ -5,6 +5,13 @@ ...@@ -5,6 +5,13 @@
FROM centos:centos7 FROM centos:centos7
# Location of the STI scripts inside the image
#
LABEL io.openshift.s2i.scripts-url=image:///usr/libexec/s2i
# Path to be used in other layers to place s2i scripts into
ENV STI_SCRIPTS_PATH=/usr/libexec/s2i
ENV JAVA_VERSON 1.8.0 ENV JAVA_VERSON 1.8.0
ENV MAVEN_VERSION 3.3.9 ENV MAVEN_VERSION 3.3.9
...@@ -21,12 +28,7 @@ ENV JAVA_HOME /usr/lib/jvm/java ...@@ -21,12 +28,7 @@ ENV JAVA_HOME /usr/lib/jvm/java
ENV MAVEN_HOME /usr/share/maven ENV MAVEN_HOME /usr/share/maven
# Add configuration files, bashrc and other tweaks # Add configuration files, bashrc and other tweaks
ADD ./.sti/bin/usage /opt/java/bin/ ADD ./s2i/bin/ $STI_SCRIPTS_PATH
# Default STI scripts url
ENV STI_SCRIPTS_URL https://raw.githubusercontent.com/codecentric/springboot-maven3-centos/master/.sti/bin
# Default destination of scripts and sources, this is where assemble will look for them
ENV STI_LOCATION /tmp
# Create 'ruby' account we will use to run Ruby application # Create 'ruby' account we will use to run Ruby application
# Add support for '#!/usr/bin/ruby' shebang. # Add support for '#!/usr/bin/ruby' shebang.
...@@ -51,4 +53,5 @@ USER java ...@@ -51,4 +53,5 @@ USER java
EXPOSE 8080 EXPOSE 8080
CMD ["/opt/java/bin/usage"] # Set the default CMD to print the usage of the language image
CMD $STI_SCRIPTS_PATH/usage
...@@ -5,7 +5,7 @@ This repository contains the sources and ...@@ -5,7 +5,7 @@ This repository contains the sources and
[Dockerfile](https://github.com/codecentric/springboot-maven3-centos/blob/master/Dockerfile) [Dockerfile](https://github.com/codecentric/springboot-maven3-centos/blob/master/Dockerfile)
of the base image for deploying Spring Boot applications as reproducible Docker of the base image for deploying Spring Boot applications as reproducible Docker
images. The resulting images can be run either by [Docker](http://docker.io) images. The resulting images can be run either by [Docker](http://docker.io)
or using [STI](https://github.com/openshift/source-to-image). or using [S2I](https://github.com/openshift/source-to-image).
This image is heavily inspired by the awesome [openshift/ruby-20-centos](https://github.com/openshift/ruby-20-centos/) This image is heavily inspired by the awesome [openshift/ruby-20-centos](https://github.com/openshift/ruby-20-centos/)
builder image. builder image.
...@@ -18,9 +18,9 @@ _TODO_ Publish Image to Docker Hub ...@@ -18,9 +18,9 @@ _TODO_ Publish Image to Docker Hub
Repository organization Repository organization
------------------------ ------------------------
* **`.sti/bin/`** * **`s2i/bin/`**
This folder contains scripts that are run by [STI](https://github.com/openshift/source-to-image): This folder contains scripts that are run by [S2I](https://github.com/openshift/source-to-image):
* **assemble** * **assemble**
...@@ -51,13 +51,6 @@ Environment variables ...@@ -51,13 +51,6 @@ Environment variables
application GIT repository. In case your application is located in a application GIT repository. In case your application is located in a
sub-folder, you can set this variable to a *./myapplication*. sub-folder, you can set this variable to a *./myapplication*.
* **STI_SCRIPTS_URL** (default: '[.sti/bin](https://raw.githubusercontent.com/codecentric/springboot-maven3-centos/master/.sti/bin)')
This variable specifies the location of directory, where *assemble*, *run* and
*save-artifacts* scripts are downloaded/copied from. By default the scripts
in this repository will be used, but users can provide an alternative
location and run their own scripts.
Contributing Contributing
------------ ------------
...@@ -76,10 +69,10 @@ Usage ...@@ -76,10 +69,10 @@ Usage
**Building the [spring-boot-example](https://github.com/codecentric/spring-boot-example) Spring Boot application..** **Building the [spring-boot-example](https://github.com/codecentric/spring-boot-example) Spring Boot application..**
1. **using standalone [STI](https://github.com/openshift/source-to-image) and running the resulting image by [Docker](http://docker.io):** 1. **using standalone [S2I](https://github.com/openshift/source-to-image) and running the resulting image by [Docker](http://docker.io):**
``` ```
$ sti build git://github.com/codecentric/spring-boot-example codecentric/springboot-maven3-centos spring-boot-app $ s2i build git://github.com/codecentric/spring-boot-example codecentric/springboot-maven3-centos spring-boot-app
$ docker run -p 8080:8080 spring-boot-app $ docker run -p 8080:8080 spring-boot-app
``` ```
......
...@@ -13,9 +13,9 @@ image_dir=$(readlink -zf ${test_dir}/..) ...@@ -13,9 +13,9 @@ image_dir=$(readlink -zf ${test_dir}/..)
scripts_url="file://${image_dir}/.sti/bin" scripts_url="file://${image_dir}/.sti/bin"
cid_file=$(mktemp -u --suffix=.cid) cid_file=$(mktemp -u --suffix=.cid)
# Since we built the candidate image locally, we don't want STI attempt to pull # Since we built the candidate image locally, we don't want S2I attempt to pull
# it from Docker hub # it from Docker hub
sti_args="-s ${scripts_url}" s2i_args="--force-pull=false"
# TODO: This should be part of the image metadata # TODO: This should be part of the image metadata
test_port=8080 test_port=8080
...@@ -36,8 +36,8 @@ container_ip() { ...@@ -36,8 +36,8 @@ container_ip() {
docker inspect --format="{{ .NetworkSettings.IPAddress }}" $(cat $cid_file) docker inspect --format="{{ .NetworkSettings.IPAddress }}" $(cat $cid_file)
} }
run_sti_build() { run_s2i_build() {
sti build ${sti_args} file://${test_dir}/test-app ${IMAGE_NAME} ${IMAGE_NAME}-testapp s2i build ${sti_args} file://${test_dir}/test-app ${IMAGE_NAME} ${IMAGE_NAME}-testapp
} }
prepare() { prepare() {
...@@ -95,9 +95,14 @@ wait_for_cid() { ...@@ -95,9 +95,14 @@ wait_for_cid() {
done done
} }
test_usage() { test_s2i_usage() {
info "Testing the 'sti usage' command" info "Testing the 'sti usage' command"
sti usage ${sti_args} ${IMAGE_NAME} &>/dev/null s2i usage ${sti_args} ${IMAGE_NAME} &>/dev/null
}
test_docker_run_usage() {
info "Testing 'docker run' usage"
docker run ${IMAGE_NAME} &>/dev/null
} }
test_connection() { test_connection() {
...@@ -130,7 +135,11 @@ run_sti_build ...@@ -130,7 +135,11 @@ run_sti_build
check_result $? check_result $?
# Verify the 'usage' script is working properly # Verify the 'usage' script is working properly
test_usage test_s2i_usage
check_result $?
# Verify the 'usage' script is working properly when running the base image with 'docker run ...'
test_docker_run_usage
check_result $? check_result $?
# Verify that the HTTP connection can be established to test application container # Verify that the HTTP connection can be established to test application container
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment