Skip to content

Commit

Permalink
Merge pull request #73 from szymonpoltorak/DEV-79-DockerWorkflow
Browse files Browse the repository at this point in the history
Dev 79 docker workflow
  • Loading branch information
szymonpoltorak authored Mar 9, 2024
2 parents f8bda82 + 0c68341 commit 1755eeb
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 4 deletions.
70 changes: 70 additions & 0 deletions .github/workflows/checkDockerDev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Check dockercompose.dev

on:
push:
branches: [ "main", "devel" ]
pull_request:
branches: [ "main", "devel" ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Install jq
run: sudo apt-get install -y jq

- name: Setup useful functions
run: |
rc=/tmp/rcfile
echo "lscontainers() { docker ps -qa | xargs --no-run-if-empty docker inspect; }" >> $rc
echo "asserttrue() { [ \"\$(cat)\" = \"true\" ]; }" >> $rc
echo "checkstatus() { lscontainers | jq -r '.[] | select(.Name == \"/'\"\$1\"'\").State.Status == \"'\"\$2\"'\"'; }" >> $rc
echo "ishealthy() { lscontainers | jq -r '.[] | select(.Name == \"/'\"\$1\"'\").State.Health.Status == \"healthy\"'; }" >> $rc
echo "fatal() { echo \"Check failed: \$@\" 1>&2; exit 1; }" >> $rc
- name: Boot up containers
run: docker compose -f docker-compose.dev.yml up --build -d

- name: Wait for transient states to disappear
run: sleep 200

- name: Test backend
run: |
source /tmp/rcfile
checkstatus "corn-postgres" "running" | asserttrue || fatal "BackDb"
checkstatus "corn-backend" "running" | asserttrue || fatal "BackSpring"
- name: Test frontend
run: |
source /tmp/rcfile
checkstatus "corn-frontend" "running" | asserttrue || fatal "FrontNg"
- name: Test nginx
run: |
source /tmp/rcfile
checkstatus "corn-nginx" "running" | asserttrue || fatal "NginxMain"
- name: Test keycloak
run: |
source /tmp/rcfile
checkstatus "corn-keycloak" "running" | asserttrue || fatal "KcMain"
ishealthy "corn-keycloak" | asserttrue || fatal "KcMainHealth"
checkstatus "corn-keycloak-postgres" "running" | asserttrue || fatal "KcDb"
ishealthy "corn-keycloak-postgres" | asserttrue || fatal "KcDbHealth"
checkstatus "corn-keycloak-theme" "running" | asserttrue || fatal "KcTheme"
checkstatus "corn-keycloak-initializer" "exited" | asserttrue || fatal "KcInit"
- name: Test proxies connectivity
run: |
source /tmp/rcfile
curl -qo /dev/null -w "%{http_code}" 'http://localhost:4200/api/fallible' | grep -qP '^(502|503|504).*' || exit 0 && fatal "NginxBack"
curl -qo /dev/null -w "%{http_code}" 'http://localhost:4200/' | grep -qP '^(502|503|504).*' || exit 0 && fatal "NginxFront"
curl -qo /dev/null -w "%{http_code}" 'http://localhost:8081/realms/Corn' | grep -qP '^(502|503|504).*' || exit 0 && fatal "NginxKc"
- name: Test existence of Corn realm
run: |
source /tmp/rcfile
curl 'http://localhost:8081/realms/Corn/' | jq -r '.error == null' | asserttrue || fatal "CornRealm"
69 changes: 69 additions & 0 deletions .github/workflows/checkDockerProd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Check dockercompose.prod

on:
push:
branches: [ "main", "devel" ]
pull_request:
branches: [ "main", "devel" ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Install jq
run: sudo apt-get install -y jq

- name: Setup useful functions
run: |
rc=/tmp/rcfile
echo "lscontainers() { docker ps -qa | xargs --no-run-if-empty docker inspect; }" >> $rc
echo "asserttrue() { [ \"\$(cat)\" = \"true\" ]; }" >> $rc
echo "checkstatus() { lscontainers | jq -r '.[] | select(.Name == \"/'\"\$1\"'\").State.Status == \"'\"\$2\"'\"'; }" >> $rc
echo "ishealthy() { lscontainers | jq -r '.[] | select(.Name == \"/'\"\$1\"'\").State.Health.Status == \"healthy\"'; }" >> $rc
echo "fatal() { echo \"Check failed: \$@\" 1>&2; exit 1; }" >> $rc
- name: Boot up containers
run: docker compose -f docker-compose.prod.yml up --build -d

- name: Wait for transient states to disappear
run: sleep 200

- name: Test backend
run: |
source /tmp/rcfile
checkstatus "corn-postgres" "running" | asserttrue || fatal "BackDb"
checkstatus "corn-backend" "running" | asserttrue || fatal "BackSpring"
- name: Test frontend
run: |
source /tmp/rcfile
checkstatus "corn-frontend" "running" | asserttrue || fatal "FrontNginx"
- name: Test nginx
run: |
source /tmp/rcfile
checkstatus "corn-nginx" "running" | asserttrue || fatal "NginxMain"
- name: Test keycloak
run: |
source /tmp/rcfile
checkstatus "corn-keycloak" "running" | asserttrue || fatal "KcMain"
ishealthy "corn-keycloak" | asserttrue || fatal "KcMainHealth"
checkstatus "corn-keycloak-postgres" "running" | asserttrue || fatal "KcDb"
ishealthy "corn-keycloak-postgres" | asserttrue || fatal "KcDbHealth"
checkstatus "corn-keycloak-initializer" "exited" | asserttrue || fatal "KcInit"
- name: Test proxies connectivity
run: |
source /tmp/rcfile
curl -qo /dev/null -w "%{http_code}" 'http://localhost:4200/api/fallible' | grep -qP '^(502|503|504).*' || exit 0 && fatal "NginxBack"
curl -qo /dev/null -w "%{http_code}" 'http://localhost:4200/' | grep -qP '^(502|503|504).*' || exit 0 && fatal "NginxFront"
curl -qo /dev/null -w "%{http_code}" 'http://localhost:8081/realms/Corn' | grep -qP '^(502|503|504).*' || exit 0 && fatal "NginxKc"
- name: Test existence of Corn realm
run: |
source /tmp/rcfile
curl 'http://localhost:8081/realms/Corn/' | jq -r '.error == null' | asserttrue || fatal "CornRealm"
4 changes: 2 additions & 2 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ services:
healthcheck:
test: "curl -f http://localhost:8080/admin || exit 1"
interval: 1s
retries: 30
retries: 120
start_period: 15s
timeout: 5s
volumes:
Expand All @@ -117,7 +117,7 @@ services:
healthcheck:
test: "pg_isready -U keycloak"
interval: 1s
retries: 30
retries: 50
start_period: 5s
timeout: 3s

Expand Down
4 changes: 2 additions & 2 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ services:
healthcheck:
test: "curl -f http://localhost:8080/admin || exit 1"
interval: 1s
retries: 30
retries: 120
start_period: 15s
timeout: 5s

Expand All @@ -81,7 +81,7 @@ services:
healthcheck:
test: "pg_isready -U keycloak"
interval: 1s
retries: 30
retries: 50
start_period: 5s
timeout: 3s

Expand Down

0 comments on commit 1755eeb

Please sign in to comment.