How to Parallel Docker image builds with Packer

How to Parallel Docker image builds with Packer

- 4 mins

What is Packer?

Install Packer to Debian

curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
sudo apt-get update && sudo apt-get install packer

packer

 $ packer
 Usage: packer [--version] [--help] <command> [<args>]

Build an Image and Push the image to Docker Hub

packer {
  required_plugins {
    docker = {
      version = ">= 0.0.7"
      source  = "github.com/hashicorp/docker"
    }
  }
}

variable "docker_image" {
  type    = string
  default = "ubuntu:xenial"
}

source "docker" "ubuntu" {
  image  = var.docker_image
  commit = true
}

source "docker" "ubuntu-bionic" {
  image  = "ubuntu:bionic"
  commit = true
}

build {
  name    = "learn-packer"
  sources = [
    "source.docker.ubuntu",
    "source.docker.ubuntu-bionic",
  ]

  provisioner "shell" {
    environment_vars = [
      "FOO=hello world",
    ]
    inline = [
      "echo Adding file to Docker Container",
      "echo \"FOO is $FOO\" > example.txt",
    ]
  }

  provisioner "shell" {
    inline = ["echo Running ${var.docker_image} Docker image."]
  }

  post-processors {
    post-processor "docker-tag" {
        repository =  "ubuntu-xenial"
        only = ["docker.ubuntu"]
        tags = ["ubuntu-xenial"]
      }
  }
  post-processors {
    post-processor "docker-tag" {
        repository =  "gnyscnsnli/packer"
        only = ["docker.ubuntu-bionic"]
        tags = ["ubuntu-bionic"]
      }
    post-processor "docker-push" {
        login = true
        login_username = "gnyscnsnli"
        login_password = "**********"
        only = ["docker.ubuntu-bionic"]
    }
  }
}

packer

packer init .

packer

 $  packer build .

packer



:metal: :metal: :metal: :metal: :metal: :metal: :metal:


Guneycan Sanli.


Guneycan Sanli

Guneycan Sanli

A person who like learning, music, travelling and sports.

comments powered by Disqus