How to migrate a docker compose app to CodeCatalyst on EC2 and amplify?

0

Hi everyone,

I migrated my frontend to Amplify and now I have issue connecting to my backend that is still on an ec2 instance due to the api connection using http and not https. I thus want to take this occasion to migrate everything to CodeCatalyst. My question is thus how to deploy an application similar to the one deployed by the git action file and docker compose file below on CodeCatalyst?

Currently I run the following GitHub actions:

name: Docker Build and Deploy to Server

on:
  push:
    branches:
      - main

env:
  VERSION_NUMBER: latest
  APP_NAME: app
  APP_NAME_API: app-api
  REMOTE_HOST: xxxx.eu-central-1.compute.amazonaws.com

jobs:
  docker_build:
    name: Docker Build
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      
      - name: Create Artifact Directory
        id: image-dir
        run: |
          mkdir images

      - name: Build, tag, and archive image [API]
        id: build-image-api
        run: |
          docker build -t $APP_NAME_API:$VERSION_NUMBER libs/agent
          docker save $APP_NAME_API:$VERSION_NUMBER > images/$APP_NAME_API.tar

      - name: rsync deployments
        uses: burnett01/rsync-deployments@5.2
        with:
          switches: -avzr --delete
          path: images
          remote_path: /home/ubuntu
          remote_host: ${{ env.REMOTE_HOST }}
          remote_user: ubuntu
          remote_key: ${{ secrets.STAGING_DEPLOY_KEY }}

      - name: Docker Load and Spin Up Server
        uses: appleboy/ssh-action@master
        with:
          host: ${{ env.REMOTE_HOST }}
          username: ubuntu
          key: ${{ secrets.STAGING_DEPLOY_KEY }}
          script: |
            docker load < ~/images/${{ env.APP_NAME_API }}.tar  
            docker compose down
            docker compose --env-file docker.env up -d
            rm ~/images/*
            docker system prune -f -a

And the following docker-compose with the respective env files:

version: "3"

services:
  app-api:
    container_name: app-api
    network_mode: ${NETWORK_MODE}
    build:
      context: ../agent
      dockerfile: Dockerfile
    command: ["/bin/bash", "setup.docker.sh"]
    environment:
      - PORT=8080
    ports:
      - 8080:8080
    env_file:
      - api.env
    depends_on:
      pgdb:
        condition: service_healthy
    restart: unless-stopped

  pgdb:
    container_name: pgdb
    network_mode: ${NETWORK_MODE}
    image: postgres:12
    restart: unless-stopped
    volumes:
      - type: volume
        source: pgdb-data
        target: "/var/lib/postgresql/data"
    environment:
      POSTGRES_DB: admin
      POSTGRES_USER: ${DBUSER}
      POSTGRES_PASSWORD: ${DBPASS}
    ports:
      - 5432:5432
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${DBUSER}"]
      interval: 30s
      timeout: 30s
      retries: 3

  pgadmin:
    container_name: pgadmin
    network_mode: ${NETWORK_MODE}
    image: dpage/pgadmin4
    environment:
      PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL}
      PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD}
      PGADMIN_LISTEN_ADDRESS: 0.0.0.0
      PGADMIN_LISTEN_PORT: 5050
    ports:
      - 5050:5050
    volumes:
      - type: volume
        source: pgadmin-data
        target: /root/.pgadmin
    restart: unless-stopped

volumes:
  pgdb-data:
  pgadmin-data:

Thanks in advance for the support.

Best,

Fred

2 Answers
0

Hello Fred,

Greetings for the day!

Thanks for reaching out to us.

From the query, I understand that you want to migrate a docker compose app to CodeCatalyst on EC2.

CodeCatalyst by default provides a docker compose image and have the integration with Github actions. But if you are using a custom docker image then it the following actions are not supported : Deploy AWS CloudFormation stack, Deploy to ECS, and GitHub Actions.

You can go through this document which talks about how you can use docker images with CodeCatalyst - https://docs.aws.amazon.com/codecatalyst/latest/userguide/build-images.html

If you have any queries, please feel free to reach back to us or if you want technical solutions, feel free to contact our Premium support team with a case.

Regards,

Gurpreet S.

AWS
SUPPORT ENGINEER
answered 7 months ago
0

Hi Gurpreet,

Thanks for your message. I am trying to migrate everything to aws and replace the GitHub action with a build and deploy directly with CodeCatalyst.

Most of my questions lies on how to configure the ecs to be spin-up with the image build on the platform.

Would you have by any chance a template on building and configuring on ecs based off of a docker in which you could point me to the key parameters to set?

Thanks.

Best,

Fred

Fred
answered 7 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions