-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #190 from ZIFODS/183-deploy-with-terraform
183 deploy with terraform
- Loading branch information
Showing
9 changed files
with
202 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import json | ||
|
||
import boto3 | ||
|
||
|
||
def get_secret(secret_name: str, aws_region: str, aws_kms_key: str): | ||
# Create a Secrets Manager client | ||
session = boto3.session.Session() | ||
client = session.client(service_name="secretsmanager", region_name=aws_region) | ||
|
||
get_secret_value_response = client.get_secret_value(SecretId=secret_name) | ||
|
||
return json.loads(get_secret_value_response[aws_kms_key]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,24 @@ | ||
FROM python:3.10 as base | ||
FROM python:3.10-slim as base | ||
LABEL maintainer="Joseph Smith" | ||
LABEL version="0.1.0" | ||
LABEL description="FastAPI server for Zifo Skills Tracker" | ||
|
||
ENV PYTHONDONTWRITEBYTECODE=1 \ | ||
PYTHONUNBUFFERED=1 | ||
|
||
# Install wget for health check | ||
RUN apt-get -y update && apt-get -y install wget | ||
|
||
# Configure Poetry | ||
ENV POETRY_VERSION=1.2.2 | ||
ENV POETRY_HOME=/opt/poetry | ||
ENV POETRY_VENV=/opt/poetry-venv | ||
ENV POETRY_CACHE_DIR=/opt/.cache | ||
|
||
# Create and switch to a new user | ||
RUN useradd --create-home skills-user | ||
WORKDIR /home/skills-user | ||
WORKDIR /app | ||
|
||
# Install poetry separated from system interpreter | ||
RUN python3 -m venv $POETRY_VENV \ | ||
&& $POETRY_VENV/bin/pip install -U pip setuptools \ | ||
&& $POETRY_VENV/bin/pip install poetry==${POETRY_VERSION} | ||
RUN pip install poetry | ||
|
||
# Add `poetry` to PATH | ||
ENV PATH="${PATH}:${POETRY_VENV}/bin" | ||
COPY pyproject.toml . | ||
|
||
# Install dependencies | ||
COPY ./pyproject.toml ./pyproject.toml | ||
RUN poetry install --without dev | ||
RUN poetry install | ||
|
||
# Copy source code | ||
COPY ./app ./app | ||
|
||
# Run the server | ||
EXPOSE 8080 | ||
RUN mkdir ./data | ||
|
||
CMD ["poetry", "run", "hypercorn", "app.main:app", "--reload", "--bind", "0.0.0.0:8080"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/bash | ||
|
||
AWS_ACCOUNT_ID="233044492909" | ||
AWS_REGION="eu-west-2" | ||
|
||
# Frontend | ||
ECR_REPO_NAME_FRONTEND="skills-tracker-frontend" | ||
ECR_REPO_URI_FRONTEND="$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$ECR_REPO_NAME_FRONTEND" | ||
|
||
docker build -t "$ECR_REPO_URI_FRONTEND:latest" -f docker/frontend/Dockerfile . | ||
|
||
# API | ||
ECR_REPO_NAME_API="skills-tracker-api" | ||
ECR_REPO_URI_API="$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$ECR_REPO_NAME_API" | ||
|
||
docker build -t "$ECR_REPO_URI_API:latest" -f docker/api/Dockerfile . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Install DVC | ||
sudo wget \ | ||
https://dvc.org/deb/dvc.list \ | ||
-O /etc/apt/sources.list.d/dvc.list | ||
wget -qO - https://dvc.org/deb/iterative.asc | gpg --dearmor > packages.iterative.gpg | ||
sudo install -o root -g root -m 644 packages.iterative.gpg /etc/apt/trusted.gpg.d/ | ||
rm -f packages.iterative.gpg | ||
sudo apt update | ||
sudo apt install dvc | ||
|
||
# Configure DVC | ||
dvc remote modify --local s3 credentialpath '~/.aws/credentials' | ||
dvc pull --recursive |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/bash | ||
|
||
AWS_ACCOUNT_ID="233044492909" | ||
AWS_REGION="eu-west-2" | ||
|
||
# Frontend | ||
ECR_REPO_NAME_FRONTEND="skills-tracker-frontend" | ||
ECR_REPO_URI_FRONTEND="$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$ECR_REPO_NAME_FRONTEND" | ||
|
||
aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$ECR_REPO_NAME_FRONTEND | ||
|
||
docker push "$ECR_REPO_URI_FRONTEND:latest" | ||
|
||
# API | ||
ECR_REPO_NAME_API="skills-tracker-api" | ||
ECR_REPO_URI_API="$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$ECR_REPO_NAME_API" | ||
|
||
aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$ECR_REPO_NAME_API | ||
|
||
docker push "$ECR_REPO_URI_API:latest" |