Skip to content

Commit 524525c

Browse files
authored
Create runtime and build images. (#84)
* Create runtime and build images for 2.0
1 parent a5a8f61 commit 524525c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+715
-81
lines changed

2.0/Dockerfile.rhel7 renamed to 2.0/build/Dockerfile.rhel7

+6-22
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
FROM rhel7
1+
FROM dotnet/dotnet-20-rhel7-runtime
22
# This image provides a .NET Core 2.0 environment you can use to run your .NET
33
# applications.
44

5-
EXPOSE 8080
6-
7-
ENV DOTNET_CORE_VERSION=2.0
85
# Default to UTF-8 file.encoding
9-
ENV LANG=C.UTF-8 \
10-
HOME=/opt/app-root \
11-
PATH=/opt/app-root/src/.local/bin:/opt/app-root/src/bin:/opt/app-root/bin:/opt/app-root/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
6+
ENV PATH=/opt/app-root/src/.local/bin:/opt/app-root/src/bin:/opt/app-root/node_modules/.bin:${PATH} \
127
STI_SCRIPTS_PATH=/usr/libexec/s2i \
138
DOTNET_PUBLISH_PATH=/opt/app-root/publish \
149
DOTNET_RUN_SCRIPT=/opt/app-root/publish/s2i_run
@@ -43,7 +38,7 @@ RUN yum install --disablerepo=\* --enablerepo=rhel-7-server-rpms -y yum-utils &&
4338
yum-config-manager --enable rhel-7-server-dotnet-rpms && \
4439
yum-config-manager --enable rhel-7-server-rpms && \
4540
yum-config-manager --enable rhel-7-server-ose-3.2-rpms && \
46-
yum install -y --setopt=tsflags=nodocs nss_wrapper tar rh-nodejs6-npm && \
41+
yum install -y --setopt=tsflags=nodocs rh-nodejs6-npm && \
4742
yum clean all && \
4843
mkdir -p /opt/app-root/{src,publish,warmup} && \
4944
useradd -u 1001 -r -g 0 -d /opt/app-root/src -s /sbin/nologin \
@@ -52,20 +47,13 @@ RUN yum install --disablerepo=\* --enablerepo=rhel-7-server-rpms -y yum-utils &&
5247

5348
# TODO: remove upstream sdk
5449
# install upstream 2.0 sdk
55-
RUN yum install -y libunwind libicu && \
56-
curl https://download.microsoft.com/download/0/6/5/0656B047-5F2F-4281-A851-F30776F8616D/dotnet-dev-linux-x64.2.0.0-preview1-005977.tar.gz -o /tmp/dotnet-sdk.tar.gz && \
57-
mkdir -p /opt/dotnet && \
58-
tar xf /tmp/dotnet-sdk.tar.gz -C /opt/dotnet && \
59-
ln -s /opt/dotnet/dotnet /usr/bin/dotnet
50+
RUN curl https://download.microsoft.com/download/0/6/5/0656B047-5F2F-4281-A851-F30776F8616D/dotnet-dev-linux-x64.2.0.0-preview1-005977.tar.gz -o /tmp/dotnet-sdk.tar.gz && \
51+
tar xf /tmp/dotnet-sdk.tar.gz -C /opt/dotnet "./sdk" && \
52+
rm /tmp/dotnet-sdk.tar.gz
6053

6154
# Switch to default app-user for cache population
6255
USER 1001
6356

64-
# Don't download/extract docs for nuget packages
65-
ENV NUGET_XMLDOC_MODE=skip
66-
# Don't do initially populate of package cache
67-
ENV DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
68-
6957
# TODO: scl enable rh-dotnet20 --
7058
# TODO: replace '.0-preview1-final' from AspNetPackageVersion with '.*'
7159
# Create NuGet package cache
@@ -102,10 +90,6 @@ WORKDIR /opt/app-root/src
10290
# Run container by default as user with id 1001 (default)
10391
USER 1001
10492

105-
# By default, ASP.NET Core runs on port 5000. We configure it to match
106-
# the container port.
107-
ENV ASPNETCORE_URLS=http://*:8080
108-
10993
ENTRYPOINT ["container-entrypoint"]
11094

11195
# Set the default CMD to print the usage of the language image.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

2.0/test/run renamed to 2.0/build/test/run

+83-48
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ declare -a CLI_APPS=(
2929
dotnet-configuration-debug
3030
dotnet-configuration-release
3131
)
32-
declare -a WEB_APPS=(asp-net-hello-world asp-net-hello-world-envvar asp-net-hello-world-envvar2)
32+
declare -a WEB_APPS=(
33+
asp-net-hello-world
34+
asp-net-hello-world-envvar
35+
asp-net-hello-world-envvar2
36+
)
3337

3438
test_dir="$(readlink -zf $(dirname "${BASH_SOURCE[0]}"))"
3539
image_dir=$(readlink -zf ${test_dir}/..)
@@ -47,6 +51,7 @@ image_exists() {
4751
}
4852

4953
container_exists() {
54+
local cid_file="$1"
5055
image_exists $(cat $cid_file)
5156
}
5257

@@ -80,18 +85,23 @@ prepare() {
8085
}
8186

8287
run_test_application() {
83-
docker run --user=100001 ${CONTAINER_ARGS} -d --cidfile=${cid_file} -p ${test_port}:${test_port} ${IMAGE_NAME}-testapp
88+
local image="$1"
89+
local cid_file="$2"
90+
docker run --user=100001 ${CONTAINER_ARGS} -d --cidfile=${cid_file} -p ${test_port}:${test_port} ${image}
8491
}
8592

8693
run_cli_test_application() {
87-
docker run --user=100001 ${CONTAINER_ARGS} -i --rm ${IMAGE_NAME}-testapp
94+
local image=$1
95+
docker run --user=100001 ${CONTAINER_ARGS} -i --rm ${image}
8896
}
8997

90-
cleanup_app() {
98+
cleanup_container() {
99+
local cid_file="$1"
91100
info "Cleaning up app container ..."
92101
if [ -f $cid_file ]; then
93-
if container_exists; then
102+
if container_exists "${cid_file}"; then
94103
docker stop $(cat $cid_file)
104+
docker rm $(cat $cid_file)
95105
fi
96106
fi
97107
}
@@ -118,7 +128,7 @@ check_command_exists_at()
118128
local command=$1
119129
local at=$2
120130
info "Testing if ${command} is at ${at}"
121-
local actual=$(docker run ${IMAGE_NAME}-testapp bash -c "command -v ${command}")
131+
local actual=$(docker run --rm ${IMAGE_NAME}-testapp bash -c "command -v ${command}")
122132
if [[ "${at}_" != "${actual}_" ]]; then
123133
info "TEST FAILED (${command} is at ${actual}, expected ${at})"
124134
cleanup
@@ -148,7 +158,7 @@ test_s2i_usage() {
148158
test_docker_run_usage() {
149159
local expected="$1"
150160
info "Testing 'docker run' usage (${expected}) ..."
151-
docker run ${IMAGE_NAME} 2>&1 | grep "${expected}" 2>&1 >/dev/null
161+
docker run --rm ${IMAGE_NAME} 2>&1 | grep "${expected}" 2>&1 >/dev/null
152162
}
153163

154164
test_pid_1() {
@@ -159,7 +169,7 @@ test_pid_1() {
159169
out="$(docker exec $(cat ${cid_file}) /bin/bash -c 'ps --no-headers -o args 1' 2>&1)"
160170
if ! echo "${out}" | grep "dotnet" | grep -q '\.dll' ; then
161171
echo "'dotnet <assembly>' not process with PID 1. PID 1 process was: '${out}'"
162-
cleanup_app
172+
cleanup_container "${cid_file}"
163173
return 1
164174
fi
165175
}
@@ -168,9 +178,10 @@ test_scl_usage() {
168178
local run_cmd="$1"
169179
local expected="$2"
170180
local cid_file="$3"
181+
local image="$4"
171182

172-
info "Testing the image SCL enable"
173-
out=$(docker run --rm ${IMAGE_NAME} /bin/bash -c "${run_cmd}" 2>&1)
183+
info "Testing the image SCL enable for '${run_cmd}'"
184+
out=$(docker run --rm ${image} /bin/bash -c "${run_cmd}" 2>&1)
174185
if ! echo "${out}" | grep -q "${expected}"; then
175186
echo "ERROR[/bin/bash -c "${run_cmd}"] Expected '${expected}', got '${out}'"
176187
return 1
@@ -233,52 +244,88 @@ test_http() {
233244
return $result
234245
}
235246

236-
test_web_application() {
237-
local cid_file=$(mktemp -u --suffix=.cid)
238-
# Verify that the HTTP connection can be established to test application container
239-
run_test_application &
247+
test_web_app_http() {
248+
test_http "/" "Hello world"
249+
check_result $?
250+
test_http "/TextFile.txt" "A text file."
251+
check_result $?
252+
}
240253

241-
# Wait for the container to write it's CID file
242-
wait_for_cid
254+
test_web_app_scl() {
255+
local image="$1"
256+
local cid_file="$2"
243257

244-
test_scl_usage "dotnet --version" "${dotnet_version}" "${cid_file}"
258+
test_scl_usage "dotnet --version" "${dotnet_version}" "${cid_file}" "${image}"
245259
check_result $?
246260

247261
# Verify $HOME != $CWD. See https://github.com/redhat-developer/s2i-dotnetcore/issues/28
248-
test_scl_usage "pwd" "/opt/app-root/src" "${cid_file}"
262+
test_scl_usage "pwd" "/opt/app-root/src" "${cid_file}" "${image}"
249263
check_result $?
250-
test_scl_usage "echo \$HOME" "/opt/app-root" "${cid_file}"
264+
test_scl_usage "echo \$HOME" "/opt/app-root" "${cid_file}" "${image}"
251265
check_result $?
252266

253267
# Verify npm is enabled in the container
254-
test_scl_usage "npm --version" "2.15.1" "${cid_file}"
268+
test_scl_usage "npm --version" "2.15.1" "${cid_file}" "${image}"
269+
}
255270

256-
test_http "/" "Hello world"
257-
check_result $?
258-
test_http "/TextFile.txt" "A text file."
259-
check_result $?
271+
init_web_app() {
272+
local image="$1"
273+
local cid_file="$2"
274+
275+
# Verify that the HTTP connection can be established to test application container
276+
run_test_application "${image}" "${cid_file}" &
277+
278+
# Wait for the container to write it's CID file
279+
wait_for_cid
260280

261281
test_pid_1 "${cid_file}"
262282
check_result $?
283+
}
284+
285+
test_web_application() {
286+
local app="$1"
287+
info "Starting web application tests for '${app}'"
288+
prepare ${app}
289+
run_s2i_build ${app}
290+
check_result $?
291+
292+
image="${IMAGE_NAME}-testapp"
263293

264-
cleanup_app
294+
##
295+
# test the image
296+
##
297+
info "Starting build image tests"
298+
local cid_file=$(mktemp -u --suffix=.cid)
299+
init_web_app "${image}" "${cid_file}"
300+
# test application with default user
301+
test_web_app_scl "${image}" "${cid_file}"
302+
test_web_app_http
303+
304+
# test application with random user
305+
CONTAINER_ARGS="-u 12345" test_web_app_scl "${image}" "${cid_file}"
306+
CONTAINER_ARGS="-u 12345" test_web_app_http
307+
cleanup_container "${cid_file}"
308+
309+
info "All web application tests for '${app}' finished successfully."
310+
cleanup ${app}
265311
}
266312

267313
test_openshift_sample_app() {
314+
local image="$1"
268315
local cid_file=$(mktemp -u --suffix=.cid)
269316
# Verify that the HTTP connection can be established to test application container
270-
run_test_application &
317+
run_test_application "${image}" "${cid_file}" &
271318

272319
# Wait for the container to write it's CID file
273320
wait_for_cid
274321

275-
test_scl_usage "dotnet --version" "${dotnet_version}" "${cid_file}"
322+
test_scl_usage "dotnet --version" "${dotnet_version}" "${cid_file}" "${image}"
276323
check_result $?
277324

278325
test_http "/" "Sample pages using ASP.NET Core MVC" "grep \"ASP.NET Core MVC\" | sed -e 's#<li>##g' -e 's#</li>##g' -e 's#^ \\+##g'"
279326
check_result $?
280327

281-
cleanup_app
328+
cleanup_container "${cid_file}"
282329
}
283330

284331
echo_details() {
@@ -393,22 +440,21 @@ success_cli() {
393440

394441
test_cli_app() {
395442
local app="$1"
396-
info "Testing CLI app: ${app} ..."
443+
info "Testing CLI app against build image: ${app} ..."
397444
prepare ${app}
398445
run_s2i_build ${app}
399446
check_result $?
400447

401448
local expected="$( get_expected_cli ${app} )"
402-
local actual_pre="$( run_cli_test_application )"
449+
local actual_pre="$( run_cli_test_application ${IMAGE_NAME}-testapp)"
403450
local actual="$( filter_cli "${app}" "${actual_pre}" )"
404451
if ! success_cli "${app}" "${actual}" "${expected}"; then
405452
info "Test CLI app: ${app} FAILED."
406453
echo_details "${expected}" "${actual}"
407454
cleanup ${app}
408455
exit 1
409-
else
410-
info "Test CLI app: ${app} PASSED."
411456
fi
457+
info "Test CLI app (build image): ${app} PASSED."
412458
cleanup ${app}
413459
}
414460

@@ -419,7 +465,7 @@ test_new_web_app() {
419465
check_result $?
420466

421467
local cid_file=$(mktemp -u --suffix=.cid)
422-
run_test_application &
468+
run_test_application "${IMAGE_NAME}-testapp" "${cid_file}" &
423469
wait_for_cid
424470

425471
# installed via DOTNET_NPM_TOOLS
@@ -429,7 +475,7 @@ test_new_web_app() {
429475
test_http "/js/site.min.js"
430476
check_result $?
431477

432-
cleanup_app
478+
cleanup_container "${cid_file}"
433479
info "All tests for the ${app} finished successfully."
434480
cleanup ${app}
435481
}
@@ -456,10 +502,10 @@ if [ ${OPENSHIFT_ONLY} = true ]; then
456502
check_result $?
457503

458504
# test application with default user
459-
test_openshift_sample_app
505+
test_openshift_sample_app "${IMAGE_NAME}-testapp"
460506

461507
# test application with random user
462-
CONTAINER_ARGS="-u 12345" test_openshift_sample_app
508+
CONTAINER_ARGS="-u 12345" test_openshift_sample_app "${IMAGE_NAME}-testapp"
463509

464510
info "All tests for the ${sample_app_url} finished successfully."
465511
cleanup "ignore-me"
@@ -471,18 +517,7 @@ else
471517
done
472518

473519
for app in ${WEB_APPS[@]}; do
474-
prepare ${app}
475-
run_s2i_build ${app}
476-
check_result $?
477-
478-
# test application with default user
479-
test_web_application
480-
481-
# test application with random user
482-
CONTAINER_ARGS="-u 12345" test_web_application
483-
484-
info "All tests for the ${app} finished successfully."
485-
cleanup ${app}
520+
test_web_application "${app}"
486521
done
487522

488523
test_new_web_app

2.0/runtime/Dockerfile.rhel7

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
FROM rhel7
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+
14+
LABEL io.k8s.description="Platform for running .NET Core 2.0 applications" \
15+
io.k8s.display-name=".NET Core 2.0" \
16+
io.openshift.tags="runtime,.net,dotnet,dotnetcore,rh-dotnet20-runtime" \
17+
io.openshift.expose-services="8080:http"
18+
19+
# Labels consumed by Red Hat build service
20+
LABEL name="dotnet/dotnet-20-rhel7-runtime" \
21+
com.redhat.component="rh-dotnet20-runtime-docker" \
22+
version="2.0" \
23+
release="1" \
24+
architecture="x86_64"
25+
26+
# Don't download/extract docs for nuget packages
27+
ENV NUGET_XMLDOC_MODE=skip
28+
29+
# Don't do initially populate of package cache
30+
ENV DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
31+
32+
## By default, ASP.NET Core runs on port 5000. We configure it to match
33+
## the container port.
34+
ENV ASPNETCORE_URLS=http://*:8080
35+
36+
RUN yum install -y --setopt=tsflags=nodocs nss_wrapper tar && \
37+
yum clean all
38+
39+
# TODO: remove upstream sdk
40+
# install upstream 2.0 sdk
41+
RUN yum install --disablerepo=\* --enablerepo=rhel-7-server-rpms -y libunwind libicu && \
42+
yum clean all && \
43+
curl https://download.microsoft.com/download/0/6/5/0656B047-5F2F-4281-A851-F30776F8616D/dotnet-dev-linux-x64.2.0.0-preview1-005977.tar.gz -o /tmp/dotnet-sdk.tar.gz && \
44+
mkdir -p /opt/dotnet && \
45+
tar xf /tmp/dotnet-sdk.tar.gz -C /opt/dotnet && \
46+
ln -s /opt/dotnet/dotnet /usr/bin/dotnet; \
47+
rm /tmp/dotnet-sdk.tar.gz; \
48+
rm -rf /opt/dotnet/sdk

0 commit comments

Comments
 (0)