Skip to content

Commit

Permalink
make docker works for playground, scrapix and meilisearch
Browse files Browse the repository at this point in the history
  • Loading branch information
qdequele committed Nov 30, 2024
1 parent abe215f commit ec4dd44
Show file tree
Hide file tree
Showing 86 changed files with 6,540 additions and 3,496 deletions.
49 changes: 49 additions & 0 deletions .github/scripts/wait-for-it.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bash
# Use: ./wait-for-it.sh host:port [-t timeout] [-- command args]
# From: https://github.com/vishnubob/wait-for-it

WAITFORIT_cmdname=${0##*/}

echoerr() { if [[ $WAITFORIT_QUIET -ne 1 ]]; then echo "$@" 1>&2; fi }

usage()
{
cat << USAGE >&2
Usage:
$WAITFORIT_cmdname host:port [-t timeout] [-- command args]
-h HOST | --host=HOST Host or IP under test
-p PORT | --port=PORT TCP port under test
-t TIMEOUT | --timeout=TIMEOUT Timeout in seconds, zero for no timeout
-- COMMAND ARGS Execute command with args after the test finishes
USAGE
exit 1
}

wait_for()
{
if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then
echoerr "$WAITFORIT_cmdname: waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT"
else
echoerr "$WAITFORIT_cmdname: waiting for $WAITFORIT_HOST:$WAITFORIT_PORT without a timeout"
fi
WAITFORIT_start_ts=$(date +%s)
while :
do
if [[ $WAITFORIT_ISBUSY -eq 1 ]]; then
nc -z $WAITFORIT_HOST $WAITFORIT_PORT
WAITFORIT_result=$?
else
(echo -n > /dev/tcp/$WAITFORIT_HOST/$WAITFORIT_PORT) >/dev/null 2>&1
WAITFORIT_result=$?
fi
if [[ $WAITFORIT_result -eq 0 ]]; then
WAITFORIT_end_ts=$(date +%s)
echoerr "$WAITFORIT_cmdname: $WAITFORIT_HOST:$WAITFORIT_PORT is available after $((WAITFORIT_end_ts - WAITFORIT_start_ts)) seconds"
break
fi
sleep 1
done
return $WAITFORIT_result
}

# Rest of the script...
39 changes: 39 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Test

on:
pull_request:
branches: [main]

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: "18"
cache: "yarn"

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Build
run: yarn build

- name: Start test environment
run: docker-compose -f docker-compose.test.yml up -d

- name: Wait for services
run: |
.github/scripts/wait-for-it.sh localhost:7700 -t 60
.github/scripts/wait-for-it.sh localhost:3000 -t 60
.github/scripts/wait-for-it.sh localhost:8080 -t 60
- name: Run tests
run: yarn test:integration

- name: Cleanup
run: docker-compose -f docker-compose.test.yml down
12 changes: 6 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
# Specify the base Docker image. You can read more about
# the available images at https://crawlee.dev/docs/guides/docker-images
# You can also use any other image from Docker Hub.
FROM apify/actor-node-puppeteer-chrome:18 AS builder
FROM apify/actor-node-puppeteer-chrome:20 AS builder

# Copy just package.json and package-lock.json
# to speed up the build using Docker layer cache.
COPY --chown=myuser package*.json ./

# Install all dependencies. Don't audit to speed up the installation.
RUN yarn install --production=false
RUN npm install --include=dev

# Next, copy the source files using the user set
# in the base image.
COPY --chown=myuser . ./

# Install all dependencies and build the project.
# Don't audit to speed up the installation.
RUN yarn run build
RUN npm run build

# Create final image
FROM apify/actor-node-puppeteer-chrome:18
FROM apify/actor-node-puppeteer-chrome:20

# Copy only built JS files from builder image
COPY --from=builder --chown=myuser /home/myuser/dist ./dist
Expand All @@ -31,7 +31,7 @@ COPY --chown=myuser package*.json ./
# Install NPM packages, skip optional and development dependencies to
# keep the image small. Avoid logging too much and print the dependency
# tree for debugging
RUN yarn install --production=false
RUN npm install

# Next, copy the remaining files and directories with the source code.
# Since we do this after NPM install, quick build will be really fast
Expand All @@ -40,4 +40,4 @@ COPY --chown=myuser . ./

# Run the image. If you know you won't need headful browsers,
# you can remove the XVFB start script for a micro perf gain.
CMD ./start_xvfb_and_run_cmd.sh && yarn start:prod -- -c $CRAWLER_CONFIG -b /usr/bin/google-chrome --silent
CMD ./start_xvfb_and_run_cmd.sh && npm run start:prod -- -c $CRAWLER_CONFIG -b /usr/bin/google-chrome --silent
5 changes: 0 additions & 5 deletions config/nodemon:build.json

This file was deleted.

5 changes: 0 additions & 5 deletions config/nodemon:default-scrap.json

This file was deleted.

5 changes: 0 additions & 5 deletions config/nodemon:docsearch-scrap.json

This file was deleted.

27 changes: 0 additions & 27 deletions docker-compose.dev.yml

This file was deleted.

18 changes: 0 additions & 18 deletions docker-compose.test.yml

This file was deleted.

37 changes: 37 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/compose-spec/compose-spec/master/schema/compose-spec.json
services:
meilisearch:
image: getmeili/meilisearch:latest
environment:
- MEILI_MASTER_KEY=masterKey
ports:
- "7700:7700"

playground:
build:
context: ./playground
dockerfile: Dockerfile
ports:
- "3000:3000"

scraper:
build:
context: .
dockerfile: Dockerfile
environment:
- NODE_ENV=test
- REDIS_URL=redis://redis:6379
ports:
- "8080:8080"
depends_on:
- meilisearch
- playground

redis:
image: redis:latest
restart: always
ports:
- 6379:6379

volumes:
meili_data:
7 changes: 7 additions & 0 deletions jest.integration.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
testMatch: ["**/tests/integration/**/*.test.ts"],
setupFilesAfterEnv: ["<rootDir>/tests/setup.ts"],
testTimeout: 30000,
};
Loading

0 comments on commit ec4dd44

Please sign in to comment.