Skip to content

Commit

Permalink
add missing docker images
Browse files Browse the repository at this point in the history
  • Loading branch information
yaskoo committed Nov 2, 2018
1 parent feb942f commit de2f1d3
Show file tree
Hide file tree
Showing 31 changed files with 460 additions and 36 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
target/
test-output/
build.log
docker/http-proxy/usr/local/bin/proxytpl
62 changes: 33 additions & 29 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,42 +83,15 @@ function build_docker_image() {
docker image build \
--rm --no-cache \
--tag $tag \
--quiet \
$ctx
}

version="$(mvn -q -N -f cs-deployment/pom.xml -Dexec.executable=echo -Dexec.args='${project.version}' exec:exec)"

echo "Building base wildfly docker image..."
docker image build \
--rm --no-cache --quiet \
--tag docker-reg.sirmaplatform.com/sep-base-wildfly:$version \
--file $script_dir/sirma-platform/platform/Dockerfile.base \
$script_dir/sirma-platform/platform

echo "Building Coservation Space wildfly docker image..."
docker image build \
--rm --no-cache --quiet \
--build-arg sep_base_image_version=$version \
--tag docker-reg.sirmaplatform.com/cs-wildfly:$version \
$script_dir/cs-deployment

echo "Building Alfresco docker image..."
docker image build \
--rm --no-cache --quiet \
--tag docker-reg.sirmaplatform.com/sep-alfresco:$version \
$script_dir/sirma-platform/alfresco

build_docker_image "docker-reg.sirmaplatform.com/nginx:2" "$script_dir/docker/nginx/2"

echo "Building UI docker image..."
docker image build \
--rm --no-cache --quiet \
--tag docker-reg.sirmaplatform.com/seip-ui:$version \
$script_dir/sirma-platform/ui2


build_docker_image "docker-reg.sirmaplatform.com/base:1" "$script_dir/docker/base/1"
build_docker_image "docker-reg.sirmaplatform.com/base:2" "$script_dir/docker/base/2"
build_docker_image "docker-reg.sirmaplatform.com/base:2.0.1" "$script_dir/docker/base/2.0.1"

build_docker_image "docker-reg.sirmaplatform.com/nginx:1.12.2-u2" "$script_dir/docker/nginx/1.12.2-u2"

Expand All @@ -137,6 +110,7 @@ build_docker_image "docker-reg.sirmaplatform.com/export:2.22.0-SNAPSHOT" "$scrip
build_docker_image "docker-reg.sirmaplatform.com/compare-pdf:2.22.0-SNAPSHOT" "$script_dir/docker/compare-pdf"

build_docker_image "docker-reg.sirmaplatform.com/openjdk-jre:7-base-1" "$script_dir/docker/openjdk-jre/7-base-1"
build_docker_image "docker-reg.sirmaplatform.com/openjdk-jre:8-1" "$script_dir/docker/openjdk-jre/8-1"
build_docker_image "docker-reg.sirmaplatform.com/wso2idp:5" "$script_dir/docker/wso2idp/5"
build_docker_image "docker-reg.sirmaplatform.com/sep-wso2is:2.22.0-SNAPSHOT" "$script_dir/docker/sep-wso2is"

Expand All @@ -162,3 +136,33 @@ go get github.com/imdario/mergo gopkg.in/yaml.v2
mkdir -p "$script_dir/docker/http-proxy/rootfs/usr/local/bin"
go build -o "$script_dir/docker/http-proxy/rootfs/usr/local/bin/proxytpl" "$script_dir/docker/http-proxy/proxytpl.go"
build_docker_image "docker-reg.sirmaplatform.com/http-proxy:2.22.0-SNAPSHOT" "$script_dir/docker/http-proxy"

build_docker_image "docker-reg.sirmaplatform.com/wildfly:9.0.2-u3" "$script_dir/docker/wildfly/9.0.2-u3"

echo "Building base wildfly docker image..."
docker image build \
--rm --no-cache --quiet \
--tag docker-reg.sirmaplatform.com/sep-base-wildfly:$version \
--file $script_dir/sirma-platform/platform/Dockerfile.base \
$script_dir/sirma-platform/platform

echo "Building Coservation Space wildfly docker image..."
docker image build \
--rm --no-cache --quiet \
--build-arg sep_base_image_version=$version \
--tag docker-reg.sirmaplatform.com/cs-wildfly:$version \
$script_dir/cs-deployment

echo "Building Alfresco docker image..."
docker image build \
--rm --no-cache --quiet \
--tag docker-reg.sirmaplatform.com/sep-alfresco:$version \
$script_dir/sirma-platform/alfresco

