Skip to content

Commit 7927d07

Browse files
authored
ci: add GitHub Actions workflow for building and testing services (#16)
* gains GH action to build docker compose * dont copy in Cargo.lock * remove llm_engine Cargo.lock * remove query runner Cargo.lock * git ignore Cargo.lock * use docker compose (not docker-compose) * leverage cached images * wait longer for services to start
1 parent e193653 commit 7927d07

File tree

7 files changed

+145
-4550
lines changed

7 files changed

+145
-4550
lines changed

.github/workflows/build.yml

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
name: Build and Test System
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
workflow_dispatch:
9+
10+
jobs:
11+
build-api:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v3
16+
17+
- name: Set up Docker Buildx
18+
uses: docker/setup-buildx-action@v2
19+
20+
- name: Build API service
21+
uses: docker/build-push-action@v4
22+
with:
23+
context: ./api
24+
push: false
25+
load: true
26+
tags: lucidata-api:latest
27+
cache-from: type=gha
28+
cache-to: type=gha,mode=max
29+
30+
build-llm-engine:
31+
runs-on: ubuntu-latest
32+
steps:
33+
- name: Checkout repository
34+
uses: actions/checkout@v3
35+
36+
- name: Set up Docker Buildx
37+
uses: docker/setup-buildx-action@v2
38+
39+
- name: Build LLM Engine service
40+
uses: docker/build-push-action@v4
41+
with:
42+
context: ./llm_engine
43+
push: false
44+
load: true
45+
tags: lucidata-llm-engine:latest
46+
cache-from: type=gha
47+
cache-to: type=gha,mode=max
48+
49+
build-query-runner:
50+
runs-on: ubuntu-latest
51+
steps:
52+
- name: Checkout repository
53+
uses: actions/checkout@v3
54+
55+
- name: Set up Docker Buildx
56+
uses: docker/setup-buildx-action@v2
57+
58+
- name: Build Query Runner service
59+
uses: docker/build-push-action@v4
60+
with:
61+
context: ./query_runner
62+
push: false
63+
load: true
64+
tags: lucidata-query-runner:latest
65+
cache-from: type=gha
66+
cache-to: type=gha,mode=max
67+
68+
system-test:
69+
needs: [build-api, build-llm-engine, build-query-runner]
70+
runs-on: ubuntu-latest
71+
steps:
72+
- name: Checkout repository
73+
uses: actions/checkout@v3
74+
75+
# Save and load images from the build jobs
76+
- name: Set up Docker Buildx
77+
uses: docker/setup-buildx-action@v2
78+
79+
# Download the images built in the previous jobs
80+
- name: Download API image
81+
uses: docker/build-push-action@v4
82+
with:
83+
context: ./api
84+
load: true
85+
tags: lucidata-api:latest
86+
cache-from: type=gha
87+
outputs: type=docker,dest=/tmp/api-image.tar
88+
89+
- name: Download LLM Engine image
90+
uses: docker/build-push-action@v4
91+
with:
92+
context: ./llm_engine
93+
load: true
94+
tags: lucidata-llm-engine:latest
95+
cache-from: type=gha
96+
outputs: type=docker,dest=/tmp/llm-engine-image.tar
97+
98+
- name: Download Query Runner image
99+
uses: docker/build-push-action@v4
100+
with:
101+
context: ./query_runner
102+
load: true
103+
tags: lucidata-query-runner:latest
104+
cache-from: type=gha
105+
outputs: type=docker,dest=/tmp/query-runner-image.tar
106+
107+
- name: Load saved images
108+
run: |
109+
docker load < /tmp/api-image.tar
110+
docker load < /tmp/llm-engine-image.tar
111+
docker load < /tmp/query-runner-image.tar
112+
docker images
113+
114+
- name: Start services with docker compose
115+
run: |
116+
# Use the pre-built images instead of rebuilding
117+
docker compose up -d
118+
env:
119+
COMPOSE_DOCKER_CLI_BUILD: 0
120+
DOCKER_BUILDKIT: 1
121+
122+
- name: Wait for services to be healthy
123+
run: |
124+
# Give services some time to start up
125+
echo "Waiting for services to start..."
126+
sleep 60
127+
128+
# Check if API is healthy
129+
if curl -s http://localhost:8000/api/health > /dev/null; then
130+
echo "API is healthy"
131+
else
132+
echo "API health check failed"
133+
docker compose logs
134+
exit 1
135+
fi
136+
137+
echo "All services are running properly!"
138+
139+
- name: Stop services
140+
if: always() # Ensures this step runs even if previous steps fail
141+
run: docker compose down

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Thumbs.db
1717

1818
# Rust / Cargo
1919
**/target/
20-
api/Cargo.lock
20+
**/Cargo.lock
2121
**/*.rs.bk
2222
*.pdb
2323

api/Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ RUN apt-get update && \
77
apt-get install -y pkg-config libssl-dev libpq-dev && \
88
rm -rf /var/lib/apt/lists/*
99

10-
# Copy Cargo.toml and Cargo.lock first to leverage Docker cache
10+
# Copy Cargo.toml first to leverage Docker cache
1111
COPY Cargo.toml ./
12-
COPY Cargo.lock ./
1312

1413
# Create a dummy main.rs to build dependencies
1514
RUN mkdir -p src && echo "fn main() {}" > src/main.rs

0 commit comments

Comments
 (0)