Giter Site home page Giter Site logo

engineerit2014 / git-deploy-aws-ecs Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 16 KB

Deploy: Dockerized Microservice to AWS ECS (EC2 instance)

Home Page: https://github.com/laironacosta/git-deploy-aws-ecs

Dockerfile 56.19% Go 43.81%
golang aws-ec2 aws-ecs aws-ecs-cluster aws-ecs-task aws-ecs-service aws-ecs-fargate github-actions dockerfile gin-gonic

git-deploy-aws-ecs's Introduction

Deploy: Dockerized Microservice to AWS ECS (EC2 instance)

This project shows how to deploy a dockerized Golang microservice on AWS ECS using Github Actions. Emphasizing that the same process works for any microservice deployed in another language, because the starting point is to have the microservice dockerized.

Before we start, it is important to list the steps that Github, or we ourselves must execute if we do not use Github Actions to make our microservice available to an EC2 instance.

Workflow:

  • Build and push a new container image to Amazon ECR.
  • Deploy a new task definition to Amazon ECS.
  • Check the service using the public IP of the configured EC2 or ELB.

Table of Contents

Installing Go

Local Installation

https://www.ardanlabs.com/blog/2016/05/installing-go-and-your-workspace.html

Editors

Visual Studio Code
https://code.visualstudio.com/Updates
https://github.com/microsoft/vscode-go

VIM
http://www.vim.org/download.php
http://farazdagi.com/blog/2015/vim-as-golang-ide/

Goland
https://www.jetbrains.com/go/

Installing the repository

From a command prompt, issue the following commands:

mkdir -p $(go env GOPATH)/src/github.com/laironacosta && cd $_
git clone https://github.com/laironacosta/git-deploy-aws-ecs.git

NOTE: This assumes you have Git installed. If you don’t, you can find the installation instructions here: https://git-scm.com/

Configuration

Dependencies

The only dependencies to start the configuration of your project are:

  • Dockerfile: You must have implemented the Dockerfile of your microservice.
  • AWS Console Access: You must have access to the AWS console.
  • AWS Credentials: You must have aws credentials configured on your machine to be able to execute commands to AWS.
  • Github: Your repository must be versioned on Github and you must have access.

Required files in your repo

You must create two files in order to deploy the microservice on AWS ECS using Github actions:

  1. .github/workflows/aws.yml: This file contains the entire workflow that will build and push a new container image to Amazon ECR, and then deploy a new task definition to Amazon ECS, when a condition is met in Github such as doing Push to branch develop. (copy the example code from the repo)
  2. task-definition.json: This file contains the details of your container definition on AWS.

Set-up steps

1. Create an ECR repository to store your images

  • For example: aws ecr create-repository --repository-name my-ecr-repo --region us-east-2.
  • Replace the value of ECR_REPOSITORY in the workflow file (aws.yml) with your repository's name.
  • Replace the value of aws-region in the workflow file (aws.yml) with your repository's region.

2. Create an ECS task definition, an ECS cluster, and an ECS service

3. Store your ECS task definition as a JSON file in your repository

  • The format should follow the output of aws ecs register-task-definition --generate-cli-skeleton.
  • Replace the value of task-definition in the workflow file (aws.yml) with your JSON file's name.
  • Replace the value of container-name in the workflow file (aws.yml) with the name of the container in the containerDefinitions section of the task definition.

4. Store an IAM user access key in GitHub Actions secrets named AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.

  • See the documentation for each action used below for the recommended IAM policies for this IAM user, and best practices on handling the access key credentials.

Running

After configuring all the above, it is time to push the changes to your Github repository and after the automatic execution of the workflow in Github Actions, you could validate the availability of your app in your EC2 instance.

git-deploy-aws-ecs's People

Contributors

engineerit2014 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.