Skip to content

Commit d351d4b

Browse files
committed
feat: e2e tests using docker compose
1 parent d9d8b18 commit d351d4b

30 files changed

+3663
-2297
lines changed

.github/workflows/e2e.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: E2E Tests
2+
3+
permissions:
4+
contents: read
5+
issues: write
6+
pull-requests: write
7+
8+
on:
9+
push:
10+
branches: [main]
11+
issue_comment:
12+
types: [created]
13+
14+
jobs:
15+
e2e:
16+
runs-on: ubuntu-latest
17+
# Run on push/PR or when a maintainer comments "/test e2e" or "/run e2e"
18+
if: |
19+
github.event_name != 'issue_comment' || (
20+
github.event.issue.pull_request &&
21+
(contains(github.event.comment.body, '/test e2e') || contains(github.event.comment.body, '/run e2e')) &&
22+
(github.event.comment.author_association == 'OWNER' ||
23+
github.event.comment.author_association == 'MEMBER' ||
24+
github.event.comment.author_association == 'COLLABORATOR')
25+
)
26+
27+
steps:
28+
- name: Checkout code
29+
uses: actions/checkout@v4
30+
with:
31+
# When triggered by comment, checkout the PR branch
32+
ref: ${{ github.event_name == 'issue_comment' && format('refs/pull/{0}/head', github.event.issue.number) || github.ref }}
33+
34+
- name: Add reaction to comment
35+
if: github.event_name == 'issue_comment'
36+
uses: peter-evans/create-or-update-comment@v4
37+
with:
38+
token: ${{ secrets.GITHUB_TOKEN }}
39+
comment-id: ${{ github.event.comment.id }}
40+
reactions: eyes
41+
42+
- name: Set up Node.js
43+
uses: actions/setup-node@v4
44+
with:
45+
node-version: '18'
46+
cache: 'npm'
47+
48+
- name: Install dependencies
49+
run: npm ci
50+
51+
- name: Build and start services with Docker Compose
52+
run: docker-compose up -d --build
53+
54+
- name: Wait for services to be ready
55+
run: |
56+
timeout 60 bash -c 'until docker-compose ps | grep -q "Up"; do sleep 2; done'
57+
sleep 10
58+
59+
- name: Run E2E tests
60+
run: npm run test:e2e
61+
env:
62+
GIT_PROXY_URL: http://localhost:8000
63+
GIT_PROXY_UI_URL: http://localhost:8081
64+
E2E_TIMEOUT: 30000
65+
66+
- name: Stop services
67+
if: always()
68+
run: docker-compose down -v

