Skip to content

Commit

Permalink
Docker setup with ECR and GitHub actions
Browse files Browse the repository at this point in the history
  • Loading branch information
csuvajit committed Sep 18, 2023
1 parent 04ef851 commit 29ad7a9
Show file tree
Hide file tree
Showing 23 changed files with 205 additions and 35 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/aws-ecr-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: CD/ECR

on:
push:
branches:
- main
workflow_dispatch:

env:
AWS_REGION: us-east-1

jobs:
build:
name: ECR

strategy:
matrix:
service: [service-app, service-capital, service-clans, service-wars]

runs-on: buildjet-4vcpu-ubuntu-2204-arm

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}

- name: Get ECR Registry
id: ecr-login
uses: aws-actions/amazon-ecr-login@v1

- name: Login to ECR
uses: docker/login-action@v1
with:
registry: ${{ steps.ecr-login.outputs.registry }}

- name: Set up Docker Buildkit
uses: docker/setup-buildx-action@v2
with:
buildkitd-flags: --debug

- name: Get Tags for Image
id: metadata
uses: docker/metadata-action@v3
with:
images: ${{ steps.ecr-login.outputs.registry }}/${{ matrix.service }}
tags: |
type=raw,value=latest
- name: Docker Build, Tag and Push to ECR
uses: docker/build-push-action@v2
with:
context: .
platforms: linux/arm64
push: true
tags: ${{ steps.metadata.outputs.tags }}
build-args: GIT_SHA=${{ github.sha }},SERVICE_NAME=${{ matrix.service }}
25 changes: 25 additions & 0 deletions .github/workflows/eslint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: CI/CD

on:
push:
pull_request:

jobs:
lint:
name: ESLint
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Use Node.js 18
uses: actions/setup-node@v3
with:
node-version: 18

- name: NPM Install
run: npm ci

- name: Run ESLint
run: npm run lint
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import * as request from 'supertest';
import { AppModule } from './../src/app.module';
import { AppModule } from '../src/app.module';

