github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/website/source/docs/enterprise/faq/monolithic-artifacts.html.md (about)

     1  ---
     2  layout: "enterprise"
     3  page_title: "Monolithic Artifacts - FAQ - Terraform Enterprise"
     4  sidebar_current: "docs-enterprise-faq-monolithic"
     5  description: |-
     6    How do I build multiple applications into one artifact?
     7  ---
     8  
     9  # Monolithic Artifacts
    10  
    11  *How do I build multiple applications into one artifact?*
    12  
    13  Create your new Applications in Terraform Enterprise using the application
    14  compilation feature.
    15  
    16  You can either link each Application to the single Build Template you will be
    17  using to create the monolithic artifact, or run periodic Packer builds.
    18  
    19  Each time an Application is pushed, it will store the new application version in
    20  the artifact registry as a tarball. These will be available for you to download
    21  at build-time on the machines they belong.
    22  
    23  Here's an example `compile.json` template that you will include with the rest of
    24  your application files that do the compiling:
    25  
    26  
    27  ```json
    28  {
    29    "variables": {
    30      "app_slug": "{{ env `ATLAS_APPLICATION_SLUG` }}"
    31    },
    32    "builders": [
    33      {
    34        "type": "docker",
    35        "image": "ubuntu:14.04",
    36        "commit": true
    37      }
    38    ],
    39    "provisioners": [
    40      {
    41        "type": "shell",
    42        "inline": [
    43          "apt-get -y update"
    44        ]
    45      },
    46      {
    47        "type": "file",
    48        "source": ".",
    49        "destination": "/tmp/app"
    50      },
    51      {
    52        "type": "shell",
    53        "inline": [
    54          "cd /tmp/app",
    55          "make"
    56        ]
    57      },
    58      {
    59        "type": "file",
    60        "source": "/tmp/compiled-app.tar.gz",
    61        "destination": "compiled-app.tar.gz",
    62        "direction": "download"
    63      }
    64    ],
    65    "post-processors": [
    66      [
    67        {
    68          "type": "artifice",
    69          "files": ["compiled-app.tar.gz"]
    70        },
    71        {
    72          "type": "atlas",
    73          "artifact": "{{user `app_slug` }}",
    74          "artifact_type": "archive"
    75        }
    76      ]
    77    ]
    78  }
    79  ```
    80  
    81  In your Packer template, you can download each of the latest applications
    82  artifacts onto the host using the shell provisioner:
    83  
    84  
    85  ```text
    86  $ curl -L -H "X-Atlas-Token: ${ATLAS_TOKEN}" https://atlas.hashicorp.com/api/v1/artifacts/hashicorp/example/archive/latest/file -o example.tar.gz
    87  ```
    88  
    89  Here's an example Packer template:
    90  
    91  ```json
    92  {
    93    "variables": {
    94      "atlas_username": "{{env `ATLAS_USERNAME`}}",
    95      "aws_access_key": "{{env `AWS_ACCESS_KEY_ID`}}",
    96      "aws_secret_key": "{{env `AWS_SECRET_ACCESS_KEY`}}",
    97      "aws_region":     "{{env `AWS_DEFAULT_REGION`}}",
    98      "instance_type":  "c3.large",
    99      "source_ami":     "ami-9a562df2",
   100      "name":           "example",
   101      "ssh_username":   "ubuntu",
   102      "app_dir":        "/app"
   103    },
   104    "push": {
   105      "name": "{{user `atlas_username`}}/{{user `name`}}",
   106      "vcs": false
   107    },
   108    "builders": [
   109      {
   110        "type":            "amazon-ebs",
   111        "access_key":      "{{user `aws_access_key`}}",
   112        "secret_key":      "{{user `aws_secret_key`}}",
   113        "region":          "{{user `aws_region`}}",
   114        "vpc_id":          "",
   115        "subnet_id":       "",
   116        "instance_type":   "{{user `instance_type`}}",
   117        "source_ami":      "{{user `source_ami`}}",
   118        "ami_regions":     [],
   119        "ami_name":        "{{user `name`}} {{timestamp}}",
   120        "ami_description": "{{user `name`}} AMI",
   121        "run_tags":        { "ami-create": "{{user `name`}}" },
   122        "tags":            { "ami": "{{user `name`}}" },
   123        "ssh_username":    "{{user `ssh_username`}}",
   124        "ssh_timeout":     "10m",
   125        "ssh_private_ip":  false,
   126        "associate_public_ip_address": true
   127      }
   128    ],
   129    "provisioners": [
   130      {
   131        "type": "shell",
   132        "execute_command": "echo {{user `ssh_username`}} | {{ .Vars }} sudo -E -S sh '{{ .Path }}'",
   133        "inline": [
   134          "apt-get -y update",
   135          "apt-get -y upgrade",
   136          "apt-get -y install curl unzip tar",
   137          "mkdir -p {{user `app_dir`}}",
   138          "chmod a+w {{user `app_dir`}}",
   139          "cd /tmp",
   140          "curl -L -H 'X-Atlas-Token: ${ATLAS_TOKEN}' https://atlas.hashicorp.com/api/v1/artifacts/{{user `atlas_username`}}/{{user `name`}}/archive/latest/file -o example.tar.gz",
   141          "tar -xzf example.tar.gz -C {{user `app_dir`}}"
   142        ]
   143      }
   144    ],
   145    "post-processors": [
   146      {
   147        "type": "atlas",
   148        "artifact": "{{user `atlas_username`}}/{{user `name`}}",
   149        "artifact_type": "amazon.image",
   150        "metadata": {
   151          "created_at": "{{timestamp}}"
   152        }
   153      }
   154    ]
   155  }
   156  ```
   157  
   158  Once downloaded, you can place each application slug where it needs to go to
   159  produce the monolithic artifact your are accustom to.