Skip to content

Commit f409f19

Browse files
committed
Adds Docker image build and basic health check using docker-compose
1 parent ff8e7d7 commit f409f19

8 files changed

Lines changed: 376 additions & 9 deletions

File tree

.github/workflows/docker.yml

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
name: Docker Build
2+
3+
on:
4+
push:
5+
branches: [main, develop, docker_build] # Adjust branches as needed
6+
pull_request:
7+
branches: [main] # Adjust branches as needed
8+
9+
permissions:
10+
contents: read
11+
packages: write # Needed to push images to GHCR
12+
13+
jobs:
14+
build-push-run:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
20+
- name: Set up Docker Buildx
21+
uses: docker/setup-buildx-action@v3
22+
23+
- name: Log in to GitHub Container Registry
24+
uses: docker/login-action@v3
25+
with:
26+
registry: ghcr.io
27+
username: ${{ github.actor }}
28+
password: ${{ secrets.GITHUB_TOKEN }}
29+
30+
- name: Extract CWS Version and Define Image Tag
31+
id: image_info
32+
run: |
33+
# Assuming utils.sh is at the repository root
34+
CWS_VER=$(grep 'export CWS_VER=' utils.sh | cut -d"'" -f2)
35+
# Use GitHub owner and repo name for GHCR image path (lowercase)
36+
OWNER_LOWER=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
37+
REPO_LOWER=$(echo "${{ github.event.repository.name }}" | tr '[:upper:]' '[:lower:]')
38+
IMAGE_NAME="ghcr.io/$OWNER_LOWER/$REPO_LOWER"
39+
echo "version=$CWS_VER" >> $GITHUB_OUTPUT
40+
echo "original_tag=nasa-ammos/common-workflow-service:$CWS_VER" >> $GITHUB_OUTPUT
41+
echo "ghcr_tag=$IMAGE_NAME:$CWS_VER" >> $GITHUB_OUTPUT
42+
working-directory: ${{ github.workspace }} # Run from repo root
43+
44+
- name: Build CWS Docker Image using script
45+
run: |
46+
chmod +x build-testing.sh
47+
# The script builds using the 'nasa-ammos/...' tag internally
48+
# Execute the script directly now that we are in its directory
49+
./build-testing.sh
50+
# Explicitly check the exit code of the script
51+
if [ $? -ne 0 ]; then
52+
echo "::error::Docker image build script failed."
53+
exit 1
54+
fi
55+
working-directory: install/docker/cws-image # Run from the script's directory
56+
57+
- name: Re-tag image for GHCR
58+
run: |
59+
echo "Tagging ${{ steps.image_info.outputs.original_tag }} as ${{ steps.image_info.outputs.ghcr_tag }}"
60+
docker tag "${{ steps.image_info.outputs.original_tag }}" "${{ steps.image_info.outputs.ghcr_tag }}"
61+
62+
- name: Push Docker image to GHCR
63+
run: |
64+
echo "Pushing ${{ steps.image_info.outputs.ghcr_tag }}"
65+
docker push "${{ steps.image_info.outputs.ghcr_tag }}"
66+
67+
- name: Prepare Docker Compose Environment
68+
run: |
69+
# Create external network required by docker-compose
70+
docker network create cws-network
71+
echo "Docker network 'cws-network' created"
72+
working-directory: install/docker/console-db-es-ls-kibana
73+
74+
- name: Update image tag in docker-compose.yml
75+
run: |
76+
# Escape slashes in the image tag for sed
77+
ESCAPED_TAG=$(echo "${{ steps.image_info.outputs.ghcr_tag }}" | sed 's/\//\\\//g')
78+
echo "Updating image tag in docker-compose.yml to $ESCAPED_TAG"
79+
# Target both cws and cws-worker services
80+
sed -i "s/image: nasa-ammos\/common-workflow-service:.*/image: $ESCAPED_TAG/g" docker-compose.yml
81+
echo "docker-compose.yml after update:"
82+
cat docker-compose.yml
83+
working-directory: install/docker/console-db-es-ls-kibana
84+
85+
- name: Start Services with Docker Compose
86+
run: docker compose up -d
87+
working-directory: install/docker/console-db-es-ls-kibana
88+
89+
- name: Verify CWS Console Startup
90+
run: |
91+
echo "Waiting up to 1 minute for CWS console to become healthy..." # Updated comment
92+
MAX_WAIT=60 # 1 minute max wait # Updated value and comment
93+
INTERVAL=15 # Check every 15 seconds
94+
ELAPSED=0
95+
# Use the healthcheck URL from docker-compose.yml
96+
HEALTHCHECK_URL="https://localhost:38443/cws-ui/login"
97+
98+
while true; do
99+
# Use curl's exit code to check success (-k for self-signed cert, -f to fail on server errors, -s silent, -L follow redirects)
100+
if curl -kfsL --output /dev/null "$HEALTHCHECK_URL"; then
101+
echo "CWS console is up and responding at $HEALTHCHECK_URL!"
102+
echo "Current running containers:"
103+
docker ps
104+
exit 0
105+
fi
106+
107+
if [ $ELAPSED -ge $MAX_WAIT ]; then
108+
echo "CWS console did not become healthy within $MAX_WAIT seconds."
109+
echo "Current running containers:"
110+
docker ps
111+
echo "Docker Compose logs for cws service (cws-console):"
112+
docker compose logs cws
113+
exit 1
114+
fi
115+
116+
sleep $INTERVAL
117+
ELAPSED=$((ELAPSED + INTERVAL))
118+
echo "Still waiting for CWS console... ($ELAPSED/$MAX_WAIT seconds)"
119+
done
120+
working-directory: install/docker/console-db-es-ls-kibana # Ensure correct context for docker-compose logs
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#! /bin/bash
2+
3+
# This script creates certs required by CWS when run inside the container.
4+
5+
# Define target directories within the container
6+
# Ensure TOMCAT_VER matches the version used in the CWS distribution
7+
TOMCAT_VER="9.0.75"
8+
TOMCAT_BASE_DIR="/home/cws_user/cws/server/apache-tomcat-${TOMCAT_VER}"
9+
TOMCAT_CONF_DIR="${TOMCAT_BASE_DIR}/conf"
10+
TOMCAT_LIB_DIR="${TOMCAT_BASE_DIR}/lib"
11+
KEYSTORE_FILE="${TOMCAT_CONF_DIR}/.keystore"
12+
TRUSTSTORE_FILE="${TOMCAT_LIB_DIR}/cws_truststore.jks"
13+
CERT_FILE="/tmp/cws.crt" # Temporary location for the exported cert
14+
PASSWORD="changeit" # Must match the password expected by CWS/Tomcat
15+
16+
echo "Generating CWS certificates..."
17+
echo " Keystore target: ${KEYSTORE_FILE}"
18+
echo " Truststore target: ${TRUSTSTORE_FILE}"
19+
20+
# Ensure target directories exist
21+
mkdir -p "${TOMCAT_CONF_DIR}"
22+
mkdir -p "${TOMCAT_LIB_DIR}"
23+
24+
# Create private key and self-signed certificate within the keystore at the target location
25+
keytool -genkey -keyalg RSA \
26+
-dname "cn=cws-container, ou=CWS, o=NASA, l=Pasadena, s=CA, c=US" \
27+
-alias cws \
28+
-keypass "${PASSWORD}" \
29+
-keystore "${KEYSTORE_FILE}" \
30+
-storepass "${PASSWORD}" \
31+
-storetype JKS \
32+
-validity 3650 \
33+
-keysize 2048
34+
if [ $? -ne 0 ]; then echo "ERROR: Failed to generate keystore."; exit 1; fi
35+
echo " Keystore generated."
36+
37+
# Extract self-signed certificate from keystore to a temporary file
38+
keytool -export -alias cws \
39+
-file "${CERT_FILE}" \
40+
-keystore "${KEYSTORE_FILE}" \
41+
-storepass "${PASSWORD}"
42+
if [ $? -ne 0 ]; then echo "ERROR: Failed to export certificate."; exit 1; fi
43+
echo " Certificate exported to ${CERT_FILE}."
44+
45+
# Import self-signed certificate into truststore at the target location
46+
keytool -import -alias cws \
47+
-file "${CERT_FILE}" \
48+
-keypass "${PASSWORD}" \
49+
-noprompt \
50+
-keystore "${TRUSTSTORE_FILE}" \
51+
-storepass "${PASSWORD}" \
52+
-storetype JKS
53+
if [ $? -ne 0 ]; then echo "ERROR: Failed to import certificate into truststore."; exit 1; fi
54+
echo " Certificate imported into truststore."
55+
56+
# Clean up temporary certificate file
57+
rm -f "${CERT_FILE}"
58+
echo " Temporary certificate file removed."
59+
60+
echo "Certificate generation complete."
61+
exit 0

