Skip to content

Commit

Permalink
Add deployement
Browse files Browse the repository at this point in the history
  • Loading branch information
flemzord committed Jul 8, 2021
1 parent 3a168d4 commit 41a56e4
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
41 changes: 41 additions & 0 deletions .github/deploy_ecs_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env python3
from os import environ as ENV
import sys
import boto3
import json
import subprocess


class bcolors:
HEADER = "\033[95m"
OKBLUE = "\033[94m"
OKCYAN = "\033[96m"
OKGREEN = "\033[92m"
WARNING = "\033[93m"
FAIL = "\033[91m"
ENDC = "\033[0m"
BOLD = "\033[1m"
UNDERLINE = "\033[4m"


def get_ecs_service(cluster_name, tag):
ecs = boto3.client("ecs")

# Get Latest TaskDef
ecs_services = ecs.list_services(
cluster=cluster_name,
)["serviceArns"]

for svc in ecs_services:
service_name = svc.replace(
"arn:aws:ecs:eu-west-1:496288716344:service/", ""
).replace(cluster_name + "/", "")
print(f"{bcolors.OKGREEN}: Start to deploy {service_name} with {tag}")
process = subprocess.Popen(f"ecs deploy {cluster_name} {service_name} --tag {tag}", shell=True, stdout=subprocess.PIPE)
process.wait()

return "true"


if __name__ == "__main__":
get_ecs_service(sys.argv[1], sys.argv[2])
11 changes: 11 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ jobs:
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: "eu-west-1"
AWS_ECS_CLUSTER: "numary-preprod-ecs"
steps:
- uses: actions/setup-go@v2
with:
go-version: '1.16'
- uses: actions/setup-python@v2
with:
python-version: '3.9'
- uses: actions/checkout@v2
- name: Configure git for private modules
env:
Expand Down Expand Up @@ -65,3 +70,9 @@ jobs:
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:latest .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
- name: Deploy new version in ECS
env:
IMAGE_TAG: ${{ github.sha }}
run: |
pip install ecs-deploy boto3
python .github/deploy_ecs_service.py $AWS_ECS_CLUSTER $IMAGE_TAG
13 changes: 13 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@ jobs:
env:
GOOS: linux
GOARCH: ${{ matrix.arch }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: "eu-west-1"
AWS_ECS_CLUSTER: "numary-prod-ecs"
steps:
- uses: actions/setup-go@v2
with:
go-version: '1.16'
- uses: actions/setup-python@v2
with:
python-version: '3.9'
- uses: actions/checkout@v2
- name: Configure git for private modules
env:
Expand Down Expand Up @@ -64,3 +71,9 @@ jobs:
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:latest .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
- name: Deploy new version in ECS
env:
IMAGE_TAG: ${{ steps.get_release.outputs.tag_name }}
run: |
pip install ecs-deploy boto3
python .github/deploy_ecs_service.py $AWS_ECS_CLUSTER $IMAGE_TAG

0 comments on commit 41a56e4

Please sign in to comment.