diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml new file mode 100644 index 0000000..61db4a5 --- /dev/null +++ b/.github/workflows/run-tests.yml @@ -0,0 +1,46 @@ +name: Docker Actions + +on: + push: + paths: + - '**.js' + - '**.json' + - '**.yml' + branches: + - main + +jobs: + setup-and-test: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Docker Compose + run: | + sudo rm /usr/local/bin/docker-compose + curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /tmp/docker-compose + chmod +x /tmp/docker-compose + sudo mv /tmp/docker-compose /usr/local/bin/docker-compose + + - name: Start localstack + run: docker-compose up -d mongodb + + - name: Use Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + + - name: Restore dependencies + run: | + cd ./app + npm ci + + - name: Run tests + run: | + cd ./app + npm test + + - name: Clean up + run: docker-compose down --volumes \ No newline at end of file diff --git a/app/Dockerfile b/app/Dockerfile deleted file mode 100644 index 66069e8..0000000 --- a/app/Dockerfile +++ /dev/null @@ -1,19 +0,0 @@ -FROM node:20.11-alpine3.18 as build - -WORKDIR /src/ - -COPY package.json package-lock.json /src/ - -RUN npm ci --silent - -COPY . . - -FROM node:20.11-alpine3.18 as dev - -WORKDIR /src/ - -COPY --from=build /src/node_modules node_modules - -USER node - -CMD npm run start \ No newline at end of file diff --git a/app/docker-compose.yml b/app/docker-compose.yml deleted file mode 100644 index 47592a5..0000000 --- a/app/docker-compose.yml +++ /dev/null @@ -1,29 +0,0 @@ -version: "3.5" - -services: - api01-test: - hostname: api01 - build: . - environment: - DB_HOST: mongodb - DB_NAME: customers - ports: - - "9999:9999" - # command: npm run test - command: npm run test:dev - volumes: - - .:/src - - nodemodules:/src/node_modules - depends_on: - - mongodb - - mongodb: - image: mongo - ports: - - 27017:27017 - environment: - MONGO_INITDB_ROOT_USERNAME: root - MONGO_INITDB_ROOT_PASSWORD: example - -volumes: - nodemodules: {} diff --git a/app/package-lock.json b/app/package-lock.json index d7e6669..55657c4 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -12,8 +12,11 @@ "fastify": "^4.26.1", "mongodb": "^6.7.0" }, + "bin": { + "ew-test-runner": "test-runner/bin/index.js" + }, "engines": { - "node": "v20.11.0" + "node": "v20.12.1" } }, "node_modules/@fastify/ajv-compiler": { diff --git a/app/package.json b/app/package.json index b46311b..e6e701c 100644 --- a/app/package.json +++ b/app/package.json @@ -3,10 +3,13 @@ "version": "0.0.1", "description": "", "main": "index.js", + "bin": { + "ew-test-runner": "./../test-runner/bin/index.js" + }, "scripts": { "start": "DB_NAME=customers node src/index.js", "dev": "DB_NAME=customers node --watch src/index.js", - "test": "NODE_ENV=test node ./../test-runner/bin/index.js --test test/", + "test": "NODE_ENV=test ew-test-runner --test test/", "test:dev": "NODE_ENV=test node --watch ./../test-runner/bin/index.js --test test/", "test:debug": "NODE_ENV=test node --watch --inspect ./../test-runner/bin/index.js --test test/", "seed": "node src/db-seed/seed.js" diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..adf721e --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,13 @@ +version: "3.5" + +services: + mongodb: + image: mongo + ports: + - 27017:27017 + environment: + MONGO_INITDB_ROOT_USERNAME: root + MONGO_INITDB_ROOT_PASSWORD: example + +volumes: + nodemodules: {}