From cb555b56b30ad8ec1a013458533ec5326b705143 Mon Sep 17 00:00:00 2001 From: alexsanderp Date: Fri, 4 Feb 2022 10:18:37 -0300 Subject: [PATCH 1/6] Adding github workflow --- .github/workflows/deploy.yml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..82f0425 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,34 @@ +name: Deploy +on: + push: + branches: + - main + +jobs: + deploy: + runs-on: self-hosted + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Configure AWS Region + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-region: us-east-1 + + - name: Install AWS CLI + run: | + python3 -m pip install awscli + + - name: Login to AWS ECR + id: login_ecr + uses: aws-actions/amazon-ecr-login@v1 + + - name: Build, Tag, and Push Image to AWS ECR + env: + ECR_REGISTRY: ${{ steps.login_ecr.outputs.registry }} + ECR_REPOSITORY: microservices/maestro + IMAGE_TAG: latest + run: | + docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG From d92cd8d69e570b193a989eab0a224981d9e75c04 Mon Sep 17 00:00:00 2001 From: alexsanderp Date: Fri, 4 Feb 2022 10:20:45 -0300 Subject: [PATCH 2/6] Update CI/CD --- .github/workflows/deploy.yml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 82f0425..80cd6b4 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -2,6 +2,8 @@ name: Deploy on: push: branches: + - dev + - stg - main jobs: @@ -11,6 +13,16 @@ jobs: - name: Checkout uses: actions/checkout@v2 + - name: Extract Environment + shell: bash + run: | + if [ ${GITHUB_REF} == "refs/heads/main" ]; then + echo "##[set-output name=result;]$(echo "prd")" + else + echo "##[set-output name=result;]$(echo ${GITHUB_REF#refs/heads/})" + fi + id: extract_environment + - name: Configure AWS Region uses: aws-actions/configure-aws-credentials@v1 with: @@ -27,7 +39,7 @@ jobs: - name: Build, Tag, and Push Image to AWS ECR env: ECR_REGISTRY: ${{ steps.login_ecr.outputs.registry }} - ECR_REPOSITORY: microservices/maestro + ECR_REPOSITORY: microservices/maestro_${{ steps.extract_environment.outputs.result }} IMAGE_TAG: latest run: | docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . From 13081d21c43d48214a2798d5b447190a838bde19 Mon Sep 17 00:00:00 2001 From: alexsanderp Date: Fri, 4 Feb 2022 10:23:10 -0300 Subject: [PATCH 3/6] Update Dockerfile --- Dockerfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3b435f3..978e9e2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,12 @@ -FROM node:14 as packages -WORKDIR /packages +FROM node:14 as node_modules +WORKDIR /node_modules COPY package.json . RUN npm install -FROM node:alpine +FROM node:14-alpine WORKDIR /app COPY . /app/ -COPY --from=packages /packages/node_modules /app/node_modules +COPY --from=packages /node_modules /app/node_modules RUN npm run build EXPOSE 3333 ENTRYPOINT npm run start From ea79c4da590ba5d251382e4cdcc9e898b076a639 Mon Sep 17 00:00:00 2001 From: alexsanderp Date: Fri, 4 Feb 2022 10:25:05 -0300 Subject: [PATCH 4/6] Update Dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 978e9e2..13fd9e2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,7 @@ RUN npm install FROM node:14-alpine WORKDIR /app COPY . /app/ -COPY --from=packages /node_modules /app/node_modules +COPY --from=node_modules /node_modules /app/node_modules RUN npm run build EXPOSE 3333 ENTRYPOINT npm run start From 2229ef9f9db7cd222d2a52f653ba18ccfd3b8cb0 Mon Sep 17 00:00:00 2001 From: alexsanderp Date: Fri, 4 Feb 2022 10:50:08 -0300 Subject: [PATCH 5/6] Update Dockerfile --- .github/workflows/deploy.yml | 30 +++++++++++++++++------------- Dockerfile | 8 ++++---- docker-compose.yml | 28 ++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 17 deletions(-) create mode 100644 docker-compose.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 80cd6b4..b45a4f3 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -13,6 +13,19 @@ jobs: - name: Checkout uses: actions/checkout@v2 + - name: Install Docker Compose + run: | + python3 -m pip install docker-compose + + - name: Install AWS CLI + run: | + python3 -m pip install awscli + . + - name: Configure AWS Region + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-region: us-east-1 + - name: Extract Environment shell: bash run: | @@ -23,24 +36,15 @@ jobs: fi id: extract_environment - - name: Configure AWS Region - uses: aws-actions/configure-aws-credentials@v1 - with: - aws-region: us-east-1 - - - name: Install AWS CLI - run: | - python3 -m pip install awscli - - name: Login to AWS ECR id: login_ecr uses: aws-actions/amazon-ecr-login@v1 - name: Build, Tag, and Push Image to AWS ECR env: - ECR_REGISTRY: ${{ steps.login_ecr.outputs.registry }} - ECR_REPOSITORY: microservices/maestro_${{ steps.extract_environment.outputs.result }} IMAGE_TAG: latest + ENV: ${{ steps.extract_environment.outputs.result }} run: | - docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . - docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG + export ENV=$ENV + docker-compose build + docker-compose push diff --git a/Dockerfile b/Dockerfile index 13fd9e2..3b435f3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,12 @@ -FROM node:14 as node_modules -WORKDIR /node_modules +FROM node:14 as packages +WORKDIR /packages COPY package.json . RUN npm install -FROM node:14-alpine +FROM node:alpine WORKDIR /app COPY . /app/ -COPY --from=node_modules /node_modules /app/node_modules +COPY --from=packages /packages/node_modules /app/node_modules RUN npm run build EXPOSE 3333 ENTRYPOINT npm run start diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..9218f95 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,28 @@ +version: "3.8" +services: + maestro: + build: . + image: 468720548566.dkr.ecr.us-east-1.amazonaws.com/microservices/maestro_${ENV}:latest + container_name: maestro + restart: always + ports: + - 3333:3333 + + node_exporter: + image: prom/node-exporter:v1.3.1 + container_name: node_exporter + restart: always + volumes: + - /proc:/host/proc:ro + - /sys:/host/sys:ro + - /:/rootfs:ro + - /run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket:ro + command: + - '--path.procfs=/host/proc' + - '--path.rootfs=/rootfs' + - '--path.sysfs=/host/sys' + - '--collector.filesystem.ignored-mount-points=^/(sys|proc|dev|host|etc)($$|/)' + - '--collector.systemd' + - '--collector.processes' + network_mode: host + pid: host From 3193354bea083cdff1d434fa4b9dd6a357081021 Mon Sep 17 00:00:00 2001 From: alexsanderp Date: Fri, 4 Feb 2022 10:56:57 -0300 Subject: [PATCH 6/6] Update CI/CD --- .github/workflows/deploy.yml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index b45a4f3..8ef2a7f 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -13,14 +13,22 @@ jobs: - name: Checkout uses: actions/checkout@v2 + - name: Update Pip + run: | + python3 -m pip install --upgrade pip + - name: Install Docker Compose run: | - python3 -m pip install docker-compose + python3 -m pip install docker-compose --upgrade - name: Install AWS CLI run: | - python3 -m pip install awscli - . + python3 -m pip install awscli --upgrade + + - name: Install AWS Elastic Beanstalk ClI + run: | + python3 -m pip install awsebcli --upgrade + - name: Configure AWS Region uses: aws-actions/configure-aws-credentials@v1 with: @@ -42,8 +50,8 @@ jobs: - name: Build, Tag, and Push Image to AWS ECR env: - IMAGE_TAG: latest ENV: ${{ steps.extract_environment.outputs.result }} + IMAGE_TAG: latest run: | export ENV=$ENV docker-compose build