Skip to content

Commit a8f4df0

Browse files
committed
Overhaul of Source-to-Image
Updating README(s), templates, and examples
1 parent cad7480 commit a8f4df0

File tree

22 files changed

+448
-131
lines changed

22 files changed

+448
-131
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,12 @@ You can start using `s2i` right away (see [releases](https://github.com/openshif
233233
with the following test sources and publicly available images:
234234

235235
```
236-
$ s2i build https://github.com/pmorie/simple-ruby openshift/ruby-20-centos7 test-ruby-app
236+
$ s2i build https://github.com/openshift/ruby-hello-world openshift/ruby-23-centos7 test-ruby-app
237237
$ docker run --rm -i -p :8080 -t test-ruby-app
238238
```
239239

240240
```
241-
$ s2i build https://github.com/bparees/openshift-jee-sample openshift/wildfly-100-centos7 test-jee-app
241+
$ s2i build --ref=7.1.x --context-dir=helloworld https://github.com/jboss-developer/jboss-eap-quickstarts openshift/wildfly-101-centos7 test-jee-app
242242
$ docker run --rm -i -p :8080 -t test-jee-app
243243
```
244244

cmd/s2i/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ func newCmdCreate() *cobra.Command {
269269
b := create.New(args[0], args[1])
270270
b.AddSTIScripts()
271271
b.AddDockerfile()
272+
b.AddReadme()
272273
b.AddTests()
273274
},
274275
}

docs/cli.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,11 @@ Example: data posted will be in the form:
146146

147147
#### Example Usage
148148

149-
Build a Ruby application from a Git source, using the official `ruby-20-centos7` builder
149+
Build a Ruby application from a Git source, using the official `ruby-23-centos7` builder
150150
image, the resulting image will be named `ruby-app`:
151151

152152
```
153-
$ s2i build https://github.com/mfojtik/sinatra-app-example openshift/ruby-20-centos7 ruby-app
153+
$ s2i build https://github.com/openshift/ruby-hello-world openshift/ruby-23-centos7 ruby-app
154154
```
155155

156156
Build a Node.js application from a local directory, using a local image, the resulting
@@ -167,19 +167,19 @@ Use this method only for development or local testing.
167167

168168
**NOTE**: All your changes have to be committed by `git` in order to build them with S2I.
169169

170-
Build a Java application from a Git source, using the official `openshift/wildfly-100-centos7`
170+
Build a Java application from a Git source, using the official `openshift/wildfly-101-centos7`
171171
builder image but overriding the scripts URL from local directory. The resulting
172172
image will be named `java-app`:
173173

174174
```
175-
$ s2i build --scripts-url=file://s2iscripts https://github.com/bparees/openshift-jee-sample openshift/wildfly-100-centos7 java-app
175+
$ s2i build --scripts-url=file://s2iscripts --ref=7.1.x --context-dir=kitchensink https://github.com/jboss-developer/jboss-eap-quickstarts openshift/wildfly-101-centos7 java-app
176176
```
177177

178178
Build a Ruby application from a Git source, specifying `ref`, and using the official
179-
`ruby-20-centos7` builder image. The resulting image will be named `ruby-app`:
179+
`ruby-23-centos7` builder image. The resulting image will be named `ruby-app`:
180180

181181
```
182-
$ s2i build --ref=my-branch https://github.com/mfojtik/sinatra-app-example openshift/ruby-20-centos7 ruby-app
182+
$ s2i build --ref=my-branch https://github.com/openshift/ruby-hello-world openshift/ruby-23-centos7 ruby-app
183183
```
184184

185185
***NOTE:*** If the ref is invalid or not present in the source repository then the build will fail.
@@ -188,7 +188,7 @@ Build a Ruby application from a Git source, overriding the scripts URL from a lo
188188
and specifying the scripts and sources be placed in `/opt` directory:
189189

190190
```
191-
$ s2i build --scripts-url=file://s2iscripts --destination=/opt https://github.com/mfojtik/sinatra-app-example openshift/ruby-20-centos7 ruby-app
191+
$ s2i build --scripts-url=file://s2iscripts --destination=/opt https://github.com/openshift/ruby-hello-world openshift/ruby-23-centos7 ruby-app
192192
```
193193

194194
# s2i rebuild
@@ -232,9 +232,9 @@ $ s2i usage <builder image> [flags]
232232

233233
#### Example Usage
234234

235-
Print the official `ruby-20-centos7` builder image usage:
235+
Print the official `ruby-23-centos7` builder image usage:
236236
```
237-
$ s2i usage openshift/ruby-20-centos7
237+
$ s2i usage openshift/ruby-23-centos7
238238
```
239239

240240

examples/README.md

Lines changed: 0 additions & 52 deletions
This file was deleted.

examples/nginx-app/save-artifacts

Lines changed: 0 additions & 16 deletions
This file was deleted.

examples/nginx-app/test/index.html

Lines changed: 0 additions & 13 deletions
This file was deleted.

examples/nginx-app/Dockerfile renamed to examples/nginx-centos7/Dockerfile

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
12
# nginx-centos7
2-
# Here you can use whatever image base is relevant for your application.
3+
# Here you can use whatever base image is relevant for your application.
34
FROM centos:centos7
45

56
# Here you can specify the maintainer for the image that you're building
6-
MAINTAINER Victor Palade <ipalade@redhat.com>
7+
MAINTAINER Your Name <your.name@example.com>
78

8-
# Export the environment variable that provides information about the application.
9-
# Replace this with the according version for your application.
9+
# Export an environment variable that provides information about the application version.
10+
# Replace this with the version for your application.
1011
ENV NGINX_VERSION=1.6.3
1112

1213
# Set the labels that are used for OpenShift to describe the builder image.
@@ -18,18 +19,30 @@ LABEL io.k8s.description="Nginx Webserver" \
1819
# (run, assemble, save-artifacts)
1920
io.openshift.s2i.scripts-url="image:///usr/libexec/s2i"
2021

21-
# Install our Nginx package and clean the yum cache so that we don't have any
22-
# cached files waste space.
23-
RUN yum install -y epel-release && \
22+
# Install the nginx web server package and clean the yum cache
23+
RUN yum install -y epel-release && \
2424
yum install -y --setopt=tsflags=nodocs nginx && \
2525
yum clean all
2626

27-
# We will change the default port for nginx (It's required if you plan on
28-
# running images as non-root user).
27+
# Change the default port for nginx
28+
# Required if you plan on running images as a non-root user).
2929
RUN sed -i 's/80/8080/' /etc/nginx/nginx.conf
30+
RUN sed -i 's/user nginx;//' /etc/nginx/nginx.conf
3031

3132
# Copy the S2I scripts to /usr/libexec/s2i since we set the label that way
32-
COPY ["run", "assemble", "save-artifacts", "usage", "/usr/libexec/s2i/"]
33+
COPY ./s2i/bin/ /usr/libexec/s2i
34+
35+
RUN chown -R 1001:1001 /opt/app-root
36+
RUN chown -R 1001:1001 /usr/share/nginx
37+
RUN chown -R 1001:1001 /var/log/nginx
38+
RUN chown -R 1001:1001 /var/lib/nginx
39+
RUN touch /run/nginx.pid
40+
RUN chown -R 1001:1001 /run/nginx.pid
41+
42+
USER 1001
43+
44+
# Set the default port for applications built using this image
45+
EXPOSE 8080
3346

3447
# Modify the usage script in your application dir to inform the user how to run
3548
# this image.

examples/nginx-centos7/Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
IMAGE_NAME = nginx-centos7
3+
4+
.PHONY: build
5+
build:
6+
docker build -t $(IMAGE_NAME) .
7+
8+
.PHONY: test
9+
test:
10+
docker build -t $(IMAGE_NAME)-candidate .
11+
IMAGE_NAME=$(IMAGE_NAME)-candidate test/run

examples/nginx-centos7/README.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
2+
# Creating a basic S2I builder image
3+
4+
## Getting started
5+
6+
### Files and Directories
7+
| File | Required? | Description |
8+
|------------------------|-----------|--------------------------------------------------------------|
9+
| Dockerfile | Yes | Defines the base builder image |
10+
| s2i/bin/assemble | Yes | Script that builds the application |
11+
| s2i/bin/usage | No | Script that prints the usage of the builder |
12+
| s2i/bin/run | Yes | Script that runs the application |
13+
| s2i/bin/save-artifacts | No | Script for incremental builds that saves the built artifacts |
14+
| test/run | No | Test script for the builder image |
15+
| test/test-app | Yes | Test application source code |
16+
17+
#### Dockerfile
18+
Create a *Dockerfile* that installs all of the necessary tools and libraries that are needed to build and run our application. This file will also handle copying the s2i scripts into the created image.
19+
20+
#### S2I scripts
21+
22+
##### assemble
23+
Create an *assemble* script that will build our application, e.g.:
24+
- build python modules
25+
- bundle install ruby gems
26+
- setup application specific configuration
27+
28+
The script can also specify a way to restore any saved artifacts from the previous image.
29+
30+
##### run
31+
Create a *run* script that will start the application.
32+
33+
##### save-artifacts (optional)
34+
Create a *save-artifacts* script which allows a new build to reuse content from a previous version of the application image.
35+
36+
##### usage (optional)
37+
Create a *usage* script that will print out instructions on how to use the image.
38+
39+
##### Make the scripts executable
40+
Make sure that all of the scripts are executable by running *chmod +x s2i/bin/**
41+
42+
#### Create the builder image
43+
The following command will create a builder image named nginx-centos7 based on the Dockerfile that was created previously.
44+
```
45+
docker build -t nginx-centos7 .
46+
```
47+
The builder image can also be created by using the *make* command since a *Makefile* is included.
48+
49+
Once image has finished building, the command *s2i usage nginx-centos7* will print out the help info that was defined in the *usage* script.
50+
51+
#### Testing the builder image
52+
The builder image can be tested using the following commands:
53+
```
54+
docker build -t nginx-centos7-candidate .
55+
IMAGE_NAME=nginx-centos7-candidate test/run
56+
```
57+
The builder image can also be tested by using the *make test* command since a *Makefile* is included.
58+
59+
#### Creating the application image
60+
The application image combines the builder image with your applications source code, which is served using whatever application is installed via the *Dockerfile*, compiled using the *assemble* script, and run using the *run* script.
61+
The following command will create the application image:
62+
```
63+
s2i build test/test-app nginx-centos7 nginx-centos7-app
64+
---> Building and installing application from source...
65+
```
66+
Using the logic defined in the *assemble* script, s2i will now create an application image using the builder image as a base and including the source code from the test/test-app directory.
67+
68+
#### Running the application image
69+
Running the application image is as simple as invoking the docker run command:
70+
```
71+
docker run -d -p 8080:8080 nginx-centos7-app
72+
```
73+
The application, which consists of a simple static web page, should now be accessible at [http://localhost:8080](http://localhost:8080).
74+
75+
#### Using the saved artifacts script
76+
Rebuilding the application using the saved artifacts can be accomplished using the following command:
77+
```
78+
s2i build --incremental=true test/test-app nginx-centos7 nginx-app
79+
---> Restoring build artifacts...
80+
---> Building and installing application from source...
81+
```
82+
This will run the *save-artifacts* script which includes the custom code to backup the currently running application source, rebuild the application image, and then re-deploy the previously saved source using the *assemble* script.

examples/nginx-app/assemble renamed to examples/nginx-centos7/s2i/bin/assemble

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@ fi
1616
# Restore artifacts from the previous build (if they exist).
1717
# We set them here just for show, but you will need to set this up with your logic
1818
# according to the application directory that you chose.
19-
if [ "$(ls /tmp/artifacts/ 2>/dev/null)" ]; then
20-
echo "---> Restoring build artifacts..."
21-
mv /tmp/artifacts/* /usr/share/nginx/html/
22-
fi
23-
# Override our default nginx index.html file.
24-
# This is what we consider in this example `installing the application`
19+
20+
#if [ "$(ls /tmp/artifacts/ 2>/dev/null)" ]; then
21+
# echo "---> Restoring build artifacts..."
22+
# mv /tmp/artifacts/* <your directory here>
23+
#fi
24+
25+
# Override the default nginx index.html file.
26+
# This is what we consider in this example 'installing the application'
2527
# here you can go ahead an replace this with the actual building of python modules,
2628
# bundle install, and anything else you need.
29+
2730
echo "---> Building and installing application from source..."
28-
cp -Rf /tmp/src/index.html /usr/share/nginx/html/index.html
31+
mv /tmp/src/* /usr/share/nginx/html/

examples/nginx-app/run renamed to examples/nginx-centos7/s2i/bin/run

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77

88
# We will turn off daemonizing for the nginx process so that the container
99
# doesn't exit after the process runs.
10-
# We will also specify the default port on which it should listen.
10+
1111
exec /usr/sbin/nginx -g "daemon off;"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh -e
2+
#
3+
# S2I save-artifacts script for the 'nginx-centos7' image.
4+
# The save-artifacts script streams a tar archive to standard output.
5+
# The archive contains the files and folders you want to re-use in the next build.
6+
#
7+
# For more information see the documentation:
8+
# https://github.com/openshift/source-to-image/blob/master/docs/builder_image.md
9+
#
10+
#tar cf - <your files here>

examples/nginx-app/usage renamed to examples/nginx-centos7/s2i/bin/usage

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ To use it, install S2I: https://github.com/openshift/source-to-image
55
66
Sample invocation:
77
8-
s2i build test/ nginx-centos7 nginx-app
8+
s2i build test/test-app nginx-centos7 nginx-centos7-app
99
1010
You can then run the resulting image via:
11-
docker run -d -p 8080:8080 nginx-app
11+
docker run -d -p 8080:8080 nginx-centos7-app
1212
and see the test via http://localhost:8080
1313
EOF

0 commit comments

Comments
 (0)