diff --git a/.dockerignore b/.dockerignore index 0771aee5..c35383ab 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,6 +1,15 @@ +.git .env +.env.* *.cpuprofile *.swp +*.log +node_modules +cov_profile deno-test.xml -/data \ No newline at end of file +/data +Dockerfile +Dockerfile.* +.dockerignore +.gitlab-ci.yml \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2b9f0555..8548a947 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -5,7 +5,10 @@ default: stages: - test + - e2e-setup + - e2e-test +# Original test stage test: stage: test timeout: 2 minutes @@ -29,3 +32,55 @@ test: - deno-test.xml reports: junit: deno-test.xml + +# 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 --build + # Wait for ditto instance to become active + - end=$((SECONDS + 30)); while [[ $SECONDS -lt $end ]] && ! curl http://localhost:4036; do echo "Waiting for localhost:4036..."; sleep 1; echo $SECONDS ; done + # Generate dynamic child pipeline configuration + - | + cat > child-pipeline.yml << EOF + playwright-tests: + trigger: + project: soapbox-pub/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