From 9355ab9b17ddbc0d24666f2141c54483505b8c1d Mon Sep 17 00:00:00 2001 From: Chad Curtis Date: Tue, 1 Apr 2025 05:41:31 -0400 Subject: [PATCH] Attempt to build ditto locally for test run target. --- .dockerignore | 12 ++++++- .gitlab-ci.yml | 78 ++++++++++++++++++++++++++++++++--------- Dockerfile.test | 27 ++++++++++++++ docker-compose.test.yml | 28 +++++++++++++++ 4 files changed, 127 insertions(+), 18 deletions(-) create mode 100644 Dockerfile.test create mode 100644 docker-compose.test.yml diff --git a/.dockerignore b/.dockerignore index 0771aee5..926a4484 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,6 +1,16 @@ +.git .env +.env.* *.cpuprofile *.swp +*.log +node_modules +cov_profile deno-test.xml -/data \ No newline at end of file +/data +Dockerfile +Dockerfile.* +docker-compose.* +.dockerignore +.gitlab-ci.yml \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 02c565e7..4369eddb 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -5,11 +5,20 @@ default: stages: - test - - trigger-playwright-tests + - e2e-setup + - e2e-test +# Original test stage test: stage: test timeout: 2 minutes + before_script: + # Install nak for test environment + - apt-get update && apt-get install -y curl build-essential + - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y + - . "$HOME/.cargo/env" && cargo install nak + # Generate NSEC + - export DITTO_NSEC=$(nak key generate | nak encode nsec) script: - deno fmt --check - deno task lint @@ -20,7 +29,6 @@ test: services: - postgres:16 variables: - DITTO_NSEC: nsec1zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zygs4rm7hz DATABASE_URL: postgres://postgres:postgres@postgres:5432/postgres POSTGRES_HOST_AUTH_METHOD: trust RUST_BACKTRACE: 1 @@ -31,22 +39,58 @@ test: reports: junit: deno-test.xml -trigger-playwright-tests: - stage: trigger-playwright-tests - image: ubuntu:latest - before_script: - - apt update && apt install -y curl +# Start E2E environment +e2e-environment: + stage: e2e-setup + image: docker/compose:latest + services: + - docker:dind + variables: + DOCKER_HOST: tcp://docker:2375 + DOCKER_TLS_CERTDIR: "" + DOCKER_DRIVER: overlay2 script: + - docker compose -f docker-compose.test.yml up -d + # Wait for Ditto to be healthy - | - curl --request POST \ - --form "token=${PLAYWRIGHT_TRIGGER_TOKEN}" \ - --form "ref=main" \ - --form "merge_requests_events=true" \ - --form "variables[CI_PROJECT_ID]=${CI_PROJECT_ID}" \ - --form "variables[CI_MERGE_REQUEST_IID]=${CI_MERGE_REQUEST_IID}" \ - --form "variables[CI_COMMIT_SHA]=${CI_COMMIT_SHA}" \ - --form "variables[CI_COMMIT_SHORT_SHA]=${CI_COMMIT_SHORT_SHA}" \ - --form "variables[CI_COMMIT_REF_NAME]=${CI_COMMIT_REF_NAME}" \ - "https://gitlab.com/api/v4/projects/67335996/trigger/pipeline" + until docker compose -f docker-compose.test.yml ps ditto | grep -q "healthy"; do + echo "Waiting for Ditto to be ready..." + sleep 2 + done + # Generate dynamic child pipeline configuration + - | + cat > child-pipeline.yml << EOF + playwright-tests: + trigger: + project: your-group/ditto-playwright + strategy: depend + variables: + BASE_URL: http://localhost:4036 + CI_PROJECT_ID: ${CI_PROJECT_ID} + CI_MERGE_REQUEST_IID: ${CI_MERGE_REQUEST_IID} + CI_COMMIT_SHA: ${CI_COMMIT_SHA} + CI_COMMIT_SHORT_SHA: ${CI_COMMIT_SHORT_SHA} + CI_COMMIT_REF_NAME: ${CI_COMMIT_REF_NAME} + EOF + artifacts: + paths: + - child-pipeline.yml only: - merge_requests + +# Trigger child pipeline +e2e-test: + stage: e2e-test + trigger: + include: + - artifact: child-pipeline.yml + job: e2e-environment + strategy: depend + needs: + - e2e-environment + variables: + BASE_URL: http://localhost:4036 + after_script: + - docker compose -f docker-compose.test.yml down -v + only: + - merge_requests \ No newline at end of file diff --git a/Dockerfile.test b/Dockerfile.test new file mode 100644 index 00000000..002f564d --- /dev/null +++ b/Dockerfile.test @@ -0,0 +1,27 @@ +FROM denoland/deno:2.2.2 + +WORKDIR /app + +# Install curl and Rust for nak installation +RUN apt-get update && apt-get install -y \ + curl \ + jq \ + unzip \ + && rm -rf /var/lib/apt/lists/* + +# Copy the application files +COPY . . + +# Install soapbox +RUN deno task soapbox + +# Generate NSEC at build time +RUN export DITTO_NSEC=$(deno task nsec) && \ + echo "export DITTO_NSEC=$DITTO_NSEC" > /app/nsec.env + +ENV DATABASE_URL="" + +EXPOSE 4036 + +# Use array form with shell -c to properly handle the command +CMD ["/bin/sh", "-c", ". /app/nsec.env && deno run -A /app/packages/ditto/server.ts"] \ No newline at end of file diff --git a/docker-compose.test.yml b/docker-compose.test.yml new file mode 100644 index 00000000..e09a98ae --- /dev/null +++ b/docker-compose.test.yml @@ -0,0 +1,28 @@ +version: '3.8' + +services: + postgres: + image: postgres:16 + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: postgres + POSTGRES_HOST_AUTH_METHOD: trust + healthcheck: + test: ["CMD-SHELL", "pg_isready -U postgres"] + interval: 5s + timeout: 5s + retries: 5 + + ditto: + build: + context: . + dockerfile: Dockerfile.test + environment: + - DATABASE_URL=postgres://postgres:postgres@postgres:5432/postgres + - RUST_BACKTRACE=1 + ports: + - "4036:4036" + depends_on: + postgres: + condition: service_healthy \ No newline at end of file