Dockerfile

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Build stage
2+
FROM node:20 AS builder
3+
4+
USER root
5+
6+
WORKDIR /app
7+
8+
# Copy package files
9+
COPY package*.json ./
10+
11+
# Install all dependencies (including dev dependencies for building)
12+
RUN npm pkg delete scripts.prepare && npm ci --include=dev --loglevel verbose
13+
14+
# Copy source files and config files needed for build
15+
COPY tsconfig.json tsconfig.publish.json proxy.config.json config.schema.json integration-test.config.json vite.config.ts index.html index.ts ./
16+
COPY src/ /app/src/
17+
COPY public/ /app/public/
18+
19+
# Build the UI and server
20+
RUN npm run build-ui --loglevel verbose \
21+
&& npx tsc --project tsconfig.publish.json \
22+
&& cp config.schema.json dist/
23+
24+
# Prune dev dependencies after build is complete
25+
RUN npm prune --production
26+
27+
# Production stage
28+
FROM node:20-slim AS production
29+
30+
RUN apt-get update && apt-get install -y \
31+
git tini \
32+
&& rm -rf /var/lib/apt/lists/*
33+
34+
WORKDIR /app
35+
36+
# Copy the modified package.json (without prepare script) and production node_modules from builder
37+
COPY --from=builder /app/package*.json ./
38+
COPY --from=builder /app/node_modules/ /app/node_modules/
39+
40+
# Copy built artifacts from builder stage
41+
COPY --from=builder /app/dist/ /app/dist/
42+
COPY --from=builder /app/build /app/dist/build/
43+
44+
# Copy configuration files needed at runtime
45+
COPY proxy.config.json config.schema.json ./
46+
47+
# Copy entrypoint script
48+
COPY docker-entrypoint.sh /docker-entrypoint.sh
49+
RUN chmod +x /docker-entrypoint.sh
50+
51+
EXPOSE 8080 8000
52+
53+
ENTRYPOINT ["tini", "--", "/docker-entrypoint.sh"]
54+
CMD ["node", "dist/index.js"]

docker-compose.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
version: '3.7'
2+
3+
services:
4+
git-proxy:
5+
build: .
6+
ports:
7+
- '8000:8000'
8+
- '8081:8081'
9+
command: ['node', 'dist/index.js', '--config', '/app/integration-test.config.json']
10+
volumes:
11+
- ./integration-test.config.json:/app/integration-test.config.json:ro
12+
depends_on:
13+
- mongodb
14+
- git-server
15+
networks:
16+
- git-network
17+
environment:
18+
- NODE_ENV=test
19+
- GIT_PROXY_UI_PORT=8081
20+
- GIT_PROXY_SERVER_PORT=8000
21+
- NODE_OPTIONS=--trace-warnings
22+
23+
mongodb:
24+
image: mongo:7
25+
ports:
26+
- '27017:27017'
27+
networks:
28+
- git-network
29+
environment:
30+
- MONGO_INITDB_DATABASE=gitproxy
31+
volumes:
32+
- mongodb_data:/data/db
33+
34+
git-server:
35+
build: localgit/
36+
environment:
37+
- GIT_HTTP_EXPORT_ALL=true
38+
networks:
39+
- git-network
40+
hostname: git-server
41+
42+
networks:
43+
git-network:
44+
driver: bridge
45+
46+
volumes:
47+
mongodb_data:

docker-entrypoint.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
# Create runtime configuration file for the UI
4+
# This allows the UI to discover its environment dynamically
5+
cat > /app/dist/runtime-config.json << EOF
6+
{
7+
"apiUrl": "${VITE_API_URI:-}",
8+
"allowedOrigins": [
9+
"${VITE_ALLOWED_ORIGINS:-*}"
10+
],
11+
"environment": "${NODE_ENV:-production}"
12+
}
13+
EOF
14+
15+
echo "Created runtime configuration with:"
16+
echo " API URL: ${VITE_API_URI:-auto-detect}"
17+
echo " Allowed Origins: ${VITE_ALLOWED_ORIGINS:-*}"
18+
19+
exec "$@"

integration-test.config.json

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"cookieSecret": "integration-test-cookie-secret",
3+
"sessionMaxAgeHours": 12,
4+
"rateLimit": {
5+
"windowMs": 60000,
6+
"limit": 150
7+
},
8+
"tempPassword": {
9+
"sendEmail": false,
10+
"emailConfig": {}
11+
},
12+
"authorisedList": [
13+
{
14+
"project": "coopernetes",
15+
"name": "test-repo",
16+
"url": "http://git-server:8080/coopernetes/test-repo.git"
17+
},
18+
{
19+
"project": "finos",
20+
"name": "git-proxy",
21+
"url": "http://git-server:8080/finos/git-proxy.git"
22+
}
23+
],
24+
"sink": [
25+
{
26+
"type": "fs",
27+
"params": {
28+
"filepath": "./."
29+
},
30+
"enabled": false
31+
},
32+
{
33+
"type": "mongo",
34+
"connectionString": "mongodb://mongodb:27017/gitproxy",
35+
"options": {
36+
"useNewUrlParser": true,
37+
"useUnifiedTopology": true,
38+
"tlsAllowInvalidCertificates": false,
39+
"ssl": false
40+
},
41+
"enabled": true
42+
}
43+
],
44+
"authentication": [
45+
{
46+
"type": "local",
47+
"enabled": true
48+
}
49+
]
50+
}

localgit/Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM httpd:2.4
2+
3+
RUN apt-get update && apt-get install -y \
4+
git \
5+
apache2-utils \
6+
&& rm -rf /var/lib/apt/lists/*
7+
8+
COPY httpd.conf /usr/local/apache2/conf/httpd.conf
9+
10+
RUN htpasswd -cb /usr/local/apache2/conf/.htpasswd admin admin123 \
11+
&& htpasswd -b /usr/local/apache2/conf/.htpasswd testuser user123
12+
13+
COPY init-repos.sh /usr/local/bin/init-repos.sh
14+
15+
RUN chmod +x /usr/local/bin/init-repos.sh \
16+
&& /usr/local/bin/init-repos.sh
17+
18+
EXPOSE 8080
19+
20+
CMD ["httpd-foreground"]

localgit/httpd.conf

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
ServerRoot "/usr/local/apache2"
2+
Listen 0.0.0.0:8080
3+
4+
LoadModule mpm_event_module modules/mod_mpm_event.so
5+
LoadModule unixd_module modules/mod_unixd.so
6+
LoadModule authz_core_module modules/mod_authz_core.so
7+
LoadModule authn_core_module modules/mod_authn_core.so
8+
LoadModule auth_basic_module modules/mod_auth_basic.so
9+
LoadModule authn_file_module modules/mod_authn_file.so
10+
LoadModule authz_user_module modules/mod_authz_user.so
11+
LoadModule alias_module modules/mod_alias.so
12+
LoadModule cgi_module modules/mod_cgi.so
13+
LoadModule env_module modules/mod_env.so
14+
LoadModule dir_module modules/mod_dir.so
15+
LoadModule mime_module modules/mod_mime.so
16+
LoadModule log_config_module modules/mod_log_config.so
17+
18+
User www-data
19+
Group www-data
20+
21+
ServerName git-server
22+
23+
# Git HTTP Backend Configuration - Serve directly from root
24+
ScriptAlias / "/usr/lib/git-core/git-http-backend/"
25+
SetEnv GIT_PROJECT_ROOT "/var/git"
26+
SetEnv GIT_HTTP_EXPORT_ALL
27+
28+
<LocationMatch "^/.+\.git">
29+
AuthType Basic
30+
AuthName "Git Access"
31+
AuthUserFile "/usr/local/apache2/conf/.htpasswd"
32+
Require valid-user
33+
</LocationMatch>
34+
35+
# Error and access logging
36+
ErrorLog /proc/self/fd/2
37+
LogLevel info
38+
39+
# Define log formats
40+
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
41+
LogFormat "%h %l %u %t \"%r\" %>s %b" common
42+
LogFormat "%{Referer}i -> %U" referer
43+
LogFormat "%{User-agent}i" agent
44+
45+
# Use combined format for detailed request logging
46+
CustomLog /proc/self/fd/1 combined
47+
48+
TypesConfig conf/mime.types

0 commit comments

Comments
 (0)