Skip to content

Commit ee23ced

Browse files
authored
Add CentOS based images for 2.0 (#134)
1 parent 13f6b78 commit ee23ced

File tree

6 files changed

+192
-31
lines changed

6 files changed

+192
-31
lines changed

2.0/build/Dockerfile

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
FROM centos/dotnet-20-runtime-centos7
2+
# This image provides a .NET Core 2.0 environment you can use to run your .NET
3+
# applications.
4+
5+
# Default to UTF-8 file.encoding
6+
ENV PATH=/opt/app-root/src/.local/bin:/opt/app-root/src/bin:/opt/app-root/node_modules/.bin:${PATH} \
7+
STI_SCRIPTS_PATH=/usr/libexec/s2i
8+
9+
LABEL io.k8s.description="Platform for building and running .NET Core 2.0 applications" \
10+
io.k8s.display-name=".NET Core 2.0" \
11+
io.openshift.s2i.scripts-url=image:///usr/libexec/s2i \
12+
io.openshift.tags="builder,.net,dotnet,dotnetcore,rh-dotnet20" \
13+
io.openshift.expose-services="8080:http" \
14+
io.s2i.scripts-url=image:///usr/libexec/s2i
15+
16+
# Labels consumed by Red Hat build service
17+
LABEL name="centos/dotnet-20-centos7" \
18+
com.redhat.component="rh-dotnet20-docker" \
19+
version="2.0" \
20+
release="1" \
21+
architecture="x86_64"
22+
23+
# Labels consumed by Eclipse JBoss OpenShift plugin
24+
LABEL com.redhat.dev-mode="DEV_MODE:false" \
25+
com.redhat.deployments-dir="/opt/app-root/src"
26+
27+
# Switch to root for package installs
28+
USER 0
29+
30+
# Copy the S2I scripts from the specific language image to $STI_SCRIPTS_PATH.
31+
COPY ./s2i/bin/ /usr/libexec/s2i
32+
33+
RUN yum install -y centos-release-dotnet centos-release-scl-rh && \
34+
INSTALL_PKGS="rh-nodejs6-npm rh-nodejs6-nodejs-nodemon rh-dotnet20-dotnet-sdk-2.0 rsync" && \
35+
yum install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \
36+
rpm -V $INSTALL_PKGS && \
37+
yum clean all -y
38+
39+
# Directory with the sources is set as the working directory.
40+
RUN mkdir /opt/app-root/src
41+
WORKDIR /opt/app-root/src
42+
43+
# Since $HOME is set to /opt/app-root, the yum install may have created config
44+
# directories (such as ~/.pki/nssdb) there. These will be owned by root and can
45+
# cause actions that work on all of /opt/app-root to fail. So we need to fix
46+
# the permissions on those too.
47+
RUN chown -R 1001:0 /opt/app-root && fix-permissions /opt/app-root
48+
49+
ENV ENABLED_COLLECTIONS="$ENABLED_COLLECTIONS rh-nodejs6"
50+
51+
# Run container by default as user with id 1001 (default)
52+
USER 1001
53+
54+
# Set the default CMD to print the usage of the language image.
55+
CMD /usr/libexec/s2i/usage

2.0/build/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ To build a simple [dotnet-sample-app](test/asp-net-hello-world) application
1313
using standalone [S2I](https://github.com/openshift/source-to-image) and then run the
1414
resulting image with [Docker](http://docker.io) execute:
1515

16-
* **For RHEL based image**
17-
1816
```
1917
$ sudo s2i build git://github.com/redhat-developer/s2i-dotnetcore --context-dir=2.0/test/asp-net-hello-world dotnet/dotnet-20-rhel7 dotnet-sample-app
2018
$ sudo docker run -p 8080:8080 dotnet-sample-app
@@ -36,6 +34,10 @@ Repository organization
3634
RHEL based Dockerfile. In order to perform build or test actions on this
3735
Dockerfile you need to run the action on a properly subscribed RHEL machine.
3836

37+
* **Dockerfile**
38+
39+
CentOS based Dockerfile.
40+
3941
* **`root/usr/bin/`**
4042

4143
This folder contains common scripts.

2.0/runtime/Dockerfile

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
FROM centos:7
2+
# This image provides a .NET Core 2.0 environment you can use to run your .NET
3+
# applications.
4+
5+
EXPOSE 8080
6+
7+
ENV DOTNET_CORE_VERSION=2.0
8+
9+
# Default to UTF-8 file.encoding
10+
ENV LANG=C.UTF-8 \
11+
HOME=/opt/app-root \
12+
PATH=/opt/app-root/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
13+
DOTNET_APP_PATH=/opt/app-root/app \
14+
DOTNET_DEFAULT_CMD=default-cmd.sh
15+
16+
LABEL io.k8s.description="Platform for running .NET Core 2.0 applications" \
17+
io.k8s.display-name=".NET Core 2.0" \
18+
io.openshift.tags="runtime,.net,dotnet,dotnetcore,rh-dotnet20-runtime" \
19+
io.openshift.expose-services="8080:http"
20+
21+
# Labels consumed by Red Hat build service
22+
LABEL name="centos/dotnet-20-runtime-centos7" \
23+
com.redhat.component="rh-dotnet20-runtime-docker" \
24+
version="2.0" \
25+
release="1" \
26+
architecture="x86_64"
27+
28+
# Don't download/extract docs for nuget packages
29+
ENV NUGET_XMLDOC_MODE=skip
30+
31+
# Don't do initially populate of package cache
32+
ENV DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
33+
34+
## By default, ASP.NET Core runs on port 5000. We configure it to match
35+
## the container port.
36+
ENV ASPNETCORE_URLS=http://*:8080
37+
38+
# Each language image can have 'contrib' a directory with extra files needed to
39+
# run and build the applications.
40+
COPY ./contrib/ /opt/app-root
41+
42+
COPY ./root/usr/bin /usr/bin
43+
44+
RUN yum install -y centos-release-dotnet && \
45+
INSTALL_PKGS="rh-dotnet20-dotnet-runtime-2.0 nss_wrapper tar unzip" && \
46+
yum install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \
47+
rpm -V $INSTALL_PKGS && \
48+
yum clean all -y
49+
50+
# Get prefix path and path to scripts rather than hard-code them in scripts
51+
ENV CONTAINER_SCRIPTS_PATH=/opt/app-root \
52+
ENABLED_COLLECTIONS="rh-dotnet20"
53+
54+
# When bash is started non-interactively, to run a shell script, for example it
55+
# looks for this variable and source the content of this file. This will enable
56+
# the SCL for all scripts without need to do 'scl enable'.
57+
ENV BASH_ENV=${CONTAINER_SCRIPTS_PATH}/etc/scl_enable \
58+
ENV=${CONTAINER_SCRIPTS_PATH}/etc/scl_enable \
59+
PROMPT_COMMAND=". ${CONTAINER_SCRIPTS_PATH}/etc/scl_enable"
60+
61+
# Add default user
62+
RUN mkdir -p ${DOTNET_APP_PATH} && \
63+
useradd -u 1001 -r -g 0 -d ${HOME} -s /sbin/nologin \
64+
-c "Default Application User" default
65+
66+
WORKDIR ${DOTNET_APP_PATH}
67+
COPY default-cmd.sh ${DOTNET_DEFAULT_CMD}
68+
CMD "./${DOTNET_DEFAULT_CMD}"
69+
70+
# In order to drop the root user, we have to make some directories world
71+
# writable as OpenShift default security model is to run the container under
72+
# random UID.
73+
RUN chown -R 1001:0 /opt/app-root && fix-permissions /opt/app-root
74+
75+
ENTRYPOINT [ "container-entrypoint" ]
76+
77+
# Run container by default as user with id 1001 (default)
78+
USER 1001

2.0/runtime/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ Repository organization
4646
RHEL based Dockerfile. In order to perform build or test actions on this
4747
Dockerfile you need to run the action on a properly subscribed RHEL machine.
4848

49+
* **Dockerfile**
50+
51+
CentOS based Dockerfile.
52+
4953
* **`test/`**
5054

5155
This folder contains binary archives of [S2I](https://github.com/openshift/source-to-image)

README.md

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,26 @@ image can be run using [Docker](http://docker.io).
88

99
Versions
1010
----------------
11+
1112
.NET Core versions currently provided are:
12-
* 1.0
13-
* 1.1
14-
* 2.0
1513

16-
RHEL versions currently supported are:
17-
* RHEL 7
14+
* 1.0 (RHEL 7)
15+
* 1.1 (RHEL 7)
16+
* 2.0 (RHEL 7, CentOS 7)
1817

19-
Installation
20-
----------------
2118

22-
To build a RHEL 7 based .NET Core image, you need to run the build on a
23-
properly subscribed RHEL machine.
19+
Building
20+
----------------
2421

2522
```
2623
$ git clone https://github.com/redhat-developer/s2i-dotnetcore.git
27-
$ cd s2i-dotnetcore/1.0
28-
$ sudo docker build -f Dockerfile.rhel7 -t dotnet/dotnetcore-10-rhel7 .
24+
$ sudo VERSIONS=2.0 ./build.sh
2925
```
3026

27+
Note: to build RHEL 7 based images, you need to run the build on a
28+
properly subscribed RHEL machine. To build CentOS images on RHEL, set
29+
BUILD_CENTOS=true. On non-RHEL, building CentOS images is the default.
30+
3131
Usage
3232
---------------------------------
3333

@@ -43,13 +43,15 @@ see [1.0 usage documentation](1.0/README.md).
4343

4444
Image name structure
4545
------------------------
46-
##### Structure: dotnet/1-2-3
4746

48-
1. Platform name (lowercase) - dotnetcore
49-
2. Platform version (without dots) - 10
50-
3. Base builder image - rhel7
47+
##### Structure: 1/2-3-4
48+
49+
1. Prefix: 'dotnet' for RHEL, 'centos' for CentOS
50+
2. Platform name: 'dotnetcore' for 1.x, 'dotnet' for 2.0+
51+
3. Platform version (without dots)
52+
4. Base builder image: 'rhel7' or 'centos7'
5153

52-
Example: `dotnet/dotnetcore-10-rhel7`
54+
Examples: `dotnet/dotnetcore-10-rhel7`, `centos/dotnet-20-centos7`
5355

5456
OpenShift Templates
5557
-------------------

build.sh

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#
1414
# VERSIONS The list of versions to build/test.
1515
# Defaults to all versions. i.e "1.0 1.1".
16+
#
17+
# BUILD_CENTOS If 'true' build CentOS based images.
1618
# -----------------------------------------------------
1719
#
1820
# Usage:
@@ -49,36 +51,54 @@ check_result_msg() {
4951

5052
build_image() {
5153
local path=$1
52-
local name=$2
54+
local docker_filename=$2
55+
local name=$3
5356
if ! image_exists ${name}; then
5457
echo "Building Docker image ${name} ..."
5558
if [ ! -d "${path}" ]; then
5659
echo "No directory found at given location '${path}'. Skipping this image."
5760
return
5861
fi
5962
pushd ${path} &>/dev/null
60-
docker build -f Dockerfile.rhel7 -t ${name} .
63+
docker build -f ${docker_filename} -t ${name} .
6164
check_result_msg $? "Building Docker image ${name} FAILED!"
6265
popd &>/dev/null
6366
fi
6467
}
6568

6669
test_images() {
6770
local path=$1
71+
local test_image=$2
72+
local runtime_image=$3
6873
echo "Running tests..."
69-
${path}/run
74+
IMAGE_NAME=${test_image} RUNTIME_IMAGE_NAME=${runtime_image} ${path}/run
7075
check_result_msg $? "Tests FAILED!"
7176
}
7277

73-
VERSIONS="${VERSIONS:-1.0 1.1 2.0}"
78+
# Default to CentOS when not on RHEL.
79+
if ! [[ `grep "Red Hat Enterprise Linux" /etc/redhat-release` ]]; then
80+
BUILD_CENTOS=true
81+
fi
82+
83+
if [ "$BUILD_CENTOS" = "true" ]; then
84+
VERSIONS="${VERSIONS:-2.0}"
85+
image_os="centos7"
86+
image_prefix="centos"
87+
docker_filename="Dockerfile"
88+
else
89+
VERSIONS="${VERSIONS:-1.0 1.1 2.0}"
90+
image_prefix="dotnet"
91+
image_os="rhel7"
92+
docker_filename="Dockerfile.rhel7"
93+
fi
7494

7595
for v in ${VERSIONS}; do
7696
if [ "$v" == "1.0" ] || [ "$v" == "1.1" ]; then
77-
build_name="dotnet/$(base_image_name ${v})-rhel7"
97+
build_name="${image_prefix}/$(base_image_name ${v})-${image_os}"
7898

7999
# Build the build image
80-
build_image "${v}" "${build_name}"
81-
test_images "${v}/test"
100+
build_image "${v}" "${docker_filename}" "${build_name}"
101+
test_images "${v}/test" "${build_name}"
82102

83103
if [ "$TEST_OPENSHIFT" = "true" ]; then
84104
build_name="registry.access.redhat.com/${build_name}:latest"
@@ -89,16 +109,16 @@ for v in ${VERSIONS}; do
89109
popd &>/dev/null
90110
fi
91111
else
92-
build_name="dotnet/$(base_image_name ${v})-rhel7"
93-
runtime_name="dotnet/$(base_image_name ${v})-runtime-rhel7"
112+
build_name="${image_prefix}/$(base_image_name ${v})-${image_os}"
113+
runtime_name="${image_prefix}/$(base_image_name ${v})-runtime-${image_os}"
94114

95115
# Build the runtime image
96-
build_image "${v}/runtime" "${runtime_name}"
97-
test_images "${v}/runtime/test"
116+
build_image "${v}/runtime" "${docker_filename}" "${runtime_name}"
117+
test_images "${v}/runtime/test" "${runtime_name}"
98118

99119
# Build the build image
100-
build_image "${v}/build" "${build_name}"
101-
test_images "${v}/build/test"
120+
build_image "${v}/build" "${docker_filename}" "${build_name}"
121+
test_images "${v}/build/test" "${build_name}" "${runtime_name}"
102122

103123
if [ "$TEST_OPENSHIFT" = "true" ]; then
104124
build_name="registry.access.redhat.com/${build_name}:latest"

0 commit comments

Comments
 (0)