install/docker/console-db-es-ls-kibana/docker-compose.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ services:
126126
timeout: 2s
127127
retries: 12
128128
volumes:
129-
- ./config.properties:/home/cws_user/config.properties:ro
130-
- ~/.cws/creds:/root/.cws/creds:ro
129+
- ./config.properties:/home/cws_user/config.properties:rw
130+
# - ~/.cws/creds:/root/.cws/creds:rw
131131
- console-logs-volume:/home/cws_user/cws/server/apache-tomcat-9.0.75/logs
132132
networks:
133133
- external-network
@@ -151,8 +151,8 @@ services:
151151
- ES_HOST=es
152152
- ES_PORT=9200
153153
volumes:
154-
- ./worker-config.properties:/home/cws_user/config.properties:ro
155-
- ~/.cws/creds:/root/.cws/creds:ro
154+
- ./worker-config.properties:/home/cws_user/config.properties:rw
155+
# - ~/.cws/creds:/root/.cws/creds:rw
156156
- worker1-logs-volume:/home/cws_user/cws/server/apache-tomcat-9.0.75/logs
157157
networks:
158158
- external-network

install/docker/cws-image/Dockerfile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM oraclelinux:8
22

33
RUN yum update -y && \
4-
yum install -y mysql java-17-openjdk java-17-openjdk-devel rsync which && \
4+
yum install -y mysql java-17-openjdk java-17-openjdk-devel rsync which wget tar gzip && \
55
yum clean all
66

