Skip to content

Commit

Permalink
Merge pull request #5 from arakakimath/integration-layer
Browse files Browse the repository at this point in the history
first deploy to main
  • Loading branch information
arakakimath authored Feb 25, 2025
2 parents c01a5ed + 200a1fb commit f2fe0e6
Show file tree
Hide file tree
Showing 46 changed files with 18,536 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
node_modules
dist
Dockerfile
.git
.dockerignore
.gitignore
client.http
.eslintignore
.eslintrc.json
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DATABASE_URL="mongodb://mongodb:docker@localhost:27017/order-logistics?authSource=admin"
PORT=3333
1 change: 1 addition & 0 deletions .env.test.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NODE_ENV="test"
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
27 changes: 27 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"extends": [
"@rocketseat/eslint-config/node"
//"plugin:vitest-globals/recommended"
],

"rules": {
"prettier/prettier": [
"error",
{
"endOfLine": "crlf",
"printWidth": 80,
"tabWidth": 2,
"singleQuote": true,
"trailingComma": "all",
"arrowParens": "always",
"semi": false
}
],
"camelcase": "off",
"no-useless-constructor": "off",
"no-new": "off"
}
// "env": {
// "vitest-globals/env": true
// }
}
78 changes: 78 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: CI

on:
push:
branches:
- main

permissions:
id-token: write
contents: write
issues: write
pull-requests: write

jobs:
build:
name: 'Build and Push'
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup node
uses: actions/setup-node@v4
with:
node-version: 22
cache: 'npm'
- run: npm ci
- run: npm test

- name: Semantic Release
uses: cycjimmy/semantic-release-action@v4
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}

- name: Generate tag
id: generate-tag
run: |
SHA=$(echo $GITHUB_SHA | head -c7)
echo "sha=$SHA" >> $GITHUB_OUTPUT
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_LOGIN_ROLE }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

- name: Build docker image
id: build-docker-image
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
TAG: ${{ steps.generate-tag.outputs.sha }}
run: |
docker build -t $REGISTRY/arakakimath-ci:$TAG .
docker push $REGISTRY/arakakimath-ci:$TAG
docker tag $REGISTRY/arakakimath-ci:$TAG $REGISTRY/arakakimath-ci:latest
docker push $REGISTRY/arakakimath-ci:latest
IMAGE=$(echo $REGISTRY/arakakimath-ci:$TAG)
echo "image=$IMAGE" >> $GITHUB_OUTPUT
- name: Deploy to App Runner
id: deploy-app-runner
uses: awslabs/amazon-app-runner-deploy@main
with:
service: arakakimath-api
image: ${{ steps.build-docker-image.outputs.image }}
access-role-arn: ${{ secrets.AWS_APPRUNNER_ROLE_ARN }}
region: ${{ secrets.AWS_REGION }}
cpu: 0.5
memory: 1
port: 3000
wait-for-service-stability-seconds: 180

- name: App Runner check
run: echo "App Runner running... ${{ steps.deploy-app-runner.outputs.service-url }}"
36 changes: 36 additions & 0 deletions .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Run Tests

on:
push:
branches:
- integration-layer

jobs:
run-tests:
name: Run Tests
runs-on: ubuntu-latest

services:
mongo:
image: mongo:latest
ports:
- 27017:27017
env:
MONGO_INITDB_ROOT_USERNAME: docker
MONGO_INITDB_ROOT_PASSWORD: docker
MONGO_INITDB_DATABASE: order-logistics-api

steps:
- uses: actions/checkout@v4

- name: Setup node
uses: actions/setup-node@v4
with:
node-version: 22
cache: 'npm'
- run: npm ci
- run: npm test
- run: npm run test:e2e
env:
DATABASE_URL: "mongodb://docker:docker@localhost:27017/order-logistics-api?authSource=admin"
NODE_ENV: "test"
60 changes: 60 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# compiled output
/dist
/node_modules
/build

# Logs
logs
*.log
npm-debug.log*
pnpm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# OS
.DS_Store

# Tests
/coverage
/.nyc_output

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# dotenv environment variable files
.env
.env.test
.env.development.local
.env.test.local
.env.production.local
.env.local

# temp directory
.temp
.tmp

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Database
data
22 changes: 22 additions & 0 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"branches": [
"main"
],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
[
"@semantic-release/changelog",
{
"changelogFile": "CHANGELOG.md"
}
],
[
"@semantic-release/git",
{
"assets": [ "CHANGELOG.md" ]
}
],
"@semantic-release/github"
]
}
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM node:22 AS build

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install

COPY . .

RUN npm run build
RUN npm ci --production && npm cache clean --force

FROM node:22-alpine3.21

WORKDIR /usr/src/app

COPY --from=build /usr/src/app/package.json ./package.json
COPY --from=build /usr/src/app/dist ./dist
COPY --from=build /usr/src/app/node_modules ./node_modules

EXPOSE 3333

CMD ["npm", "run", "start:prod"]
17 changes: 17 additions & 0 deletions client.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@baseUrl = https://localhost:3333

# @name create_user
POST {{baseUrl}}/users
Content-Type: application/json

{
"name": "Matheus Arakaki",
"cpf": "123.456.789-00",
"password": "123457"
}

###

# @name get_user
GET {{baseUrl}}/users
Content-Type: application/json
7 changes: 7 additions & 0 deletions conf/mongod.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Configuration to prevent flooding logs from mongodb

systemLog:
destination: file
path: /var/log/mongodb/mongod.log
logAppend: true
verbosity: 1
30 changes: 30 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
services:
mongo:
image: mongo:7.0
container_name: mongo
environment:
MONGO_INITDB_ROOT_USERNAME: mongodb
MONGO_INITDB_ROOT_PASSWORD: docker
MONGO_INITDB_DATABASE: order-logistics
ports:
- 27017:27017
volumes:
- db:/data/db
- ./conf:/etc/mongo
command: ["mongod", "--config", "/etc/mongo/mongod.conf"]

order-logistics-api:
container_name: order-logistics-api
build:
context: .
ports:
- 3333:3333
depends_on:
- mongo
environment:
- DATABASE_URL=mongodb://mongodb:docker@mongo:27017/order-logistics?authSource=admin
- PORT=3333

volumes:
db:
name: mongo_data
8 changes: 8 additions & 0 deletions nest-cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"deleteOutDir": true
}
}
Loading

0 comments on commit f2fe0e6

Please sign in to comment.