Skip to content
Open

v2 #5

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
2322b4b
init
geekwhocodes Jul 5, 2023
204b8c7
add wf
geekwhocodes Jul 5, 2023
2f6512c
wf
geekwhocodes Jul 5, 2023
0ba85c5
fix
geekwhocodes Jul 5, 2023
7d47513
Update deploy-dev.yaml
geekwhocodes Jul 5, 2023
c508b3c
fix task def
geekwhocodes Jul 5, 2023
aab5fa2
fix wf
geekwhocodes Jul 5, 2023
9d75084
fix env
geekwhocodes Jul 5, 2023
9562da4
fix workflow
geekwhocodes Jul 5, 2023
d03c0f8
fix wf
geekwhocodes Jul 5, 2023
a57a0d9
extra
geekwhocodes Jul 5, 2023
f6ce5dc
add slim support
geekwhocodes Jul 5, 2023
64d0251
fix path
geekwhocodes Jul 5, 2023
456b254
fix
geekwhocodes Jul 5, 2023
c5f8153
scripted install slim
geekwhocodes Jul 5, 2023
cb200a4
fix slim install
geekwhocodes Jul 5, 2023
2fe3a8f
fix bin name
geekwhocodes Jul 5, 2023
029b8ec
fix tag name
geekwhocodes Jul 5, 2023
fe7d5c6
setup test
geekwhocodes Jul 5, 2023
c72823d
fix wf
geekwhocodes Jul 5, 2023
c701e2b
fix wf
geekwhocodes Jul 5, 2023
3700ed2
run local postgres
geekwhocodes Jul 5, 2023
877b6ee
cov comment
geekwhocodes Jul 5, 2023
a4aa83b
run service
geekwhocodes Jul 5, 2023
b446793
fix poetry version
geekwhocodes Jul 5, 2023
eec6ee6
fix poetry install
geekwhocodes Jul 5, 2023
ed5d50e
fix poetry c
geekwhocodes Jul 5, 2023
208eafb
fix pytest script
geekwhocodes Jul 5, 2023
e77aa70
fix mock env
geekwhocodes Jul 5, 2023
33f863d
fix postgres host
geekwhocodes Jul 5, 2023
bf7fb7e
dc
geekwhocodes Jul 5, 2023
73327c7
sdaefel
geekwhocodes Jul 5, 2023
f7e21cb
vxc,mbn
geekwhocodes Jul 5, 2023
f04323f
sddg;k
geekwhocodes Jul 5, 2023
250c614
sfgdsf
geekwhocodes Jul 5, 2023
8110f9c
zz
geekwhocodes Jul 5, 2023
7f098ef
m li08350
geekwhocodes Jul 5, 2023
21bf4bd
fx,.gnl
geekwhocodes Jul 5, 2023
5fbb399
zxzxz
geekwhocodes Jul 5, 2023
883036f
zxxccc
geekwhocodes Jul 5, 2023
1426698
fix image name
geekwhocodes Jul 5, 2023
9daf68a
fix
geekwhocodes Jul 5, 2023
dab8d87
x,gn
geekwhocodes Jul 5, 2023
615a21d
fgkj
geekwhocodes Jul 5, 2023
6c0e5cb
xc,gkhj
geekwhocodes Jul 5, 2023
67667b8
sdf.
geekwhocodes Jul 5, 2023
5666147
sdf,fm
geekwhocodes Jul 5, 2023
f8c30b3
x/fgk
geekwhocodes Jul 5, 2023
952de88
commc
geekwhocodes Jul 5, 2023
c517198
zxdfnv 09
geekwhocodes Jul 6, 2023
9f041c9
mnkuyd
geekwhocodes Jul 6, 2023
0541880
aeilet8hy
geekwhocodes Jul 6, 2023
d675cbd
xxxczzc
geekwhocodes Jul 6, 2023
def3d7b
zzzzzzzzzzz
geekwhocodes Jul 6, 2023
e94f98e
ooooooooooooooo
geekwhocodes Jul 6, 2023
4722014
1111112
geekwhocodes Jul 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .aws/task-definition.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"family": "dopalizer",
"containerDefinitions": [
{
"name": "dopalizer_api",
"image": "380617998106.dkr.ecr.us-east-1.amazonaws.com/opalizer:dopalizer-slim",
"cpu": 0,
"portMappings": [
{
"name": "dopalizer-api-8000-tcp",
"containerPort": 80,
"hostPort": 80,
"protocol": "tcp",
"appProtocol": "http"
}
],
"essential": true,
"environment": [],
"mountPoints": [],
"volumesFrom": [],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-create-group": "true",
"awslogs-group": "ecs/dopalizer-logs",
"awslogs-region": "us-east-1",
"awslogs-stream-prefix": "ecs"
}
}
}
],
"taskRoleArn": "arn:aws:iam::380617998106:role/ecsTaskExecutionRole",
"executionRoleArn": "arn:aws:iam::380617998106:role/ecsTaskExecutionRole",
"networkMode": "awsvpc",
"requiresCompatibilities": [
"FARGATE"
],
"cpu": "1024",
"memory": "2048",
"runtimePlatform": {
"cpuArchitecture": "X86_64",
"operatingSystemFamily": "LINUX"
}
}
189 changes: 189 additions & 0 deletions .github/workflows/deploy-dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@