77
ENV JAVA_HOME /usr/lib/jvm/java-openjdk
@@ -14,9 +14,16 @@ WORKDIR /home/cws_user
1414
ADD cws_server.tar.gz .
1515
ADD startup.sh .
1616
ADD wait_for_db_es_console.sh .
17+
ADD utils.sh /home/cws_user/utils.sh
1718

1819
# For time check
1920
ADD getTime.java .
2021
ADD joda-time-2.1.jar .
2122

23+
# Copy certificate generation scripts from the build context
24+
COPY cws-certs /opt/cws-certs
25+
26+
RUN chmod +x /opt/cws-certs/generate-certs.sh
27+
RUN curl -o /home/cws_user/cws/server/logstash-8.12.0.zip https://artifacts.elastic.co/downloads/logstash/logstash-8.12.0-windows-x86_64.zip
28+
2229
ENTRYPOINT [ "./wait_for_db_es_console.sh" ]
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
FROM oraclelinux:8
2+
3+
RUN yum update -y && \
4+
yum install -y mysql java-17-openjdk java-17-openjdk-devel rsync which wget tar gzip && \
5+
yum clean all
6+
7+
ENV JAVA_HOME /usr/lib/jvm/java-openjdk
8+
9+
# Install Maven
10+
ENV MAVEN_VERSION 3.9.6
11+
ENV MAVEN_HOME /usr/share/maven
12+
ENV MAVEN_CONFIG "/home/cws_user/.m2"
13+
14+
RUN mkdir -p /usr/share/maven && \
15+
wget https://dlcdn.apache.org/maven/maven-3/${MAVEN_VERSION}/binaries/apache-maven-${MAVEN_VERSION}-bin.tar.gz -P /tmp && \
16+
tar -xzf /tmp/apache-maven-${MAVEN_VERSION}-bin.tar.gz -C /usr/share/maven --strip-components=1 && \
17+
rm -f /tmp/apache-maven-${MAVEN_VERSION}-bin.tar.gz && \
18+
ln -s /usr/share/maven/bin/mvn /usr/bin/mvn
19+
20+
ENV PATH=${JAVA_HOME}/bin:${MAVEN_HOME}/bin:${PATH}
21+
22+
23+
ENV TZ=America/Los_Angeles
24+
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
25+
26+
WORKDIR /home/cws_user
27+
28+
ADD cws_server.tar.gz .
29+
ADD startup.sh .
30+
ADD wait_for_db_es_console_testing.sh .
31+
ADD utils.sh /home/cws_user/utils.sh
32+
33+
# For time check
34+
ADD getTime.java .
35+
ADD joda-time-2.1.jar .
36+
37+
# Copy certificate generation scripts from the build context
38+
COPY cws-certs /opt/cws-certs
39+
40+
# Ensure the specific script is executable
41+
RUN chmod +x /opt/cws-certs/generate-certs.sh
42+
RUN curl -o /home/cws_user/cws/server/logstash-8.12.0.zip https://artifacts.elastic.co/downloads/logstash/logstash-8.12.0-windows-x86_64.zip
43+
44+
ENTRYPOINT [ "./wait_for_db_es_console_testing.sh" ]
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env bash
2+
set -e # Exit immediately if a command exits with a non-zero status.
3+
4+
# Get version from utils.sh
5+
ROOT=$(pwd)
6+
cd ../../.. # Change to project root
7+
source utils.sh # Source utils.sh from project root
8+
ver=$CWS_VER # use version from utils.sh
9+
10+
# Rebuild cws tar-ball
11+
./build.sh # Execute build.sh from project root
12+
13+
cd $ROOT
14+
15+
CWS_PACKAGE=../../../dist/cws_server.tar.gz
16+
17+
if [ ! -f "$CWS_PACKAGE" ]; then
18+
echo "Error: Build package not found."
19+
echo "Need to build CWS package first: run './build.sh' in root dir to build cws_server.tar.gz."
20+
exit 1
21+
fi
22+
23+
cp "$CWS_PACKAGE" .
24+
cp ../../../cws-core/cws-core-libs/joda-time-2.1.jar .
25+
# Copy the certs directory from the project root into the build context
26+
cp -R ../../../cws-certs .
27+
# Copy utils.sh for setup_test_env.sh to use
28+
cp ../../../utils.sh .
29+
30+
echo "Building CWS docker image. Version = $ver"
31+
32+
docker build -t nasa-ammos/common-workflow-service:$ver -f Dockerfile-testing .
33+
34+
rm cws_server.tar.gz
35+
rm joda-time-2.1.jar
36+
# Remove the copied certs directory
37+
rm -rf cws-certs
38+
# Remove the copied utils.sh
39+
rm utils.sh
40+
41+
echo
42+
echo "Done building!"
43+
echo

