Skip to content

Commit

Permalink
deploy script
Browse files Browse the repository at this point in the history
  • Loading branch information
amirrr committed Jun 27, 2024
1 parent 17a400d commit f1e9c81
Show file tree
Hide file tree
Showing 15 changed files with 448 additions and 561 deletions.
41 changes: 41 additions & 0 deletions .aws/task-definition.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"family": "atlas-task-definition",
"containerDefinitions": [
{
"name": "atlas",
"image": "533266983284.dkr.ecr.us-east-1.amazonaws.com/atlas",
"cpu": 0,
"portMappings": [
{
"name": "atlas-container-port",
"containerPort": 8000,
"hostPort": 8000,
"protocol": "tcp",
"appProtocol": "http"
}
],
"essential": true,
"environment": [],
"environmentFiles": [],
"mountPoints": [],
"volumesFrom": [],
"ulimits": [],
"systemControls": []
}
],
"executionRoleArn": "arn:aws:iam::533266983284:role/ecsTaskExecutionRole",
"networkMode": "awsvpc",
"requiresCompatibilities": ["FARGATE"],
"cpu": "1024",
"memory": "3072",
"runtimePlatform": {
"cpuArchitecture": "X86_64",
"operatingSystemFamily": "LINUX"
},
"tags": [
{
"key": "project",
"value": "atlas"
}
]
}
168 changes: 168 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
# config files
.github/
.husky/
.jest/
.vscode/
.editorconfig
.eslintrc
.git
.gitignore
.prettierignore
.prettierrc
.releaserc
Dockerfile
docker-compose.yml
Jenkinsfile
jest.config.js

# documentation
LICENSE
CHANGELOG.md
README.md

# build files
node_modules
**/node_modules

.git
Dockerfile
.DS_Store
.gitignore
.dockerignore

/credentials
/cache
/store

/node_modules

# https://github.com/github/gitignore/blob/master/Global/macOS.gitignore

# General
*.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

# https://raw.githubusercontent.com/github/gitignore/master/Python.gitignore

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
67 changes: 67 additions & 0 deletions .github/workflows/aws-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Deploy to Amazon ECS

on:
push:
branches: ["main"]

env:
AWS_REGION: us-east-1 # AWS region, e.g. us-west-1
ECR_REPOSITORY: atlas # Amazon ECR repository name
ECS_SERVICE: atlas-service # Amazon ECS service name
ECS_CLUSTER: atlas-cluster # Amazon ECS cluster name
ECS_TASK_DEFINITION: .aws/task-definition.json # Amazon ECS task definition
CONTAINER_NAME: atlas

permissions:
id-token: write
contents: read

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

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

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_PROD_ID }}
aws-secret-access-key: ${{ secrets.AWS_PROD_KEY }}
aws-region: us-east-1

- 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
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
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 --build-arg GITHUB_HASH=${GITHUB_SHA::7} --build-arg GITHUB_BRANCH=${GITHUB_REF_NAME} .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: ${{ env.ECS_TASK_DEFINITION }}
container-name: ${{ env.CONTAINER_NAME }}
image: ${{ steps.build-image.outputs.image }}

- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ env.ECS_SERVICE }}
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@
},
"[github-actions-workflow]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[dockerfile]": {
"editor.defaultFormatter": "ms-azuretools.vscode-docker"
}
}
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Build step #1: build the React front end
FROM node:18-alpine as build-step
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY client/package*.json ./
RUN npm ci
COPY client/ ./
RUN npm run build

# Build step #2: build the API with the client as static files
FROM python:3.9
WORKDIR /app
COPY --from=build-step /app/dist ./build

RUN mkdir ./api
COPY server ./api
RUN pip install -r ./api/requirements.txt
RUN pip install gunicorn
ENV FLASK_ENV production


EXPOSE 8000
WORKDIR /app/api
CMD ["gunicorn", "-b", ":8000", "api:app"]
3 changes: 2 additions & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,6 @@
"description": "tool for exploring scientific litreture ",
"main": "postcss.config.js",
"author": "A.Nakhaei",
"license": "ISC"
"license": "ISC",
"proxy": "http://localhost:8000"
}
2 changes: 1 addition & 1 deletion client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function App() {
<SocketProvider>
<Routes>
<Route path='/' element={<Home />} />
<Route path='/login/:magicLink' element={<Home loggingIn={true} />} />
<Route path='/login/:email/:magicLink' element={<Home loggingIn={true} />} />
<Route path='/dashboard' element={<Dashboard />} />
<Route path='/table' element={<Table />} />
<Route path='/test' element={<ArrageTable />} />
Expand Down
1 change: 1 addition & 0 deletions client/src/icons/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit f1e9c81

Please sign in to comment.