Skip to content

Commit

Permalink
Added a customer Docker image, fixes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
tqvarnst committed Apr 3, 2019
1 parent 44f7e5c commit c2c5c3c
Show file tree
Hide file tree
Showing 6 changed files with 204 additions and 7 deletions.
14 changes: 7 additions & 7 deletions apb/playbooks/provision.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,14 @@
install_custom_stacks_json: |
[{
"name": "Quarkus Development",
"description": "Java JDK Stack on CentOS for https://Quarkus.io Workshop",
"description": "Java JDK Stack on CentOS for quarkus.io Workshop",
"scope": "general",
"workspaceConfig": {
"environments": {
"default": {
"recipe": {
"type": "dockerimage",
"content": "siamaksade/che-centos-jdk8"
"content": "quay.io/tqvarnst/che-quarkus:0.12.0"
},
"machines": {
"dev-machine": {
Expand Down Expand Up @@ -227,16 +227,16 @@
},
"commands": [
{
"commandLine": "mvn compile quarkus:dev -f ${current.project.path}",
"commandLine": "/opt/apache-maven-3.6.0/bin/mvn -f ${current.project.path}/pom.xml compile quarkus:dev",
"name": "Run in dev mode",
"type": "mvn",
"attributes": {
"goal": "Run",
"previewUrl": ""
"previewUrl": "${server.8080/tcp}/hello/greeting/Quarkus"
}
},
{
"commandLine": "mvn clean package -f ${current.project.path}",
"commandLine": "/opt/apache-maven-3.6.0/bin/mvn -f ${current.project.path}/pom.xml",
"name": "clean build",
"type": "mvn",
"attributes": {
Expand All @@ -245,7 +245,7 @@
}
},
{
"commandLine": "mvn verify -f ${current.project.path}",
"commandLine": "/opt/apache-maven-3.6.0/bin/mvn verify -f ${current.project.path}/pom.xml",
"name": "test",
"type": "mvn",
"attributes": {
Expand Down Expand Up @@ -286,6 +286,6 @@
"CentOS",
"Git"
],
"id": "java-oc-centos-quarkus"
"id": "che-quarkus"
}]
tags: eclipse-che
40 changes: 40 additions & 0 deletions che-stack/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
FROM registry.centos.org/che-stacks/centos-jdk8

LABEL che:server:8080:ref=quarkus-dev che:server:8080:protocol=http che:server:5005:ref=quarkus-debug che:server:5005:protocol=http che:server:9876:ref=codeserver che:server:9876:protocol=http

ARG OC_VERSION=3.11.43
ARG QUARKUS_VERSION=0.12.0

COPY ["./general-deps.install", "/tmp/install/"]
RUN sudo chown user:user /tmp/install /tmp/install/* && \
/tmp/install/general-deps.install ${OC_VERSION} && \
sudo rm -rf /tmp/install


# The following lines are needed to set the correct locale after `yum update`
# c.f. https://github.com/CentOS/sig-cloud-instance-images/issues/71
RUN sudo localedef -i en_US -f UTF-8 C.UTF-8
ENV LANG="C.UTF-8"

# Generate group.template
RUN cat /etc/group | \
sed s#root:x:0:#root:x:0:0,\${USER_ID}:#g \
> /home/user/group.template

ENV HOME /home/user
ENV M2_HOME=/opt/apache-maven-3.6.0

COPY ["./download-maven-deps.sh", "/tmp/maven-deps/"]
RUN sudo chown user:user /tmp/maven-deps /tmp/maven-deps/* && \
/tmp/maven-deps/download-maven-deps.sh ${QUARKUS_VERSION} && \
sudo rm -rf /tmp/maven-deps

COPY ["./entrypoint.sh", "/home/user/entrypoint.sh"]
ENTRYPOINT ["/home/user/entrypoint.sh"]
CMD tail -f /dev/null

# Give write access to /home/user for users with an arbitrary UID
COPY ["./grant-access-arbitrary-UID.sh", "/tmp/install/"]
RUN sudo chown user:user /tmp/install /tmp/install/* && \
/tmp/install/grant-access-arbitrary-UID.sh && \
sudo rm -rf /tmp/install
44 changes: 44 additions & 0 deletions che-stack/download-maven-deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash
# Copyright (c) 2018 Red Hat, Inc.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
#

set -e
set -u

SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd)

##
# Clone and run `mvn clean package` on a repository, removing all
# downloaded files after completion. Used to download dependencies
# to the local maven repository.
#
# params:
# ${1} - Repository to download
# ${2} - branch/tag to check out
##
git_clone_and_build() {
BRANCH=${1}
cd "${HOME}"
CURRENT_FOLDER=$(pwd)
mkdir -p tmp-folder
wget -qO tmp.zip "https://github.com/quarkusio/quarkus-quickstarts/archive/${BRANCH}.zip"
unzip tmp.zip -d tmp-folder
pushd tmp-folder/quarkus-quickstarts-${BRANCH}
./mvnw -f getting-started/pom.xml quarkus:list-extensions
for qs in $(ls */pom.xml | sed "s/\/pom.xml//g" | grep -v hibernate-orm)
do
./mvnw -B -f ${qs}/pom.xml package
done
#cd tmp-folder/quarkus-quickstarts-${BRANCH} && ./mvnw -f getting-started/pom.xml quarkus:list-extensions && ./mvnw verify -f getting-started/pom.xml && ./mvnw -B clean package -DskipTests
popd
rm -rf tmp-folder
}

QUARKUS_VERSION=${1}
echo "Downloading quickstart for Quarkus version: $QUARKUS_VERSION"
git_clone_and_build $QUARKUS_VERSION
47 changes: 47 additions & 0 deletions che-stack/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash
# Copyright (c) 2012-2017 Red Hat, Inc.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
# Contributors:
# Red Hat, Inc. - initial implementation

set -e

export USER_ID=$(id -u)
export GROUP_ID=$(id -g)

if ! grep -Fq "${USER_ID}" /etc/passwd; then
envsubst < ${HOME}/passwd.template > /etc/passwd
envsubst < ${HOME}/group.template > /etc/group

# The trick below is the one that is suggested here
# https://docs.openshift.com/enterprise/3.2/creating_images/guidelines.html#openshift-enterprise-specific-guidelines
# But every new exec call won't work because
# LD_PRELOAD, NSS_WRAPPER_PASSWD and NSS_WRAPPER_GROUP
# are not set there.
#
# envsubst < ${HOME}/passwd.template > /tmp/passwd
# envsubst < ${HOME}/group.template > /tmp/group
# export LD_PRELOAD=/usr/local/lib/libnss_wrapper.so
# export NSS_WRAPPER_PASSWD=/tmp/passwd
# export NSS_WRAPPER_GROUP=/tmp/group
touch ${HOME}/is_arbitrary_user
fi

# SSH agent is currently not supported but if we
# do want to support it we can uncomment the code below
# and fix SSHAgentLauncher that has SSHD port hardcoded
# to 22 and will expect the service to be available at that
# port. And we cannot use port 22 because it's a
# privileged port and OpenShift will complain.
#
# SSHD_PORT=2222
# /usr/bin/ssh-keygen -A
# mkdir -p /home/user/.ssh
# chmod 700 /home/user/.ssh
# echo "UsePrivilegeSeparation no" > /home/user/.ssh/sshd_config
# /usr/sbin/sshd -D -p ${SSHD_PORT} -f /home/user/.ssh/sshd_config &

exec "$@"
39 changes: 39 additions & 0 deletions che-stack/general-deps.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash
# Copyright (c) 2012-2017 Red Hat, Inc.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
# Contributors:
# Red Hat, Inc. - initial implementation
#
# Install general dependencies required by all images. Note that
# yum will skip already installed dependencies, and so will not
# increase image size unnecesssarily.
#
# usage:
# general-deps.install <OC_VERSION> [<JAVA_VERSION>]
# note: JAVA_VERSION defaults to 1.8.0
#####

set -u
set -e

OC_VERSION=${1}
JAVA_VERSION=${2:-1.8.0}

sudo yum update -y -d 1 \
&& sudo yum install -y -d 1 \
bzip2 \
curl \
gettext \
git \
java-${JAVA_VERSION}-openjdk-devel \
tar \
wget \
&& sudo wget -qO- "https://mirror.openshift.com/pub/openshift-v3/clients/${OC_VERSION}/linux/oc.tar.gz" \
| sudo tar xvz -C /usr/local/bin \
&& sudo wget -qO- "http://mirrors.ibiblio.org/apache/maven/maven-3/3.6.0/binaries/apache-maven-3.6.0-bin.tar.gz" \
| sudo tar xvz -C /opt \
&& sudo yum clean all \
&& sudo rm -rf /var/cache/yum
27 changes: 27 additions & 0 deletions che-stack/grant-access-arbitrary-UID.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash
# Copyright (c) 2012-2017 Red Hat, Inc.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
# Contributors:
# Red Hat, Inc. - initial implementation
#
# Change owner and group of /home/user, /etc/passwd, /etc/group/
# /projects and /tmp directories, to allow users with arbitrary UIDs.
#####

set -u
set -e

sudo chgrp -R 0 /home/user \
&& sudo chmod -R g+rwX /home/user \
&& sudo chgrp -R 0 /etc/passwd \
&& sudo chmod -R g+rwX /etc/passwd \
&& sudo chgrp -R 0 /etc/group \
&& sudo chmod -R g+rwX /etc/group \
&& sudo mkdir -p /projects \
&& sudo chgrp -R 0 /projects \
&& sudo chmod -R g+rwX /projects \
&& sudo chgrp -R 0 /tmp \
&& sudo chmod -R g+rwX /tmp

0 comments on commit c2c5c3c

Please sign in to comment.