Skip to content

Commit

Permalink
Merge pull request #1 from nuitee-white-label/feat-ecs
Browse files Browse the repository at this point in the history
[WIP] Deploy to ECS
  • Loading branch information
squallstar authored Feb 29, 2024
2 parents 6098755 + b38281c commit 95cee8c
Show file tree
Hide file tree
Showing 12 changed files with 646 additions and 4,153 deletions.
27 changes: 27 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
### Product areas affected

List the product areas affected.

### What does this PR do?

Describe in a couple of sentence what this PR adds or fixes.

### Ticket with product and technical specifications

Link to ClickUp ticket (if any)

### Result

Add any relevant sample input/output, screenshots or screen recordings.

### Checklist

- [ ] Added automated test coverage as appropriate for this change.

### Deployment instructions

List any deployment and post-deployment instructions.

### Author concerns

List any concerns about this PR - inelegant solutions, hacks, quick-and-dirty implementations, concerns about migrations, etc.
79 changes: 79 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Deployment

on:
push:
branches:
- main

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest

env:
AWS_ACCOUNT_ID: "021748665536"
AWS_REGION: us-east-1
CLUSTER: whitelabel-production-Cluster-iao5D0kITy8m
SERVICE_APP: whitelabel-production-room-mapping-Service-RmZCtsT9LuYd
TASK_APP: whitelabel-production-room-mapping
CONTAINER_APP: room-mapping

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
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: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

- name: Build, tag, and push image to Amazon ECR
id: build-image-app
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: whitelabel/${{ env.CONTAINER_APP }}
IMAGE_TAG: ${{ github.sha }}
run: |
# Build a docker container and
# push it to ECR so that it can
# be deployed to ECS.
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG ./
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
- name: Get current task definition
run: >
aws ecs describe-task-definition
--task-definition "arn:aws:ecs:${{ env.AWS_REGION }}:${{ env.AWS_ACCOUNT_ID }}:task-definition/${{ env.TASK_APP }}" --region "${{ env.AWS_REGION }}" --query 'taskDefinition'
> task-definition-app.json
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def-app
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: task-definition-app.json
container-name: ${{ env.CONTAINER_APP }}
image: ${{ steps.build-image-app.outputs.image }}

- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def-app.outputs.task-definition }}
service: ${{ env.SERVICE_APP }}
cluster: ${{ env.CLUSTER }}
wait-for-service-stability: true

- name: Invalidate CDN cache
uses: chetan/invalidate-cloudfront-action@v2
env:
DISTRIBUTION: E3ODYW9N91DQLZ
PATHS: "/*"
AWS_REGION: "us-east-1"
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM --platform=linux/amd64 public.ecr.aws/docker/library/node:18-alpine
LABEL maintainer="Oussama Tali <o.tali@nuitee.com>"

# Install OS dependencies
RUN apk add --no-cache curl zsh git emacs vim;

# https://github.com/nodejs/docker-node/blob/main/docs/BestPractices.md#global-npm-dependencies
ENV NPM_CONFIG_PREFIX=/home/node/.npm-global
ENV PATH=$PATH:/home/node/.npm-global/bin

# Create app directory
WORKDIR /usr/src/app

# Copy app source
COPY . /usr/src/app

EXPOSE 8080

# Build the backend
RUN npm install

# Run the app
CMD [ "npm", "run", "start" ]
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Room Matching API

## Start for development

```
docker compose up
```

---

## Deploy

```
copilot svc deploy
```
Empty file removed __VLS_types.d.ts
Empty file.
1 change: 1 addition & 0 deletions copilot/.workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
application: whitelabel
47 changes: 47 additions & 0 deletions copilot/room-mapping/manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# The manifest for the "room-mapping" service.
# Read the full specification for the "Load Balanced Web Service" type at:
# https://aws.github.io/copilot-cli/docs/manifest/lb-web-service/

# Your service name will be used in naming your resources like log groups, ECS services, etc.
name: room-mapping
type: Load Balanced Web Service

# Distribute traffic to your service.
http:
redirect_to_https: false
# Requests to this path will be forwarded to your service.
# To match all requests you can use the "/" path.
path: '/'
# You can specify a custom health check path. The default is "/".
# healthcheck: '/'

# Configuration for your containers and service.
image:
# Docker build arguments. For additional overrides: https://aws.github.io/copilot-cli/docs/manifest/lb-web-service/#image-build
build: Dockerfile
# Port exposed through your container to route traffic to it.
port: 8080

cpu: 256 # Number of CPU units for the task.
memory: 512 # Amount of memory in MiB used by the task.
platform: linux/x86_64 # See https://aws.github.io/copilot-cli/docs/manifest/lb-web-service/#platform
count: 1 # Number of tasks that should be running in your service.
exec: true # Enable running commands in your container.
network:
connect: true # Enable Service Connect for intra-environment traffic between services.

# storage:
# readonly_fs: true # Limit to read-only access to mounted root filesystems.

# Optional fields for more advanced use-cases.
#
#variables: # Pass environment variables as key value pairs.
# LOG_LEVEL: info

#secrets: # Pass secrets from AWS Systems Manager (SSM) Parameter Store.
# GITHUB_TOKEN: GITHUB_TOKEN # The key is the name of the environment variable, the value is the name of the SSM parameter.

environments:
production:
http:
alias: room-mapping.wlbl.cloud
17 changes: 17 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: "3.8"
services:
backend:
build: ./
volumes:
- .:/usr/src/app
networks:
- whitelabel
ports:
- 8080:8080

networks:
whitelabel:

volumes:
db:
driver: local
Loading

0 comments on commit 95cee8c

Please sign in to comment.