name: Deploy

on:
workflow_dispatch:
inputs:
environment:
description: "environment name [dev, test, prod]"
default: "dev"
version:
description: "version [follow semver]"

env:
AWS_REGION: ${{ vars.AWS_REGION }} # set this to your preferred AWS region, e.g. us-west-1
ECR_REPOSITORY: ${{ vars.ECR_REPOSITORY }} # set this to your Amazon ECR repository name
ECS_SERVICE: ${{ vars.ECS_SERVICE_NAME }} # set this to your Amazon ECS service name
ECS_CLUSTER: dopalizer_cluster # set this to your Amazon ECS cluster name
ECS_TASK_DEFINITION: .aws/task-definition.json # set this to the path to your Amazon ECS task definition
# file, e.g. .aws/task-definition.json
CONTAINER_NAME: dopalizer_api # set this to the name of the container in the
# containerDefinitions section of your task definition

jobs:

build:
name: Build
runs-on: ubuntu-latest

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

- name: Install poetry
run: |
pipx install poetry==1.5.1
pip install flake8 pytest pytest-cov
# set-up python with cache
- name: Setup Python 3.10
uses: actions/setup-python@v4
with:
python-version: '3.10'
cache: 'poetry'
# install requirements (including dev dependencies)
- name: Install requirements
run: poetry install

- name: Run Lint
run: poetry run ruff .

# Replace with https://black.readthedocs.io/en/stable/integrations/github_actions.html
- name: Format Black
run: poetry run black ./opalizer tests --line-length=120

- name: Run Safety
run: #poetry run safety check --disable-optional-telemetry-data
echo "Skipping this step..."
test:
needs: build
name: Test
runs-on: ubuntu-latest

services:
# Label used to access the service container
postgres:
# Docker Hub image
image: postgres
# Provide the password for postgres
env:
POSTGRES_USER: usr
POSTGRES_PASSWORD: pass
ports:
- 5432:5432
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

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

- name: Install poetry
run: |
pipx install poetry==1.5.1
pip install flake8 pytest pytest-cov
# set-up python with cache
- name: Setup Python 3.10
uses: actions/setup-python@v4
with:
python-version: '3.10'
cache: 'poetry'
# install requirements (including dev dependencies)
- name: Install requirements
run: poetry install
# run unit tests
- name: Run unit-tests
run: poetry run pytest --junitxml=pytest.xml --cov-report=term-missing:skip-covered --cov=opalizer tests/ | tee pytest-coverage.txt
env:
OPALIZERENV : "test"
OPALIZER_DB__HOST : "localhost"
OPALIZER_DB__NAME : "postgres"
OPALIZER_GMAPS_KEY : "test"
OPALIZER_DB__USERNAME : "usr"
OPALIZER_DB__PASSWORD : "pass"
OPALIZER_ADMIN__USERNAME : "admin"
OPALIZER_ADMIN__PASSWORD : "pass"
# add pytest coverage report to PR
- name: Pytest coverage comment
if: ${{ success() && github.event_name == 'pull_request' }}
id: coverageComment
uses: MishaKav/pytest-coverage-comment@main
with:
title: Coverage Report
pytest-coverage-path: pytest-coverage.txt
junitxml-path: pytest.xml
github-token: ${{ secrets.CODE_COMMC }}

deploy:
needs: test
name: Deploy - ${{ github.event.inputs.environment }} - ${{ github.event.inputs.version }}
runs-on: ubuntu-latest
environment: ${{ github.event.inputs.environment }}

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

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@0e613a0980cbf65ed5b322eb7a1e075d28913a83
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@62f4f872db3836360b72999f4b87f1ff13310f3a

