This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 and build image | |
run: | | |
./build.sh | |
# Download joda-time jar | |
cd ./install/docker/cws-image | |
curl -O https://repo1.maven.org/maven2/joda-time/joda-time/2.1/joda-time-2.1.jar | |
cp ../../../dist/cws_server.tar.gz . | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v4 | |
id: docker_build | |
with: | |
context: ./install/docker/cws-image | |
file: ./install/docker/cws-image/Dockerfile-ci | |
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: | | |
# Export image tag as environment variable for docker-compose | |
IMAGE_TAG="${{ needs.build.outputs.image_digest }}" | |
echo "CWS_IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_ENV | |
- name: Start containers with Docker Compose | |
run: | | |
docker network create cws-network | |
cd install/docker/console-db-es-ls-kibana | |
docker compose -f docker-compose-ci.yml up -d | |
sleep 60 | |
docker ps -a | |
echo "Testing CWS console access..." | |
sleep 120 | |
curl -k -s -I https://localhost:38443/cws-ui/login || echo "Console UI not accessible" | |
docker ps -a | |
docker exec cws-console bash -c "cd /home/cws_user && mvn -Dmaven.compiler.debug=true -Dmaven.compiler.debuglevel=lines,vars,source clean test jacoco:report-aggregate" | |
echo "Tests completed" | |
# - name: Run tests in CWS container | |
# run: | | |
# docker ps -a | |
# docker exec cws-console bash -c "cd /home/cws_user && mvn -Dmaven.compiler.debug=true -Dmaven.compiler.debuglevel=lines,vars,source clean test jacoco:report-aggregate" | |
# echo "Tests completed" | |
- name: Clean up | |
if: always() | |
run: | | |
# Stop and remove all containers | |
docker compose -f docker-compose-ci.yml down -v | |
docker stop cws-test || true | |
docker rm cws-test || true | |
# Docker Compose will clean up its own networks |