Skip to content

Commit f83d750

Browse files
committed
WIP: CI tests
1 parent dd6ee8c commit f83d750

File tree

3 files changed

+201
-5
lines changed

3 files changed

+201
-5
lines changed
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
name: Ditto Edge Server Quickstart CI
2+
3+
on:
4+
pull_request:
5+
types:
6+
# These first three events are the default ones.
7+
- opened
8+
- reopened
9+
- synchronize
10+
paths:
11+
- "edge-server/**"
12+
- ".github/workflows/edge-server-ci.yml"
13+
push:
14+
tags:
15+
- ditto-edge-server-release-*
16+
schedule:
17+
# Every day at 00:00 UTC.
18+
# If this changes, the upload-nightly if statement must change as well.
19+
- cron: '0 1 * * *'
20+
21+
22+
# Limits the concurrency of this workflow to prevent wasted runner time
23+
# Only one instance of this workflow can run per actor-branch.
24+
concurrency:
25+
group: ${{ github.workflow }}-${{ github.triggering_actor }}-${{ github.head_ref }}
26+
cancel-in-progress: true
27+
28+
env:
29+
DIST_BUCKET_NAME: edge-server-nightlies
30+
PUBLISH_ACCOUNT: "102052685887"
31+
PUBLISH_ROLE: "GitHubAction-EdgeServerNightlies"
32+
AWS_REGION: "us-east-1"
33+
REGISTRY_NAME: 102052685887.dkr.ecr.us-east-1.amazonaws.com
34+
IMG_REPOSITORY: ditto-preview/ditto-edge-server
35+
36+
jobs:
37+
# Sets global config variables for this workflow run.
38+
# This consolidates conditional logic an keeps things DRY.
39+
set-workfow-vars:
40+
name: Set Workflow Variables
41+
runs-on: [self-hosted, ditto-ci-runner-small]
42+
permissions: {}
43+
outputs:
44+
is-nightly: ${{ github.event.schedule == '0 1 * * *' }}
45+
steps:
46+
# Keep one no-op job to satisfy GHA parser.
47+
- name: Set Variables
48+
if: false
49+
run: |
50+
echo "Done"
51+
52+
test:
53+
name: Test on ${{ matrix.platform }}
54+
runs-on: ${{ matrix.runner }}
55+
needs:
56+
- set-workfow-vars
57+
permissions:
58+
id-token: write # This is required for requesting the JWT
59+
contents: read
60+
strategy:
61+
matrix:
62+
include:
63+
- platform: linux-x86
64+
runner: [ubuntu-latest-16-cores]
65+
target: x86_64-unknown-linux-gnu
66+
docker-platform: linux/amd64
67+
- platform: linux-aarch64
68+
runner: [linux-aarch64]
69+
target: aarch64-unknown-linux-gnu
70+
docker-platform: linux/arm64
71+
steps:
72+
- uses: actions/checkout@v4
73+
74+
# Install just command runner
75+
- name: Install just
76+
uses: extractions/setup-just@v2
77+
78+
# Install jq for JSON processing (used by justfile commands)
79+
- name: Install jq
80+
run: |
81+
sudo apt-get update && sudo apt-get install -y jq
82+
83+
# Configure quickstart config with credentials
84+
- name: Configure quickstart config
85+
uses: mikefarah/yq@master
86+
with:
87+
cmd: |
88+
yq eval \
89+
'.resources.my_ditto_db.db_id = "${{ secrets.DITTO_APP_ID }}" |
90+
.resources.my_ditto_db.auth.server.access_token = "${{ secrets.DITTO_PLAYGROUND_TOKEN }}" |
91+
.resources.my_ditto_db.auth.server.auth_url = "${{ secrets.DITTO_AUTH_URL }}" |
92+
.resources.my_http_server.databases.my_db.db_id = "${{ secrets.DITTO_APP_ID }}"' \
93+
edge-server/quickstart_config_sample.yaml > ${{runner.temp}}/quickstart_config.yaml
94+
95+
# Download the nightly edge server image for the target platform
96+
- name: Download edge server nightly for ${{ matrix.target }}
97+
working-directory: ./edge-server
98+
run: |
99+
just download ${{ matrix.target }}
100+
101+
# Load the downloaded image into Docker
102+
- name: Load edge server image
103+
working-directory: ./edge-server
104+
run: |
105+
just load
106+
107+
# Fail fast with a known reason if the sample config is no longer valid.
108+
- name: Validate Input Config
109+
working-directory: ./edge-server
110+
# Runs the edge server with the freshlyy made config mounted to /config.yaml and validates it.
111+
run: |
112+
just run ${{ runner.temp }}/quickstart_config.yaml config validate -c /config.yaml
113+
114+
# Start edge server in background
115+
- name: Start edge server
116+
working-directory: ./edge-server
117+
run: |
118+
docker run --rm -d \
119+
--name edge-server-test \
120+
-p 127.0.0.1:8080:8080 \
121+
-v ${{runner.temp}}/quickstart_config.yaml:/config.yaml \
122+
edge-server-quickstart:latest run -c /config.yaml
123+
124+
# Wait for edge server to be ready
125+
echo "Waiting for edge server to be ready..."
126+
for i in {1..30}; do
127+
if curl -s http://127.0.0.1:8080/my_server > /dev/null 2>&1; then
128+
echo "Edge server is ready!"
129+
break
130+
fi
131+
if [ $i -eq 30 ]; then
132+
echo "Edge server failed to start"
133+
docker logs edge-server-test
134+
exit 1
135+
fi
136+
echo "Attempt $i/30: Edge server not ready yet..."
137+
sleep 2
138+
done
139+
140+
# Test basic functionality: create, get, update, delete tasks
141+
- name: Test edge server functionality
142+
working-directory: ./edge-server
143+
run: |
144+
# Create a task
145+
echo "Creating a task..."
146+
TASK_RESULT=$(just create-task "Test Task from CI")
147+
echo "$TASK_RESULT"
148+
TASK_ID=$(echo "$TASK_RESULT" | jq -r '.mutateResult.value._id')
149+
echo "Created task with ID: $TASK_ID"
150+
151+
# Get all tasks
152+
echo "Getting all tasks..."
153+
TASKS=$(just get-tasks)
154+
echo "$TASKS"
155+
TASK_COUNT=$(echo "$TASKS" | jq '.items | length')
156+
if [ "$TASK_COUNT" -lt 1 ]; then
157+
echo "Error: Expected at least 1 task, got $TASK_COUNT"
158+
exit 1
159+
fi
160+
echo "Successfully retrieved $TASK_COUNT task(s)"
161+
162+
# Update the task
163+
echo "Updating task to completed..."
164+
UPDATE_RESULT=$(just update-task "$TASK_ID" "true")
165+
echo "$UPDATE_RESULT"
166+
167+
# Verify the update
168+
echo "Verifying task update..."
169+
TASKS=$(just get-tasks)
170+
TASK_DONE=$(echo "$TASKS" | jq -r ".items[] | select(._id == \"$TASK_ID\") | .done")
171+
if [ "$TASK_DONE" != "true" ]; then
172+
echo "Error: Task was not marked as done"
173+
exit 1
174+
fi
175+
echo "Task successfully updated to completed"
176+
177+
# Delete the task
178+
echo "Deleting task..."
179+
DELETE_RESULT=$(just delete-task "$TASK_ID")
180+
echo "$DELETE_RESULT"
181+
echo "Task successfully deleted"
182+
183+
# Cleanup
184+
- name: Stop edge server
185+
if: always()
186+
run: |
187+
docker stop edge-server-test || true
188+
docker rm edge-server-test || true
189+
190+
# Show logs if tests failed
191+
- name: Show edge server logs on failure
192+
if: failure()
193+
run: |
194+
docker logs edge-server-test || echo "Container not found"

edge-server/justfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ load:
1414
docker tag $LOADED_IMAGE edge-server-quickstart:latest
1515

1616
# Run the loaded docker image
17-
run *command="run -c /config.yaml":
18-
docker run --rm -p 127.0.0.1:8080:8080 -v ./quickstart_config.yaml:/config.yaml edge-server-quickstart:latest {{ command }}
17+
run config="./quickstart_config.yaml" *command="run -c /config.yaml":
18+
docker run --rm -p 127.0.0.1:8080:8080 -v {{ config }}:/config.yaml edge-server-quickstart:latest {{ command }}
1919

2020
# Creates a new task with the given title
2121
create-task *title:

edge-server/quickstart_config_sample.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ resources:
1212
provider: "__playgroundProvider"
1313
my_http_server:
1414
resource_type: HttpServer
15-
db_id: "YOUR_DB_ID_HERE"
16-
base_path: my_server
17-
http_api: true
1815
listen_addr: "0.0.0.0:8080"
16+
databases:
17+
my_db:
18+
db_id: "YOUR_DB_ID_HERE"
19+
base_path: my_server
20+
http_api: true

0 commit comments

Comments
 (0)