Skip to content

Commit 4ea88da

Browse files
committed
switch from Ubuntu to Debian
1 parent b789bda commit 4ea88da

9 files changed

Lines changed: 311 additions & 331 deletions

File tree

Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
init:
2-
packer init packer.pkr.hcl
2+
packer init baseimage.pkr.hcl
3+
packer init webserver.pkr.hcl
34

45
test: init
5-
packer validate packer.pkr.hcl
6+
packer validate baseimage.pkr.hcl
7+
packer validate webserver.pkr.hcl
68
ansible-lint
79

810
build: test
9-
packer build packer.pkr.hcl
11+
packer build baseimage.pkr.hcl
12+
packer build webserver.pkr.hcl
1013

1114
all: build

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,27 @@ to generate the AWS AMI, which we use at [codemonauts](https://codemonauts.com/)
66
If you find some problems or errors in this repositoy feel free to open an issue or directly fix it with an pull request if you want to.
77

88
## Content
9-
As a basis we choose the latest Ubuntu LTS from the official AWS AMI store. On top of this we did the following for the **base** images:
9+
As a basis we choose the latest Debian from the official AWS AMI store. On top of this we did the following for the **base** images:
1010

11-
* Deactivate the default 'ubuntu' user
11+
* Deactivate the default 'admin' user
1212
* Create our own 'codemonauts' user with our current SSH public key
1313
* Activate daily unattended-updates for security patches
1414
* Install the AWS Codedeploy agent
15-
* Activate systemd-timesyncd to get a correct clock
15+
* Install the AWS SSM agent
1616
* Install some basic CLI tools
1717

18-
Additionaly on top for the **web** images:
18+
Additionaly on top for the **webserver** images:
1919
* Install Nginx and add our config snippets
20+
* Install mozjpeg for improved JPEG encoding
2021
* Install PHP-FPM and some PHP Modules which are used by CraftCMS
2122

2223
## Images build by this repo
2324
All images are public and available in eu-central-1 and eu-west-1. The *XXX* in the AMI name is the timestamp during build in the format `YYYY-MM-DD-hh-mm`.
2425

2526
**arm64**
26-
* Ubuntu Jammy, Base (codemonauts-arm-base-jammy_XXX)
27-
* Ubuntu Jammy, Web with PHP 8.3 (codemonauts-arm-web-jammy-php83_XXX)
27+
* Debian Bookworm, Base (codemonauts-arm64-bookworm-base_XXX)
28+
* Debian Bookworm, Webserver with PHP 8.3 (codemonauts-arm64-bookworm-webserver-php83_XXX)
2829

2930
**amd64**
30-
* Ubuntu Jammy, Base (codemonauts-base-jammy_XXX)
31-
* Ubuntu Jammy, Web with PHP 7.4 (codemonauts-web-jammy-php74_XXX)
31+
* Debian Bookworm, Base (codemonauts-amd64-bookworm-base_XXX)
32+
* Debian Bookworm, Webserver with PHP 8.3 (codemonauts-amd64-bookworm-webserver-php83_XXX)

baseimage.pkr.hcl

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
packer {
2+
required_plugins {
3+
amazon = {
4+
source = "github.com/hashicorp/amazon"
5+
version = "~> 1"
6+
}
7+
amazon-ami-management = {
8+
version = ">= 1.6.1"
9+
source = "github.com/wata727/amazon-ami-management"
10+
}
11+
ansible = {
12+
source = "github.com/hashicorp/ansible"
13+
version = "~> 1"
14+
}
15+
}
16+
}
17+
18+
# Instance types to use
19+
variable "amd64_instance_type" {
20+
default = "c7a.large"
21+
}
22+
variable "arm64_instance_type" {
23+
default = "c7g.large"
24+
}
25+
26+
# Provider of the Debian base images
27+
variable "account_id" {
28+
default = "136693071363"
29+
}
30+
31+
data "amazon-ami" "debian-amd64-bookworm" {
32+
filters = {
33+
name = "debian-12-amd64-*"
34+
root-device-type = "ebs"
35+
virtualization-type = "hvm"
36+
}
37+
most_recent = true
38+
owners = ["${var.account_id}"]
39+
region = "eu-central-1"
40+
}
41+
42+
data "amazon-ami" "debian-arm64-bookworm" {
43+
filters = {
44+
name = "debian-12-arm64-*"
45+
root-device-type = "ebs"
46+
virtualization-type = "hvm"
47+
}
48+
most_recent = true
49+
owners = ["${var.account_id}"]
50+
region = "eu-central-1"
51+
}
52+
53+
# codemonauts-amd64-bookworm-base
54+
source "amazon-ebs" "codemonauts-amd64-bookworm-base" {
55+
ami_groups = ["all"]
56+
ami_name = "codemonauts-amd64-bookworm-base_${formatdate("YYYY-MM-DD-hh-mm", timestamp())}"
57+
ami_regions = ["eu-west-1"]
58+
instance_type = "${var.amd64_instance_type}"
59+
region = "eu-central-1"
60+
source_ami = "${data.amazon-ami.debian-amd64-bookworm.id}"
61+
ssh_username = "admin"
62+
tags = {
63+
Amazon_AMI_Management_Identifier = "codemonauts-amd64-bookworm-base"
64+
}
65+
}
66+
build {
67+
name = "codemonauts-amd64-bookworm-base"
68+
sources = ["source.amazon-ebs.codemonauts-amd64-bookworm-base"]
69+
70+
provisioner "shell" {
71+
pause_before = "10s"
72+
inline = [
73+
"sudo apt-get update",
74+
"sudo DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\" dist-upgrade",
75+
"sudo DEBIAN_FRONTEND=noninteractive apt-get -y install ansible"
76+
]
77+
}
78+
79+
provisioner "ansible-local" {
80+
playbook_dir = "./"
81+
playbook_file = "baseimage.yaml"
82+
}
83+
84+
post-processor "amazon-ami-management" {
85+
identifier = "codemonauts-amd64-bookworm-base"
86+
keep_releases = "3"
87+
regions = ["eu-central-1", "eu-west-1"]
88+
}
89+
}
90+
91+
# codemonauts-arm64-bookworm-base
92+
source "amazon-ebs" "codemonauts-arm64-bookworm-base" {
93+
ami_groups = ["all"]
94+
ami_name = "codemonauts-arm64-bookworm-base_${formatdate("YYYY-MM-DD-hh-mm", timestamp())}"
95+
ami_regions = ["eu-west-1"]
96+
instance_type = "${var.arm64_instance_type}"
97+
region = "eu-central-1"
98+
source_ami = "${data.amazon-ami.debian-arm64-bookworm.id}"
99+
ssh_username = "admin"
100+
tags = {
101+
Amazon_AMI_Management_Identifier = "codemonauts-arm64-bookworm-base"
102+
}
103+
}
104+
build {
105+
name = "codemonauts-arm64-bookworm-base"
106+
sources = ["source.amazon-ebs.codemonauts-arm64-bookworm-base"]
107+
108+
provisioner "shell" {
109+
pause_before = "10s"
110+
inline = [
111+
"sudo apt-get update",
112+
"sudo DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\" dist-upgrade",
113+
"sudo DEBIAN_FRONTEND=noninteractive apt-get -y install ansible"
114+
]
115+
}
116+
117+
provisioner "ansible-local" {
118+
playbook_dir = "./"
119+
playbook_file = "baseimage.yaml"
120+
}
121+
122+
post-processor "amazon-ami-management" {
123+
identifier = "codemonauts-arm64-bookworm-base"
124+
keep_releases = "3"
125+
regions = ["eu-central-1", "eu-west-1"]
126+
}
127+
}

0 commit comments

Comments
 (0)