- name: Install Docker Slim
id: install-docker-slim
run: |
curl -sL https://raw.githubusercontent.com/slimtoolkit/slim/master/scripts/install-slim.sh | sudo bash -
slim -v

- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.event.inputs.version }}
run: |
# curl -sL https://raw.githubusercontent.com/slimtoolkit/slim/master/scripts/install-slim.sh | sudo bash -
# docker-slim -v
# 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 .
slim build --target $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG --tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG-slim --env "OPALIZERENV=dev" --env "OPALIZER_GMAPS_KEY=es"
# docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG-slim
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG-slim" >> $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@c804dfbdd57f713b6c079302a4c01db7017a36fc
with:
task-definition: ${{ env.ECS_TASK_DEFINITION }}
container-name: ${{ env.CONTAINER_NAME }}
image: ${{ steps.build-image.outputs.image }}
environment-variables: |
OPALIZERENV='${{ github.event.inputs.environment }}'
OPALIZER_DB__HOST='${{ secrets.OPALIZER_DB__HOST }}'
OPALIZER_DB__NAME='${{ secrets.OPALIZER_DB__NAME }}'
OPALIZER_GMAPS_KEY='${{ secrets.OPALIZER_GMAPS_KEY }}'
OPALIZER_DB__USERNAME='${{ secrets.OPALIZER_DB__USERNAME }}'
OPALIZER_DB__PASSWORD='${{ secrets.OPALIZER_DB__PASSWORD }}'
OPALIZER_ADMIN__USERNAME='${{ secrets.OPALIZER_ADMIN__USERNAME }}'
OPALIZER_ADMIN__PASSWORD='${{ secrets.OPALIZER_ADMIN__PASSWORD }}'

- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@df9643053eda01f169e64a0e60233aacca83799a
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ env.ECS_SERVICE }}
cluster: ${{ env.ECS_CLUSTER }}
force-new-deployment: true
wait-for-service-stability: true
109 changes: 109 additions & 0 deletions .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@


name: Tests

on:
push:
branches:
- '*'
pull_request:
branches:
- '*'


jobs:

build:
name: Build
runs-on: ubuntu-latest

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

- name: Install poetry
run: |
pipx install poetry==1.5.1
pip install flake8 pytest pytest-cov
# set-up python with cache
- name: Setup Python 3.10
uses: actions/setup-python@v4
with:
python-version: '3.10'
cache: 'poetry'
# install requirements (including dev dependencies)
- name: Install requirements
run: poetry install

- name: Run Lint
run: poetry run ruff .

# Replace with https://black.readthedocs.io/en/stable/integrations/github_actions.html
- name: Format Black
run: poetry run black ./opalizer tests --line-length=120

- name: Run Safety
run: #poetry run safety check --disable-optional-telemetry-data
echo "Skipping this step..."
test:
needs: build
name: Test
runs-on: ubuntu-latest

services:
# Label used to access the service container
postgres:
# Docker Hub image
image: postgres
# Provide the password for postgres
env:
POSTGRES_USER: usr
POSTGRES_PASSWORD: pass
ports:
- 5432:5432
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

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

- name: Install poetry
run: |
pipx install poetry==1.5.1
pip install flake8 pytest pytest-cov
# set-up python with cache
- name: Setup Python 3.10
uses: actions/setup-python@v4
with:
python-version: '3.10'
cache: 'poetry'
# install requirements (including dev dependencies)
- name: Install requirements
run: poetry install
# run unit tests
- name: Run unit-tests
run: poetry run pytest --junitxml=pytest.xml --cov-report=term-missing:skip-covered --cov=opalizer tests/ | tee pytest-coverage.txt
env:
OPALIZERENV : "test"
OPALIZER_DB__HOST : "localhost"
OPALIZER_DB__NAME : "postgres"
OPALIZER_GMAPS_KEY : "test"
OPALIZER_DB__USERNAME : "usr"
OPALIZER_DB__PASSWORD : "pass"
OPALIZER_ADMIN__USERNAME : "admin"
OPALIZER_ADMIN__PASSWORD : "pass"
# add pytest coverage report to PR
- name: Pytest coverage comment
if: ${{ success() && github.event_name == 'pull_request' }}
id: coverageComment
uses: MishaKav/pytest-coverage-comment@main
with:
title: Coverage Report
pytest-coverage-path: pytest-coverage.txt
junitxml-path: pytest.xml
github-token: ${{ secrets.CODE_COMMC }}
Loading