Skip to content

Commit 91c3a88

Browse files
author
Eduardo
committed
chore: deploy code to ECR
1 parent d7e2a6e commit 91c3a88

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.env

.github/workflows/DeployApp.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Build and Deploy BackendApp to ECS
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
env:
9+
# Setting an environment variable with the value of a configuration variable
10+
ECR_IMAGE: ${{ vars.ECR_IMAGE }}
11+
AWS_DEFAULT_REGION: ${{ vars.AWS_DEFAULT_REGION }}
12+
jobs:
13+
deploy:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v2
19+
20+
- name: Set up QEMU for arm64
21+
run: |
22+
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
23+
if: runner.os == 'Linux'
24+
25+
- name: Set up Docker for arm64
26+
uses: docker/setup-qemu-action@v2
27+
with:
28+
platforms: linux/arm64
29+
30+
- name: Set up Docker
31+
uses: docker/setup-buildx-action@v3
32+
33+
- name: Configure AWS credentials
34+
uses: aws-actions/configure-aws-credentials@v2
35+
with:
36+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
37+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
38+
aws-region: sa-east-1
39+
40+
- name: Login to Amazon ECR
41+
run: |
42+
aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com
43+
44+
- name: Build and push Docker image
45+
run: |
46+
docker buildx create --use
47+
docker buildx inspect --bootstrap
48+
docker buildx build --platform linux/arm64 -t ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$ECR_IMAGE:latest --push .
49+
50+
- name: Deploy to ECS
51+
uses: imehedi/actions-awscli-v2@latest
52+
with:
53+
args: ecs update-service --cluster MpcsjNestJSStabilityIntegration --service MpcsjStabilityAPI --force-new-deployment
54+
env:
55+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
56+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
57+
AWS_DEFAULT_REGION: 'sa-east-1'

Dockerfile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# use in local to create db container
2+
# version: '3.8'
3+
4+
# services:
5+
# postgres:
6+
# container_name: 'chaxis'
7+
# image: postgres:latest
8+
# ports:
9+
# - '5432:5432'
10+
# environment:
11+
# POSTGRES_USER: chaxis
12+
# POSTGRES_PASSWORD: root
13+
# POSTGRES_DB: chaxis
14+
# PGDATA: /data/postgres
15+
# volumes:
16+
# - ./data/pg:/data/postgres
17+
18+
# -----------------------------------------------------
19+
20+
# Use an official Node.js runtime as a parent image
21+
FROM node:18-alpine AS builder
22+
23+
# Set the working directory
24+
WORKDIR /app
25+
26+
# Copy package.json and package-lock.json (or yarn.lock) before other files
27+
# Leverage Docker cache to save time on dependency installation
28+
COPY package*.json ./
29+
COPY package-lock.lock ./
30+
31+
# Install dependencies
32+
RUN npm run install
33+
34+
# Copy the rest of your application code to the container
35+
COPY . .
36+
37+
# Build the NestJS application
38+
RUN npm run prebuild
39+
RUN npm run build
40+
41+
# Expose the port that your NestJS app runs on
42+
EXPOSE 3000
43+
44+
# Define the command to run your app
45+
CMD ["node", "dist/src/main"]

0 commit comments

Comments
 (0)