Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run simple-server as a Github Actions service #5118

Draft
wants to merge 30 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
dda13f7
Checks with Docker Image
igbanam Nov 12, 2024
a823520
prefer port mapping to "expose"
igbanam Nov 12, 2024
48a4091
fix postgres healthchecks
igbanam Nov 12, 2024
bd75417
fix environment specifications
igbanam Nov 12, 2024
de8371c
remove depends_on
igbanam Nov 12, 2024
a5ab840
Fix run env specification
igbanam Nov 12, 2024
2cd5146
command workaround
igbanam Nov 12, 2024
62d45c2
attempt fix for docker entrypoint
igbanam Nov 12, 2024
bc9f95c
Special simple-server compose for CI
igbanam Nov 14, 2024
2f1890d
Fix concurrency group
igbanam Nov 14, 2024
ecd4c27
Fix docker compose file path
igbanam Nov 14, 2024
7fb19e9
Remove the ci file from the .github folder
igbanam Nov 14, 2024
2db7a5a
Merge branch 'master' into igbanam/sc-13775/change-heroku-to-docker
igbanam Nov 27, 2024
fc6a394
Use the right file path
igbanam Nov 27, 2024
191cab2
Quote name?
igbanam Nov 27, 2024
5939ab0
show all files from checkout
igbanam Nov 27, 2024
8022874
run docker after checkout :facepalm:
igbanam Nov 27, 2024
731ed52
The file name is .compose not .ci
igbanam Nov 27, 2024
44f8acc
Fix manifest endpoint for integration tests
igbanam Nov 27, 2024
f253cd4
fix server URL, fix service clean up
igbanam Nov 27, 2024
bb1611b
wait for simple server to be healthy before integration tests
igbanam Nov 28, 2024
787e7da
remember to always use absolute paths :pensive:
igbanam Nov 28, 2024
af1a379
check connectivity to the container
igbanam Nov 28, 2024
7cf8270
swap order for connectivity check
igbanam Nov 28, 2024
0ef3d8c
force docker compose to use the host network
igbanam Nov 28, 2024
3f22ffd
use 127.0.0.1 in place of localhost
igbanam Nov 28, 2024
341fa66
hub.docker.internal?
igbanam Nov 28, 2024
4103577
Revert "hub.docker.internal?"
igbanam Nov 28, 2024
c3afebf
docker bridge network binding explicitly to localhost IP
igbanam Nov 28, 2024
dac19a0
Update ci_checks_v2.yml
ademarcqrtsl Nov 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/docker/simple-server.compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,9 @@ services:
CALL_SESSION_REDIS_HOST: redis
RAILS_CACHE_REDIS_URL: redis://
SIDEKIQ_REDIS_HOST: redis

networks:
default:
driver: bridge
driver_opts:
com.docker.network.bridge.host_binding_ipv4: "127.0.0.1"
41 changes: 41 additions & 0 deletions .github/scripts/wait_for_simple_server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

# There's a possibility the Simple Server takes a while to come on, and is not
# ready when the Android integration tests need it. This implements a wait loop
# for 5 minutes — we shouldn't be waiting for longer than this — to check if we
# can ping a particular URL on the server for a healthcheck.
#
# A good example is to ping for the manifest and check if we get a 200
#
# ./wait_for_simple_server.sh http://<simple-server-host>/api/manifest.json 200

# Accept two arguments without assuming sane defaults
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <endpoint_url> <status_code>"
exit 1
fi

endpoint=$1
desired_status=$2
timeout=300
start_time=$(date +%s)

while true; do
status=$(curl -o /dev/null -s -w "%{http_code}\n" "$endpoint")

if [ "$status" -eq "$desired_status" ]; then
echo "Endpoint is up and running with status $desired_status."
break
else
echo "Current status: $status. Retrying..."
# Wait for a few seconds before retrying
sleep 5
fi

current_time=$(date +%s)
elapsed_time=$((current_time - start_time))
if [ "$elapsed_time" -ge "$timeout" ]; then
echo "Timeout reached. Exiting with failure."
exit 1
fi
done
107 changes: 107 additions & 0 deletions .github/workflows/ci_checks_v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: CI V2
on:
pull_request:
concurrency:
group: ci-v2-${{ github.head_ref }}
cancel-in-progress: true
jobs:
integration-test:
runs-on:
- ubuntu-latest
env:
AVD_API_LEVEL: 34
AVD_ARCH: x86_64
steps:
- name: Enable KVM group perms
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm

