Skip to content

Files

Latest commit

 

History

History
125 lines (87 loc) · 4.51 KB

container-bookstore-ecr.md

File metadata and controls

125 lines (87 loc) · 4.51 KB

Golang Deployment - Amazon ECR (Elastic Container Registry)

Kubernetes Deployment for Simple Golang API

goreport all contributors tags docker pulls download all view clone issues pull requests forks stars license


Build Container Image

  • Clone this repository

    git clone https://github.com/devopscorner/golang-deployment.git
    
  • Replace "YOUR_AWS_ACCOUNT" with your AWS ACCOUNT ID

    find ./ -type f -exec sed -i 's/YOUR_AWS_ACCOUNT/123456789012/g' {} \;
    
  • Set Environment Variable

    export ALPINE_VERSION=3.17   # 3.15 | 3.16 | 3.17
    export BASE_IMAGE="alpine"
    export IMAGE="YOUR_AWS_ACCOUNT.dkr.ecr.ap-southeast-1.amazonaws.com/devopscorner/bookstore"
    export TAG="latest"
    
  • Execute Build Image

    # Golang 1.19.3 - Alpine 3.15
    docker build -f Dockerfile -t ${IMAGE}:alpine .
    docker build -f Dockerfile.alpine-3.15 -t ${IMAGE}:alpine-3.15 .
    docker build -f Dockerfile.alpine-3.15 -t ${IMAGE}:golang1.19.3-alpine3.15 .
    
    # Golang 1.19.5 - Alpine 3.16
    docker build -f Dockerfile -t ${IMAGE}:alpine .
    docker build -f Dockerfile.alpine-3.16 -t ${IMAGE}:alpine-3.16 .
    docker build -f Dockerfile.alpine-3.16 -t ${IMAGE}:golang1.19.5-alpine3.16 .
    
    # Golang 1.19.5 - Alpine 3.17
    docker build -f Dockerfile -t ${IMAGE}:alpine .
    docker build -f Dockerfile.alpine-3.17 -t ${IMAGE}:alpine-3.17 .
    docker build -f Dockerfile.alpine-3.17 -t ${IMAGE}:golang1.19.5-alpine3.17 .
    
    -- or --
    
    ecr-build.sh ${YOUR_AWS_ACCOUNT} alpine Dockerfile ${ALPINE_VERSION}
    ecr-build.sh ${YOUR_AWS_ACCOUNT} alpine Dockerfile.alpine-3.15 ${ALPINE_VERSION}
    ecr-build.sh ${YOUR_AWS_ACCOUNT} alpine Dockerfile.alpine-3.16 ${ALPINE_VERSION}
    ecr-build.sh ${YOUR_AWS_ACCOUNT} alpine Dockerfile.alpine-3.17 ${ALPINE_VERSION}
    
    -- or --
    
    # default: 3.17
    make ecr-build-alpine ARGS=YOUR_AWS_ACCOUNT
    

Push Image to Amazon ECR (Elastic Container Registry)

  • Create Tags Image
    • Example:

      # Alpine
      docker tag YOUR_AWS_ACCOUNT.dkr.ecr.ap-southeast-1.amazonaws.com/devopscorner/bookstore:alpine YOUR_AWS_ACCOUNT.dkr.ecr.ap-southeast-1.amazonaws.com/devopscorner/bookstore:latest
      
      docker tag YOUR_AWS_ACCOUNT.dkr.ecr.ap-southeast-1.amazonaws.com/devopscorner/bookstore:alpine YOUR_AWS_ACCOUNT.dkr.ecr.ap-southeast-1.amazonaws.com/devopscorner/bookstore:alpine-latest
      
      docker tag YOUR_AWS_ACCOUNT.dkr.ecr.ap-southeast-1.amazonaws.com/devopscorner/bookstore:alpine YOUR_AWS_ACCOUNT.dkr.ecr.ap-southeast-1.amazonaws.com/devopscorner/bookstore:alpine-3.16
      
    • With Script:

      # default: 3.17
      docker tag ${IMAGE}:${ALPINE_VERSION}
      
      -- or --
      
      # default: 3.17
      ./ecr-tag.sh ARGS=YOUR_AWS_ACCOUNT alpine ${ALPINE_VERSION} CI_PATH=devopscorner/bookstore
      
      -- or --
      
      make ecr-tag-alpine ARGS=YOUR_AWS_ACCOUNT CI_PATH=devopscorner/bookstore
      

Push Image to Amazon ECR with Tags

  • Example:

    # Alpine
    docker push YOUR_AWS_ACCOUNT.dkr.ecr.ap-southeast-1.amazonaws.com/devopscorner/bookstore:alpine
    
    docker push YOUR_AWS_ACCOUNT.dkr.ecr.ap-southeast-1.amazonaws.com/devopscorner/bookstore:alpine-latest
    
    docker push YOUR_AWS_ACCOUNT.dkr.ecr.ap-southeast-1.amazonaws.com/devopscorner/bookstore:alpine-3.16
    
  • With Script:

    ./ecr-push.sh ARGS=YOUR_AWS_ACCOUNT alpine CI_PATH="devopscorner/bookstore"
    
    -- or --
    
    make ecr-push-alpine ARGS=YOUR_AWS_ACCOUNT CI_PATH="devopscorner/bookstore"