6

I recently started experimenting with ECS, Docker Compose, and context and it's really interesting. I have managed to deploy and host a compose-file through my terminal using docker compose up and ecs-context, but I would also like to automate this through something like Github actions.

I'm struggling to see how one would set that up, and I have yet to find a guide for it.

Are there any good resources for researching this further? What would be the alternate or maybe even better way of doing CI/CD on AWS through Github?

1

4 Answers 4

3

I was also searching about this, but I haven't found anything that confirms this is possible using any of the AWS GitHub actions. However, you can specify multiple containers as part of a same ECS task definition.

Sign up to request clarification or add additional context in comments.

Comments

1

I moved away from using Docker Compose and just wrote the CloudFormation templates manually. Docker Compose still has some limitations that require quirky workarounds.

But for anyone wondering how I approached this before moving away from it (including GHA caching):

name: Deploy with Docker Compose

on:
  push:
    branches:
      - main
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout source code
        uses: actions/checkout@v2

      - name: Configure AWS credentials
        uses: aws-actions/configure-aws-credentials@v1
        with:
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws-region: ${{ secrets.AWS_REGION }}

      - name: Login to Amazon ECR
        id: login-ecr
        uses: aws-actions/amazon-ecr-login@v1

      - name: Setup Buildx
        id: buildx
        uses: docker/setup-buildx-action@v1

      - name: Build and push <YOUR_IMAGE>
        uses: docker/build-push-action@v2
        with:
          context: .
          push: true
          cache-from: type=gha,scope=<YOUR_IMAGE>
          cache-to: type=gha,scope=<YOUR_IMAGE>
          tags: |
            ${{ steps.login-ecr.outputs.registry }}/${{ secrets.ECR_REPOSITORY }}:<YOUR_IMAGE>-${{ github.sha }}
            ${{ steps.login-ecr.outputs.registry }}/${{ secrets.ECR_REPOSITORY }}:<YOUR_IMAGE>-latest

      - name: Install Docker Compose
        run: curl -L https://raw.githubusercontent.com/docker/compose-cli/main/scripts/install/install_linux.sh | sh

      - name: Docker context
        env:
          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
          AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          AWS_REGION: ${{ secrets.AWS_REGION }}
          ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }}
          GITHUB_SHA: ${{ github.sha }}
        run: |
          docker context create ecs ecs-context --from-env
          docker --context ecs-context compose up

Comments

1

This is really new feature by docker: docker/compose-ecs. Still, some features in docker-compose are restricted, e.g. dns or networks, but this might be fit in some cases.

Comments

0

A bit open ended for a StackOverflow question but this blog post walk you through an example of how to use AWS native CI/CD tools to deploy to ECS via the docker compose integration.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.