Giter Club home page Giter Club logo

terraform-ecr-docker-build-module's Introduction

Terraform Docker build and ECR push module

This is a quite hacky module which contains few bash scripts which build docker images locally and pushes them into AWS ECR using aws cli.

Requirements

Terraform version needs to be 0.12 or newer.

You need to have following programs installed in your $PATH:

  • bash
  • md5sum or md5
  • aws
  • docker

Note: Docker server needs to be running so that we can actually build images

AWS Credentials

You need to provide AWS credentials as env or profile for aws-cli for this module to work properly

Example

# Create ECR repository
resource "aws_ecr_repository" "test_service" {
  name = "example-service-name"
}

# Build Docker image and push to ECR from folder: ./example-service-directory
module "ecr_docker_build" {
  source = "github.com/onnimonni/terraform-ecr-docker-build-module"

  # Absolute path into the service which needs to be build
  dockerfile_folder = "${path.module}/example-service-directory"

  # Tag for the builded Docker image (Defaults to 'latest')
  docker_image_tag = "development"
  
  # The region which we will log into with aws-cli
  aws_region = "eu-west-1"

  # ECR repository where we can push
  ecr_repository_url = "${aws_ecr_repository.test_service.repository_url}"
}

License

MIT

Author

Onni Hakala

terraform-ecr-docker-build-module's People

Contributors

kororo avatar mrmikemarshall avatar onnimonni avatar rodneyperez avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

terraform-ecr-docker-build-module's Issues

folder contents build docker doesn't check sub folder changes

folder-contents.sh only takes md5 changes for the files in the dockerfile-folder but not for sub folders

Steps to reproduce:

changes in sub folders of dockerfile-folder doesnt trigger build during terraform plan or terraform apply

Fix:

Tar sub folder (excluding .terraform, .git) for computing checksum.

Variable to provide build args to `docker build`

For some use cases, it's helpful to use Terraform variables to provide parameters to a Docker image build. Ideally, this could be accomplished by introducing a map variable to this module that translates to --build-arg flags in the docker build command.

For example, given a Dockerfile that has a build arg

FROM scratch
ARG foo

the module may look like

module "image" {
  source             = "github.com/onnimonni/terraform-ecr-docker-build-module"
  ecr_repository_url = aws_ecr_repository.foo.repository_url
  dockerfile_folder  = "${path.module}/docker"
  aws_region         = var.region
  docker_image_tag   = local.tag
  args = {
    foo = bar
  }
}

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.