Services

Open source

EN

Docker — from code to image with S2I

-

Getup

Normally, to generate an executable docker image, we use the docker build command, which copies the source code of our app into an image specifically prepared for the language.

From this pattern arises the need to create a tool that can standardize the build mechanism across multiple languages, offering flexibility, reproducibility, security, and speed.

Below we provide two videos that introduce the user to the Source-to-Image mechanism (s2i to friends) created specifically to meet the above purposes.

Here at Getup Cloud, we use S2I to allow our users to run the exact same production runtime environment on their local development host.

Try it for free at https://getupcloud.com.

S2I — Introduction

[embed]https://www.youtube.com/watch?v=mtSL3QWBli4[/embed]

Download link: https://github.com/openshift/source-to-image/releases

Download the image-builder for your language:

$ sudo docker pull getupcloud/php-70-centos7

Some popular images:

getupcloud/php-70-centos7
centos/php-56-centos7
ryanj/centos7-s2i-nodejs:6
centos/python-27-centos7
centos/python-35-centos7
centos/ruby-23-centos7
getupcloud/dotnet-core-10-centos7
openshift/wildfly-100-centos7

To create your executable image, use the s2i command:

$ sudo s2i build /your/source/ getupcloud/php-70-centos7 blog

TIP: the — loglevel=[0–5] flag allows you to adjust the amount of messages during the build.

Your image is ready to run:

$ sudo docker run -it — rm -p 8080:8080 blog
$ curl http://127.1:8080/

S2I — Build and execution hooks

[embed]https://www.youtube.com/watch?v=K9xz2aBjkQk[/embed]

Create the test.sh file in the root of the repo with the test logic for your app.

$ mkdir -p .s2i/bin
$ cat > .s2i/bin/assemble <<EOF

source $STI_SCRIPTS_PATH/assemble

if [ -e ./test.sh ]; then
echo '---> Running tests...'
bash ./test.sh
fi
EOF
$ git add .s2i/bin/assemble
$ git commit .s2i/bin/assemble -m 'Add assemble hook'

During buildup, the test.sh file is executed. If it ends with an error, the build script .s2i/bin/assemble also fails, stopping the build. Otherwise, the new image is ready to run.

We will soon have more videos about this tool.

Until next time!

[embed]https://upscri.be/375ca4/[/embed]

Newsletter Getup.

Atualizações sobre Kubernetes e Software Supply Chain Security todos os meses.

Operating Kubernetes in production for more than 13 years. With Quor, this experience extends to software supply chain security as well.