Skip to content

Commit d8de27f

Browse files
Simplify AMI build system (#409)
* Refactor image build system Missing parts: * Switch from Bash to Ansible * Finish and enable Azure and Google Cloud * Add remaining local changes * Remove dead code * Remove dead code * Restyled by jq * Merge master into improved-packer * Document `packer` image build process * Fix package name * Update golden tests Restyled by prettier-markdown Restyled by whitespace * Update and rename build-cml-ami.yml to build-ami.yml Co-authored-by: Restyled.io <commits@restyled.io>
1 parent ed322f3 commit d8de27f

14 files changed

+173
-307
lines changed

.github/workflows/build-ami.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: build-ami
2+
on:
3+
push:
4+
tags: ['ami*']
5+
jobs:
6+
build-ami:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- run: packer build environment
11+
env:
12+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
13+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}

.github/workflows/build-cml-ami.yml

Lines changed: 0 additions & 24 deletions
This file was deleted.

cml/ami-test.json

Lines changed: 0 additions & 44 deletions
This file was deleted.

cml/ami.json

Lines changed: 0 additions & 38 deletions
This file was deleted.

cml/clone-amis.go

Lines changed: 0 additions & 129 deletions
This file was deleted.

environment/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Amazon Machine Images
2+
3+
## Updating Images
4+
5+
1. Edit `setup.sh` and open a pull request with the changes.
6+
2. Run `packer build .` in this directory and wait for the operation to complete.
7+
8+
This operation needs to be run from the [`dvc-cml-terraform-provider`](https://github.com/iterative/itops/blob/e2423bf5b253896c68432a7e20d186918ed00703/cml/terraform/cml-terraform-provider.tf#L1-L3) IAM user, so `packer` can assume the [`cml-packer`](https://github.com/iterative/itops/blob/e2423bf5b253896c68432a7e20d186918ed00703/cml/terraform/packer-role.tf) role.

environment/ami.pkr.hcl

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
packer {
2+
required_plugins {
3+
amazon = {
4+
version = ">= 1.0.0"
5+
source = "github.com/hashicorp/amazon"
6+
}
7+
}
8+
}
9+
10+
variables {
11+
image_name = "iterative-cml"
12+
image_description = "CML (Continuous Machine Learning) Ubuntu 18.04"
13+
}
14+
15+
variables {
16+
aws_build_region = "us-west-1"
17+
aws_build_instance = "g2.2xlarge"
18+
aws_build_ubuntu_image = "*ubuntu-*-18.04-amd64-server-*"
19+
}
20+
21+
variables {
22+
aws_role_session_name = "cml-packer-session"
23+
aws_role_arn = "arn:aws:iam::260760892802:role/cml-packer"
24+
aws_subnet_id = "subnet-09fca08419c2f0575"
25+
aws_security_group_id = "sg-0b7df7d9f902ca7ec"
26+
}
27+
28+
locals {
29+
aws_tags = {
30+
ManagedBy = "packer"
31+
Name = var.image_name
32+
Environment = "prod"
33+
}
34+
35+
aws_release_regions = [
36+
"af-south-1",
37+
"ap-east-1",
38+
"ap-northeast-1",
39+
"ap-northeast-2",
40+
"ap-northeast-3",
41+
"ap-south-1",
42+
"ap-southeast-1",
43+
"ap-southeast-2",
44+
"ca-central-1",
45+
"eu-central-1",
46+
"eu-north-1",
47+
"eu-south-1",
48+
"eu-west-1",
49+
"eu-west-2",
50+
"eu-west-3",
51+
"me-south-1",
52+
"sa-east-1",
53+
"us-east-1",
54+
"us-east-2",
55+
"us-west-1",
56+
"us-west-2"
57+
]
58+
}
59+
60+
data "amazon-ami" "ubuntu" {
61+
region = var.aws_build_region
62+
owners = ["099720109477"]
63+
most_recent = true
64+
65+
filters = {
66+
name = "ubuntu/images/${var.aws_build_ubuntu_image}"
67+
root-device-type = "ebs"
68+
virtualization-type = "hvm"
69+
}
70+
71+
assume_role {
72+
role_arn = var.aws_role_arn
73+
session_name = var.aws_role_session_name
74+
}
75+
}
76+
77+
source "amazon-ebs" "source" {
78+
ami_groups = ["all"]
79+
ami_name = var.image_name
80+
ami_description = var.image_description
81+
ami_regions = local.aws_release_regions
82+
83+
region = var.aws_build_region
84+
instance_type = var.aws_build_instance
85+
86+
source_ami = data.amazon-ami.ubuntu.id
87+
ssh_username = "ubuntu"
88+
89+
security_group_id = var.aws_security_group_id
90+
subnet_id = var.aws_subnet_id
91+
92+
force_delete_snapshot = true
93+
force_deregister = true
94+
95+
tags = local.aws_tags
96+
run_tags = local.aws_tags
97+
run_volume_tags = local.aws_tags
98+
99+
assume_role {
100+
role_arn = var.aws_role_arn
101+
session_name = var.aws_role_session_name
102+
}
103+
}
104+
105+
build {
106+
sources = ["source.amazon-ebs.source"]
107+
108+
provisioner "shell" {
109+
script = "${path.root}/setup.sh"
110+
}
111+
}

cml/setup.sh renamed to environment/setup.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ if [ ! -f "$FILE" ]; then
2525
sudo apt install -y ubuntu-drivers-common
2626
sudo ubuntu-drivers autoinstall
2727

28+
sudo curl https://amazon-ecr-credential-helper-releases.s3.us-east-2.amazonaws.com/0.5.0/linux-amd64/docker-credential-ecr-login --output /usr/bin/docker-credential-ecr-login
29+
sudo chmod 755 /usr/bin/docker-credential-ecr-login
30+
2831
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
2932
curl -s -L https://nvidia.github.io/nvidia-docker/ubuntu18.04/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
3033
sudo apt update && sudo apt install -y nvidia-docker2

0 commit comments

Comments
 (0)