- name: Checkout Android source
uses: actions/checkout@v4

- name: Start Simple Service
run: |
docker compose -f ".github/docker/simple-server.compose.yml" up -d
sleep 2
docker ps


- name: Cache AVD
uses: actions/cache@v4
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: ${{ runner.os }}-avd-${{ env.AVD_API_LEVEL }}-${{ env.AVD_ARCH }}

- name: create AVD and generate snapshot for caching
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ env.AVD_API_LEVEL }}
arch: ${{ env.AVD_ARCH }}
force-avd-creation: false
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: false
disk-size: 8G
script: echo "Generated AVD snapshot for caching."

- name: set up JDK
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 17
cache: 'gradle'

- name: Build QA Test Artifacts
id: build-instrumented-tests
env:
SIMPLE_SERVER_HOST: http://127.0.0.1:8420
run: |
./gradlew --build-cache --no-daemon -PmanifestEndpoint=${{ env.SIMPLE_SERVER_HOST }}/api/ assembleQaDebug assembleQaDebugAndroidTest

# - name: Check connectivity to server container
# run: |
# curl -I http://127.0.0.1:8420
# docker exec -it $(docker ps -q -f name=server) curl -I http://server:3000

- name: Ensure the Simple Server is running
id: ensure-healthy-simple
env:
SIMPLE_SERVER_HOST: http://127.0.0.1:8420
run: .github/scripts/wait_for_simple_server.sh ${{ env.SIMPLE_SERVER_HOST }}/api/manifest.json 200

- name: QA Android Tests
id: run-instrumented-tests
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ env.AVD_API_LEVEL }}
arch: ${{ env.AVD_ARCH }}
force-avd-creation: false
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: true
disk-size: 8G
script: |
adb root
mkdir -p app/build/outputs/test-artifacts
adb install app/build/outputs/apk/qa/debug/app-qa-debug.apk
adb install app/build/outputs/apk/androidTest/qa/debug/app-qa-debug-androidTest.apk
adb shell am instrument -w -e filter org.simple.clinic.benchmark.SelectBenchmarkTests -e benchmark_app_performance false org.simple.clinic.qa.debug.test/org.simple.clinic.AndroidTestJUnitRunner >app/build/outputs/test-artifacts/logs.txt 2>app/build/outputs/test-artifacts/logs.txt
cat app/build/outputs/test-artifacts/logs.txt
adb pull /storage/emulated/0/Android/data/org.simple.clinic.qa.debug/ app/build/outputs/test-artifacts/ || true
adb uninstall org.simple.clinic.qa.debug
adb uninstall org.simple.clinic.qa.debug.test
! grep -q "FAILURES\!\!\!" app/build/outputs/test-artifacts/logs.txt

- name: Stop Simple Service
run: |
docker compose -f ".github/docker/simple-server.compose.yml" down
- name: Upload failed test artifacts
if: always() && steps.run-instrumented-tests.outcome != 'success'
uses: actions/upload-artifact@v4
with:
name: failed-test-artifacts
path: app/build/outputs/test-artifacts
42 changes: 42 additions & 0 deletions simple-server.ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
version: "3"

services:
postgres:
image: postgres:14.3-alpine
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=password
volumes:
- postgresqldata:/var/lib/postgresql/data
expose:
- "5432"

redis:
image: redis:5-alpine
expose:
- "6379"
volumes:
- redisdata:/data

server:
image: simpledotorg/server:latest
command: bash -c "rm -f tmp/pids/server.pid && bundle exec rake db:setup; bundle exec rails s -p 3000 -b '0.0.0.0'"
expose:
- "3000"
ports:
- "8420:3000"
depends_on:
- redis
- postgres
environment:
SIMPLE_SERVER_DATABASE_HOST: postgres
SIMPLE_SERVER_DATABASE_USERNAME: postgres
SIMPLE_SERVER_DATABASE_PASSWORD: password
SIMPLE_SERVER_HOST_PROTOCOL: https
CALL_SESSION_REDIS_HOST: redis
RAILS_CACHE_REDIS_URL: redis://
SIDEKIQ_REDIS_HOST: redis

volumes:
postgresqldata:
redisdata:
Loading