install/docker/cws-image/build.sh

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
#!/usr/bin/env bash
2+
set -e # Exit immediately if a command exits with a non-zero status.
23

3-
ver='2.6.0' # update this each CWS release
4+
# Get version from utils.sh
5+
ROOT=$(pwd)
6+
cd ../../.. # Change to project root
7+
source utils.sh # Source utils.sh from project root
8+
ver=$CWS_VER # use version from utils.sh
49

510
# Rebuild cws tar-ball
6-
ROOT=$(pwd)
7-
cd ../../..
8-
./build.sh
11+
./build.sh # Execute build.sh from project root
912

1013
cd $ROOT
1114

@@ -19,13 +22,21 @@ fi
1922

2023
cp "$CWS_PACKAGE" .
2124
cp ../../../cws-core/cws-core-libs/joda-time-2.1.jar .
25+
# Copy the certs directory from the project root into the build context
26+
cp -R ../../../cws-certs .
27+
# Copy utils.sh for setup_test_env.sh to use
28+
cp ../../../utils.sh .
2229

2330
echo "Building CWS docker image. Version = $ver"
2431

2532
docker build -t nasa-ammos/common-workflow-service:$ver .
2633

2734
rm cws_server.tar.gz
2835
rm joda-time-2.1.jar
36+
# Remove the copied certs directory
37+
rm -rf cws-certs
38+
# Remove the copied utils.sh
39+
rm utils.sh
2940

3041
echo
3142
echo "Done building!"

0 commit comments

Comments
 (0)