Skip to content

Workflow file for this run

name: Build and Push Docker Image
on:
push:
branches: [ develop, main, docker ]
pull_request:
branches: [ develop ]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
outputs:
image_digest: ${{ steps.image_digest.outputs.IMAGE_DIGEST }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository }}/cws
tags: |
type=ref,event=branch
type=ref,event=pr
type=sha,format=short
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'develop') }}
- name: Prepare Docker build context
run: |
cd ./install/docker/cws-image
# Download joda-time jar
curl -O https://repo1.maven.org/maven2/joda-time/joda-time/2.1/joda-time-2.1.jar
# Create a minimal cws_server.tar.gz
mkdir -p cws/server/apache-tomcat-9.0.75/logs
echo "placeholder" > cws/server/apache-tomcat-9.0.75/logs/placeholder.txt
mkdir -p cws/bin
echo "#!/bin/bash" > cws/configure.sh
echo "echo 'Mock configure script'" >> cws/configure.sh
echo "mkdir -p server/apache-tomcat-9.0.75/logs" >> cws/configure.sh
chmod +x cws/configure.sh
echo "#!/bin/bash" > cws/start_cws.sh
echo "echo 'Mock start script'" >> cws/start_cws.sh
echo "tail -f /dev/null" >> cws/start_cws.sh
chmod +x cws/start_cws.sh
tar -czf cws_server.tar.gz cws
rm -rf cws
# Make scripts executable
chmod +x wait_for_db_es_console.sh startup.sh
- name: Build and push Docker image
uses: docker/build-push-action@v4
id: docker_build
with:
context: ./install/docker/cws-image
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Get primary image tag
id: image_digest
run: |
PRIMARY_TAG=$(echo "${{ steps.meta.outputs.tags }}" | head -n 1)
echo "IMAGE_DIGEST=${PRIMARY_TAG}" >> $GITHUB_OUTPUT
test:
needs: build
runs-on: ubuntu-latest
if: github.event_name != 'pull_request'
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up test environment
run: |
mkdir -p test-output
- name: Pull Docker image
run: |
IMAGE_TAG="${{ needs.build.outputs.image_digest }}"
echo "Using image: ${IMAGE_TAG}"
docker pull ${IMAGE_TAG}
- name: Set up Docker Compose environment
run: |
# Create a docker network
docker network create cws-network
# Copy the docker-compose file
cp install/docker/console-db-es-ls-kibana/docker-compose.yml docker-compose.test.yml
# Copy config files from the repository
cp .github/ci-console-config.properties config.properties
cp .github/ci-worker-config.properties worker-config.properties
# Create creds directory if it doesn't exist
mkdir -p ~/.cws/creds
# Edit the docker-compose.test.yml to use the built image
IMAGE_TAG="${{ needs.build.outputs.image_digest }}"
sed -i "s|nasa-ammos/common-workflow-service:2.6.0|${IMAGE_TAG}|g" docker-compose.test.yml
- name: Start containers with Docker Compose
run: |
# Start services
docker compose -f docker-compose.test.yml up -d db es ldapsearch
# Wait for DB to be ready
echo "Waiting for database to be ready..."
timeout 60s bash -c 'until docker exec cws-db mysql -u root -ptest -e "SELECT 1;" >/dev/null 2>&1; do sleep 2; echo "Still waiting for database..."; done'
# Wait for ElasticSearch to be ready
echo "Waiting for Elasticsearch to be ready..."
timeout 90s bash -c 'until curl -s http://localhost:9200/_cluster/health | grep -q "status.*[green|yellow]"; do sleep 3; echo "Still waiting for ES..."; done'
# Start CWS console
docker compose -f docker-compose.test.yml up -d cws
# Wait for console to be ready
echo "Waiting for CWS console to be ready..."
timeout 120s bash -c 'until curl -k -s https://localhost:38443/cws-ui/login > /dev/null; do sleep 5; echo "Still waiting for console..."; done'
# Start worker
docker compose -f docker-compose.test.yml up -d cws-worker
- name: Create test container
run: |
IMAGE_TAG="${{ needs.build.outputs.image_digest }}"
# Create a test container that's connected to the same network
docker run --name cws-test -d \
--network cws-network \
-e JAVA_HOME=/usr/lib/jvm/java-openjdk \
-v ${PWD}:/workspace \
-w /workspace \
--entrypoint /bin/bash \
${IMAGE_TAG} -c "tail -f /dev/null"
# Verify Java setup in the container
docker exec cws-test java -version
# Install Maven
docker exec cws-test yum install -y maven
- name: Run tests in test container
run: |
# Copy test configuration file with real service endpoints
cp .github/ci-test-config.properties cws-test/src/test/resources/configuration.properties
# Run unit tests
docker exec -w /workspace cws-test bash -c "export JAVA_HOME=/usr/lib/jvm/java-17-openjdk && export PATH=\$JAVA_HOME/bin:\$PATH && mvn -Dmaven.compiler.release=17 -Dmaven.compiler.source=17 -Dmaven.compiler.target=17 clean test jacoco:report-aggregate"
# Run integration tests (without skipping!)
docker exec -w /workspace cws-test bash -c "export JAVA_HOME=/usr/lib/jvm/java-17-openjdk && export PATH=\$JAVA_HOME/bin:\$PATH && mvn -Dmaven.compiler.release=17 -Dmaven.compiler.source=17 -Dmaven.compiler.target=17 integration-test verify"
# Show summary of test results
docker exec -w /workspace cws-test bash -c "find . -name 'surefire-reports' -type d | xargs -I{} cat {}/*.txt 2>/dev/null || echo 'No test reports found'" || true
docker exec -w /workspace cws-test bash -c "find . -name 'failsafe-reports' -type d | xargs -I{} cat {}/*.txt 2>/dev/null || echo 'No test reports found'" || true
- name: Clean up
if: always()
run: |
# Stop and remove all containers
docker compose -f docker-compose.test.yml down -v
docker stop cws-test || true
docker rm cws-test || true
docker network rm cws-network || true