describe('AppController (e2e)', () => {
let app: INestApplication;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"extends": "../../tsconfig.json",
"compilerOptions": {
"declaration": false,
"outDir": "../../dist/apps/service-cron"
"outDir": "../../dist/apps/service-app"
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist", "test", "**/*spec.ts"]
Expand Down
5 changes: 1 addition & 4 deletions apps/service-capital/test/app.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ describe('ServiceCapitalController (e2e)', () => {
});

it('/ (GET)', () => {
return request(app.getHttpServer())
.get('/')
.expect(200)
.expect('Hello World!');
return request(app.getHttpServer()).get('/').expect(200).expect('Hello World!');
});
});
5 changes: 1 addition & 4 deletions apps/service-clans/test/app.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ describe('ServiceClansController (e2e)', () => {
});

it('/ (GET)', () => {
return request(app.getHttpServer())
.get('/')
.expect(200)
.expect('Hello World!');
return request(app.getHttpServer()).get('/').expect(200).expect('Hello World!');
});
});
5 changes: 1 addition & 4 deletions apps/service-wars/test/app.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ describe('ServiceWarsController (e2e)', () => {
});

it('/ (GET)', () => {
return request(app.getHttpServer())
.get('/')
.expect(200)
.expect('Hello World!');
return request(app.getHttpServer()).get('/').expect(200).expect('Hello World!');
});
});
55 changes: 55 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
version: '3.6'

services:
service-app:
image: 432159388664.dkr.ecr.us-east-1.amazonaws.com/service-app:latest
container_name: service-app
restart: always
# build:
# context: .
# dockerfile: Dockerfile
env_file:
- .env
mem_limit: 1gb
environment:
- SERVICE_NAME=service-app

service-capital:
image: 432159388664.dkr.ecr.us-east-1.amazonaws.com/service-capital:latest
container_name: service-capital
restart: always
# build:
# context: .
# dockerfile: Dockerfile
env_file:
- .env
mem_limit: 1gb
environment:
- SERVICE_NAME=service-capital

service-clans:
image: 432159388664.dkr.ecr.us-east-1.amazonaws.com/service-clans:latest
container_name: service-clans
restart: always
# build:
# context: .
# dockerfile: Dockerfile
env_file:
- .env
mem_limit: 1gb
environment:
- SERVICE_NAME=service-clans

service-wars:
image: 432159388664.dkr.ecr.us-east-1.amazonaws.com/service-wars:latest
container_name: service-wars
restart: always
# build:
# context: .
# dockerfile: Dockerfile
env_file:
- .env
mem_limit: 1gb
environment:
- SERVICE_NAME=service-app

7 changes: 2 additions & 5 deletions libs/elastic/src/elastic.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { Tokens } from '@app/constants';
import { Inject, Injectable } from '@nestjs/common';
import { Injectable } from '@nestjs/common';

@Injectable()
export class ElasticService {
constructor(@Inject(Tokens.ELASTIC) )
}
export class ElasticService {}
8 changes: 8 additions & 0 deletions libs/helper/src/helper.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Module } from '@nestjs/common';
import { HelperService } from './helper.service';

@Module({
providers: [HelperService],
exports: [HelperService],
})
export class HelperModule {}
4 changes: 4 additions & 0 deletions libs/helper/src/helper.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Injectable } from '@nestjs/common';

@Injectable()
export class HelperService {}
2 changes: 2 additions & 0 deletions libs/helper/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './helper.module';
export * from './helper.service';
9 changes: 9 additions & 0 deletions libs/helper/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"declaration": true,
"outDir": "../../dist/libs/helper"
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist", "test", "**/*spec.ts"]
}
28 changes: 19 additions & 9 deletions nest-cli.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "apps/service-cron/src",
"sourceRoot": "apps/service-app/src",
"compilerOptions": {
"deleteOutDir": true,
"webpack": false,
"tsConfigPath": "apps/service-cron/tsconfig.app.json"
"tsConfigPath": "apps/service-app/tsconfig.app.json"
},
"generateOptions": {
"spec": false
"spec": false,
"flat": true
},
"monorepo": true,
"root": "apps/service-cron",
"root": "apps/service-app",
"projects": {
"service-cron": {
"service-app": {
"type": "application",
"root": "apps/service-cron",
"root": "apps/service-app",
"entryFile": "main",
"sourceRoot": "apps/service-cron/src",
"sourceRoot": "apps/service-app/src",
"compilerOptions": {
"tsConfigPath": "apps/service-cron/tsconfig.app.json"
"tsConfigPath": "apps/service-app/tsconfig.app.json"
}
},
"service-capital": {
Expand Down Expand Up @@ -102,6 +103,15 @@
"compilerOptions": {
"tsConfigPath": "libs/elastic/tsconfig.lib.json"
}
},
"helper": {
"type": "library",
"root": "libs/helper",
"entryFile": "index",
"sourceRoot": "libs/helper/src",
"compilerOptions": {
"tsConfigPath": "libs/helper/tsconfig.lib.json"
}
}
}
}
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "service-cron",
"name": "service-backend",
"version": "0.0.1",
"description": "",
"author": "",
Expand All @@ -11,13 +11,13 @@
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/apps/service-cron/main",
"start:prod": "node dist/apps/service-app/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./apps/service-cron/test/jest-e2e.json"
"test:e2e": "jest --config ./apps/service-app/test/jest-e2e.json"
},
"dependencies": {
"@elastic/elasticsearch": "^8.9.0",
Expand Down Expand Up @@ -83,7 +83,8 @@
"^@app/mongodb(|/.*)$": "<rootDir>/libs/mongodb/src/$1",
"^@app/redis(|/.*)$": "<rootDir>/libs/redis/src/$1",
"^@app/auth(|/.*)$": "<rootDir>/libs/auth/src/$1",
"^@app/elastic(|/.*)$": "<rootDir>/libs/elastic/src/$1"
"^@app/elastic(|/.*)$": "<rootDir>/libs/elastic/src/$1",
"^@app/helper(|/.*)$": "<rootDir>/libs/helper/src/$1"
}
}
}
8 changes: 7 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@
],
"@app/elastic/*": [
"libs/elastic/src/*"
]
],
"@app/helper": [
"libs/helper/src"
],
"@app/helper/*": [
"libs/helper/src/*"
],
}
}
}

0 comments on commit 29ad7a9

Please sign in to comment.