build_docker_image "docker-reg.sirmaplatform.com/nginx:2" "$script_dir/docker/nginx/2"

echo "Building UI docker image..."
docker image build \
--rm --no-cache --quiet \
--tag docker-reg.sirmaplatform.com/seip-ui:$version \
$script_dir/sirma-platform/ui2
16 changes: 16 additions & 0 deletions cs-deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,20 @@
<module>cs-semantic-patches</module>
<module>cs-eai</module>
</modules>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<!-- https://issues.apache.org/jira/browse/SUREFIRE-1588 -->
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
2 changes: 2 additions & 0 deletions docker/base/2.0.1/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tests/
README.md
19 changes: 19 additions & 0 deletions docker/base/2.0.1/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM alpine:3.6

ENV LANG=en_US.utf8 \
DOCKER_USER=dockeru \
DOCKER_USER_ID=1000 \
DOCKER_USER_GROUP_ID=1000

COPY rootfs/ /

RUN apk --no-cache add curl bash && \
apk --no-cache --repository http://dl-2.alpinelinux.org/alpine/edge/community add shadow && \
mkdir /opt /docker-init.d && \
addgroup -g $DOCKER_USER_GROUP_ID $DOCKER_USER && \
adduser $DOCKER_USER -u $DOCKER_USER_ID -S -G $DOCKER_USER -s /bin/bash && \
sed -i -e 's|/bin/sh|/bin/bash|' -e 's|/bin/ash|/bin/bash|' /etc/passwd && \
curl -o /usr/local/bin/gosu -fsSL "https://github.com/tianon/gosu/releases/download/1.9/gosu-amd64" && \
chmod +x /entrypoint.sh /usr/local/bin/gosu /usr/local/bin/*.sh

ENTRYPOINT ["/entrypoint.sh"]
38 changes: 38 additions & 0 deletions docker/base/2.0.1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Base image for all Sirma Enterprise Systems docker images

This image provides the main entry point for assigning user permissions and contains useful scripts.

Creates a dedicated user **dockeru** that will obtain ownership of all:
* volumes
* services
* scripts placed in /docker-init.d

## Useful scripts
### replace-env.sh - Replacing environment variables inside files

Example usage: `replace-env.sh file1.conf file2.xml`

When invoked, this script will be executed for every line in the provided files.

The script supports replacing environment variables only in the following format: `${VARIABLE}`
(In other words - uppercase variable in single curly brackets starting with a dollar sign.)

The script will preserve any non binded variables.

### wait-for-service.sh - Wait for specific service to become reachable

Example usage: `wait-for-service.sh -h localhost -p 5432 -t 5 -m 10`

Command summary
-h, --host - the service hostname
-p, --port - the service port
-t, --timeout - the timeout in seconds between tries
-m, --max-tries - the maximum tries to reach the service


This script uses netcat internally.

## Built in user
The container comes with a user called `dockeru` which is used to run the actual service.
The user's UID and GID are `1000` by default, but they can be changed by setting the `DOCKER_USER_ID` and `DOCKER_USER_GROUP_ID` environment variables.
__NOTE__: if you change the UID or GID - you must manually change ownership of any volues.
45 changes: 45 additions & 0 deletions docker/base/2.0.1/rootfs/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env bash

set -e

changeown() {
for dir in $1; do
# if the root dir has the correct ownership - assume alles gut
if [ "$(stat -c '%U:%G' $dir)" != "$DOCKER_USER:$DOCKER_USER" ]; then
echo "Changing ownership of $dir"
chown -R $DOCKER_USER:$DOCKER_USER $dir
fi
done
}

echo -e "\n################# env #################"
env
echo -e "#######################################\n"

usermod -u $DOCKER_USER_ID $DOCKER_USER
groupmod -g $DOCKER_USER_GROUP_ID $DOCKER_USER

# syncing here to workaround "resource busy" problems for mounted files
sync

echo "Setting ownership ($DOCKER_USER:$DOCKER_USER) on volume and service dirs"
changeown "$(env | grep -e ^SERVICE_DIR_ -e ^VOLUME_ | cut -d'=' -f2)"

echo "Running /docker-init.d scripts"
if [ -d /docker-init.d ]; then
for f in /docker-init.d/*.sh; do
[ -f "$f" ] && . "$f"
done
fi

sync

set +u

if [ -n "$RUN_AS_ROOT" ]; then
echo "Running $@ as root"
gosu root "$@"
else
echo "Running $@"
gosu $DOCKER_USER "$@"
fi
22 changes: 22 additions & 0 deletions docker/base/2.0.1/rootfs/usr/local/bin/replace-env-vars.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
string = $0;
start = index(string, "${");

while(start > 0) {
end = index(string, "}");
if(end > 0) {
variable = substr(string, start + 2, end - start - 2);
evaluated = ENVIRON[variable];
if(length(evaluated) > 0) {
toreplace = "[$]{"variable"}";
gsub(toreplace, evaluated, $0);
}
string = substr(string, end + 1);
start = index(string, "${");
} else {
string = substr(string, start + 2);
start = index(string, "${");
}
}
print $0
}
15 changes: 15 additions & 0 deletions docker/base/2.0.1/rootfs/usr/local/bin/replace-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

set -eu

script_dir="$( cd "$( dirname "$0" )" && pwd )"

for file in $@; do
if [ -s $file ]; then
awk -f "$script_dir/replace-env-vars.awk" "${file}" > "${file}.tmp";
sync
mv "${file}.tmp" "${file}"
else
echo "The specified file ${file} does NOT exist!";
fi
done
63 changes: 63 additions & 0 deletions docker/base/2.0.1/rootfs/usr/local/bin/wait-for-service.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env bash

set -eu

# TODO: Add completion ?
# TODO: Add blocking wait ?

# Defaults
: ${tries=1}
: ${timeout=2}
: ${max_tries=20}


# Reading command line arguments
while [ $# -gt 1 ]; do
case $1 in
-h|--host)
host="$2"
shift
;;
-p|--port)
port="$2"
shift
;;
-t|--timeout)
timeout="$2"
shift
;;
-m|--max_tries)
max_tries="$2"
shift
;;
*)
echo "Argument $1 is not supported";
;;
esac
shift
done

if [ -z ${host} ]; then
echo "Provide the service host!";
exit 1;
fi

if [ -z ${port} ]; then
echo "Provide the service port!";
exit 1;
fi

service="${host}:${port}"

echo "Going to wait for ${service} to be reachable...";
until $(nc -z -w 1 ${host} ${port} > /dev/null); do
echo "${service} is not visible yet... retrying every $timeout seconds... ($tries/$max_tries)";
sleep $timeout

if [ $tries -eq $max_tries ]; then
echo "ERROR: After [${tries}] retries ${service} couldn't be reached!";
exit 1
fi
tries=$((tries+1))
done
echo "${service} is successfully reached after [${tries}] tries";
1 change: 1 addition & 0 deletions docker/base/2.0.1/tests/goss.command
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sleep 3
9 changes: 9 additions & 0 deletions docker/base/2.0.1/tests/goss.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
user:
dockeru:
exists: true

package:
curl:
installed: true
bash:
installed: true
30 changes: 30 additions & 0 deletions docker/base/2.0.1/tests/replace-env.spec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bats

DIR=${BATS_TEST_DIRNAME}

function replace() {
awk -f ${DIR}/../rootfs/usr/local/bin/replace-env-vars.awk ${DIR}/$1 > ${DIR}/$2
}

@test "Replacing environment variables in an empty file" {
replace resources/1-empty 1-result
result=$(comm -23 ${DIR}/1-result ${DIR}/resources/1-empty | wc -l)
[ "$result" -eq 0 ]
}

@test "Replacing environment variables in a file without declared variables" {
replace resources/2-nothing-to-replace 2-result
result=$(comm -23 ${DIR}/2-result ${DIR}/resources/2-nothing-to-replace | wc -l)
[ "$result" -eq 0 ]
}

@test "Replacing environment variables in a file having some declared variables" {
export SOMETHING="SoMeThiNG"
export SECOND="SeconD"
export END="EnD"
export OR="Or"
export QUOTES="quoteees"
replace resources/3-proper 3-result
result=$(comm -23 ${DIR}/3-result ${DIR}/resources/3-proper-expected | wc -l)
[ "$result" -eq 0 ]
}
Empty file.
3 changes: 3 additions & 0 deletions docker/base/2.0.1/tests/resources/2-nothing-to-replace
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
this file has nothing for replacing
even on the second line
seriously, nothing
6 changes: 6 additions & 0 deletions docker/base/2.0.1/tests/resources/3-proper
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
this file has ${SOMETHING} for replacing
even on the ${SECOND} line in the ${END}
${OR} in the beginning of the third
indeed ${SOMETHING} is replaced multiple times
but having more ${{QUOTES}} does not work
or having ${something} in different case too
6 changes: 6 additions & 0 deletions docker/base/2.0.1/tests/resources/3-proper-expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
this file has SoMeThiNG for replacing
even on the SeconD line in the EnD
Or in the beginning of the third
indeed SoMeThiNG is replaced multiple times
but having more ${{QUOTES}} does not work
or having ${something} in different case too
Loading

0 comments on commit de2f1d3

Please sign in to comment.