Skip to content

Commit

Permalink
fix: test env files with containers in cicd
Browse files Browse the repository at this point in the history
Signed-off-by: Mirko Mollik <mirkomollik@gmail.com>
  • Loading branch information
cre8 committed Sep 1, 2024
1 parent 79073ea commit b098d10
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 6 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
- name: Add entry to /etc/hosts
run: echo "127.0.0.1 host.testcontainers.internal" | sudo tee -a /etc/hosts

- name: Lint, test, build, e2e
- name: Lint, test, container, e2e
run: INPUT_GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} pnpm exec nx affected -t lint test container e2e
# comment out since the current e2e tests do not produce any artifacts
# - name: Upload coverage
Expand Down Expand Up @@ -76,6 +76,12 @@ jobs:
path: tmp/logs
retention-days: 30

# validate if the .env.example files in the deploys folder are up to date and that the containers can be health checked and started
- name: Validate deploy environment
run:
cd deploys
./test.sh

- name: Check if testcontainer logs exist
id: check_testcontainer_logs
run: echo "exists=$(if [ -d tmp/logs ]; then echo true; else echo false; fi)" >> $GITHUB_ENV
4 changes: 4 additions & 0 deletions apps/demo/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
FROM docker.io/nginx:stable-alpine

# Install wget
RUN apk --no-cache add wget

COPY dist/apps/demo/* /usr/share/nginx/html/
RUN echo "server {" > /etc/nginx/conf.d/default.conf && \
echo " listen 80;" >> /etc/nginx/conf.d/default.conf && \
Expand Down
3 changes: 3 additions & 0 deletions apps/holder-app/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
FROM docker.io/nginx:stable-alpine

# Install wget
RUN apk --no-cache add wget

# Copy application files and the startup script with permissions
COPY dist/apps/holder-app/* /usr/share/nginx/html/
COPY --chmod=755 apps/holder-app/startup.sh /usr/local/bin/startup.sh
Expand Down
3 changes: 3 additions & 0 deletions apps/issuer-frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
FROM docker.io/nginx:stable-alpine

# Install wget
RUN apk --no-cache add wget

# Copy application files and the startup script with permissions
COPY dist/apps/issuer-frontend/* /usr/share/nginx/html/
COPY --chmod=755 apps/issuer-frontend/startup.sh /usr/local/bin/startup.sh
Expand Down
3 changes: 3 additions & 0 deletions apps/verifier-frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
FROM docker.io/nginx:stable-alpine

# Install wget
RUN apk --no-cache add wget

# Copy application files and the startup script with permissions
COPY dist/apps/verifier-frontend/* /usr/share/nginx/html/
COPY --chmod=755 apps/verifier-frontend/startup.sh /usr/local/bin/startup.sh
Expand Down
6 changes: 6 additions & 0 deletions deploys/demo/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ services:
- ./config/config.json:/usr/share/nginx/html/assets/config.json
ports:
- $PORT:80
healthcheck:
test: ['CMD', 'wget', '--spider', '-q', 'http://127.0.0.1/index.html']
interval: 10s
timeout: 10s
retries: 3
start_period: 5s

volumes:
verifier:
7 changes: 6 additions & 1 deletion deploys/holder/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ services:
- OIDC_PUBLIC_CLIENT_ID=${OIDC_PUBLIC_CLIENT_ID}
- OIDC_ADMIN_CLIENT_ID=${OIDC_ADMIN_CLIENT_ID}
- OIDC_ADMIN_CLIENT_SECRET=${OIDC_ADMIN_CLIENT_SECRET}
- OIDC_PUBLIC_CLIENT_ID=${OIDC_PUBLIC_CLIENT_ID}
- DB_HOST=${DB_HOST}
- DB_PORT=${DB_PORT}
- DB_USERNAME=${DB_USERNAME}
Expand All @@ -53,6 +52,12 @@ services:
- OIDC_ALLOW_HTTP=${OIDC_ALLOW_HTTP}
ports:
- $FRONTEND_PORT:80
healthcheck:
test: ['CMD', 'wget', '--spider', '-q', 'http://127.0.0.1/index.html']
interval: 10s
timeout: 10s
retries: 3
start_period: 5s

volumes:
db:
Expand Down
6 changes: 6 additions & 0 deletions deploys/issuer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ services:
- OIDC_CLIENT_SECRET=$FRONTEND_OIDC_CLIENT_SECRET
ports:
- $FRONTEND_PORT:80
healthcheck:
test: ['CMD', 'wget', '--spider', '-q', 'http://127.0.0.1/index.html']
interval: 10s
timeout: 10s
retries: 3
start_period: 5s

db:
restart: unless-stopped
Expand Down
12 changes: 8 additions & 4 deletions deploys/keycloak/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
healthcheck:
test:
['CMD', 'pg_isready', '-q', '-d', 'postgres', '-U', '$KC_POSTGRES_USER']
timeout: 45s
timeout: 10s
interval: 10s
retries: 10
volumes:
Expand Down Expand Up @@ -53,11 +53,15 @@ services:
networks:
- keycloak-net
healthcheck:
test: ['CMD', 'curl', '-f', 'http://localhost:8080/health']
interval: 30s
test:
[
'CMD-SHELL',
"exec 3<>/dev/tcp/127.0.0.1/8080;echo -e \"GET /health/ready HTTP/1.1\r\nhost: http://localhost\r\nConnection: close\r\n\r\n\" >&3;grep \"HTTP/1.1 200 OK\" <&3",
]
interval: 10s
timeout: 10s
retries: 3
start_period: 2m
start_period: 10s

networks:
keycloak-net:
Expand Down
41 changes: 41 additions & 0 deletions deploys/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash
# this script is used to test the .env.example files and if the containers can start healthy with the provided configuration. It does not execute tests.
folders=("keycloak" "holder" "issuer" "verifier")

for folder in "${folders[@]}"; do
echo "Processing folder: $folder"
cd $folder
cp .env.example .env
docker compose up -d
echo "Waiting for containers to be healthy in $folder..."

check_health() {
containers=$(docker compose ps -q)
for container in $containers; do
health_status=$(docker inspect --format='{{.State.Health.Status}}' $container 2>/dev/null || echo "unhealthy")
if [ "$health_status" != "healthy" ]; then
return 1
fi
done
return 0
}

for i in {1..4}; do
if check_health; then
echo "All containers in $folder are healthy."
docker compose down
break
fi
echo "Waiting for containers to be healthy in $folder... ($i/3)"
sleep 5
done

if ! check_health; then
echo "Containers in $folder did not become healthy in time."
exit 1
fi

cd ..
done

echo "All containers in all folders are healthy."
6 changes: 6 additions & 0 deletions deploys/verifier/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ services:
- OIDC_CLIENT_SECRET=$FRONTEND_OIDC_CLIENT_SECRET
ports:
- $FRONTEND_PORT:80
healthcheck:
test: ['CMD', 'wget', '--spider', '-q', 'http://127.0.0.1/index.html']
interval: 10s
timeout: 10s
retries: 3
start_period: 5s

db:
restart: unless-stopped
Expand Down
4 changes: 4 additions & 0 deletions docs/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
FROM docker.io/nginx:stable-alpine

# Install wget
RUN apk --no-cache add wget

COPY site/ /usr/share/nginx/html/
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

0 comments on commit b098d10

Please sign in to comment.