From 8cb15ab7e4996b81c8dba0a33c23b3edcd319c65 Mon Sep 17 00:00:00 2001 From: Tung Bui Date: Tue, 30 Jul 2024 23:04:43 +0700 Subject: [PATCH 1/2] packer: add content and hands on --- README.md | 6 +-- topics/packer/README.md | 40 +++++++++++++++ topics/packer/basic/README.md | 34 +++++++++++++ topics/packer/basic/assets/ami-on-aws.png | Bin 0 -> 15578 bytes topics/packer/basic/aws-ubuntu.pkr.hcl | 57 ++++++++++++++++++++++ 5 files changed, 134 insertions(+), 3 deletions(-) create mode 100644 topics/packer/README.md create mode 100644 topics/packer/basic/README.md create mode 100755 topics/packer/basic/assets/ami-on-aws.png create mode 100644 topics/packer/basic/aws-ubuntu.pkr.hcl diff --git a/README.md b/README.md index 205f32d..c3455ac 100755 --- a/README.md +++ b/README.md @@ -219,14 +219,14 @@ We cover a wide range of DevOps topics in our content library, explore them unde Nginx nginx 📖 nginx.org/en/docs - ✔️ nginx basic + ✔️ Nginx basic Packer - coming-soon + packer 📖 www.packer.io - ⏩ coming-soon + ✔️ Packer basic diff --git a/topics/packer/README.md b/topics/packer/README.md new file mode 100644 index 0000000..a5e37a1 --- /dev/null +++ b/topics/packer/README.md @@ -0,0 +1,40 @@ +## 1. What is Packer? + +### Overview + +- Packer is a tool that lets you create identical machine images for multiple platforms from a single source template. +- Packer can create golden images to use in image pipelines. + +### Official website documentation of Packer + +- https://www.packer.io/ + +## 2. Prerequisites + +- None + +## 3. Installation + +### How to install Packer? + +- https://developer.hashicorp.com/packer/install + +## 4. Basics of Packer + +### Packer getting started + +- Begginner's Guide: https://developer.hashicorp.com/packer/tutorials + +### Packer Hands on + +- See: [basic](./basic/) + +## 5. More... + +### Packer cheatsheet + +- None + +### Recommended Books + +- None diff --git a/topics/packer/basic/README.md b/topics/packer/basic/README.md new file mode 100644 index 0000000..af86c58 --- /dev/null +++ b/topics/packer/basic/README.md @@ -0,0 +1,34 @@ +# Build an Ubuntu machine image on AWS with Packer + +## Pre + +- AWS account +- Packer installed + +## Init + +```bash +packer init . +``` + +## Build + +```bash +packer build aws-ubuntu.pkr.hcl + +# ... +# ==> Wait completed after 5 minutes 15 seconds +# ==> Builds finished. The artifacts of successful builds are: +# --> learn-packer.amazon-ebs.ubuntu: AMIs were created: +# us-west-2: ami-xxxxyyyyzzzztttt +``` + +## Verify + +- Go to AWS Console `us-west-2` (The region we build packer AMI): https://us-west-2.console.aws.amazon.com/ec2/home?region=us-west-2#Images:visibility=owned-by-me +- You now can see your AMI with name: `learn-packer-linux-aws-redis-` + ![](./assets/ami-on-aws.png) + +## Cleanup + +- Once you dont want to use the AMI anymore, follow https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/deregister-ami.html to delete it. diff --git a/topics/packer/basic/assets/ami-on-aws.png b/topics/packer/basic/assets/ami-on-aws.png new file mode 100755 index 0000000000000000000000000000000000000000..a8a3612c3338782ce3bbdd9614243dbdfbd4033a GIT binary patch literal 15578 zcmbWd1ys~g7cYv63L?@ajWTo(U4nz;(A^zMhcrk^qtXpScSv^(jI=|;5RyY9oda+D zzI)$$>#g_@8ACs%&Ei@14GP7 z9wepdWqgq3&y0(i&!~H)zIkkCoN?X94=j9t!x>Ns$*3g zPFCk{>>z<3VN~6?hSD>+k5=E}^AM(#IMet3z{SF(4-b31ly2tqc28)3~@WuA=ziR{ri0I$-9p>Ti=xEq~U&?(U1`DiW!ZH8l{8^1E z%5@I@Z_eL$O8=ucUHZEw7v@h?u>o`Rdtb!k;}I~HPbcKBlX>H;iDwa~Ujp8H6bb2E z;*p6d&lm4|--rr&b}6yc;r7|Bg|p3wwUw?2a!Yed3}_j zfAnj9EZ;}^``1l45K_HjZST~u^=auI!nI;?jgkWz z&B+mI-9Mkam}gpB?k09Ry_i3JX{Wyvl6JEgR}iCMko`&|k!NC0R!ZSRMCx(m=IYt{ zG`;Z$jS`-%mYrTL>tpOM{IEZL7(253}tne1{e zXm^SGri0Ha;6gTi93e;*(uDoRI5%D3rS|Gb)jq>%SS3A11MEAxM2tV>>#g`qcV0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ygw$`Mo~WT5=3CCa;Wt)-_r;Cb}^e5fM@@tH5f9O27*#soAx?00UI>` zNSN{ZmJz>MmKo%v+b7cw)E}7?#Y2nVc4ts4Q&~!DNE}W%OY+GAYnL zn`F2segVl!I${@HcoGO^C$fn7-ONnuA6QqTi6#mNxT$(j(i&{ckI{5=6Q)Hs`;Ozr z2(mRcMqWe@axGhOF-dGba+`b;0Z4JmVjTG+^t0#K>~jy4xjJQs-)y56HQeqp+@h{D z`M4L{_3X?kay)mUbo(oD(a&jh8 zX8R{PvqZ(Jv3+}|4FNs>2pLs5ed;OTpv~zO7ufu^Cj;SMM7{ z+dfd`Acz)Mw2iq(^{QT97?z%f=9Z|8D)S|WOma?qtQ~)1_uR@iOP9fZezNg{@;gqAA4Lz76HoEYjc?A)*;ujPDu5WJ8HMk#x^k~^h(G?*p_i} z6-DVUDNAV6i?a;L6Ij5GqS@xJ=PN1t0Ad(-OfuR%2zQC4D~8;wL;f4K0W~P^fhV(SwUKjai;8I$50_4 z-uq57xo~WZFe#O)Q53@Nm=oG4{PG+~lR|&_pPesIsXR~=0mO#6605iV%D>fkkw~yM zW(4bFCg9(zrFUw1c7_*s=Veu$EY)~m7cp@&!M$K{y447({f}PcB2r#CXSieQ@WBQ~&enK) zgh+JrC*gc;DDkh)v&mZOS_Sh6Ac?Z0W3u#JI=pu zV$`Am2klO-(XKQ^LO^$YM`*Wo+XQqj_XrJ$<)Tsg_AIiE_@g=`Gb?-QJ@S)m#pWZ7 un-~8u&EJsO|GL%P?=b(58K$B5s6dij(pT%jz8wD?Xn7fBP?fZ4@c#w-2_%dF literal 0 HcmV?d00001 diff --git a/topics/packer/basic/aws-ubuntu.pkr.hcl b/topics/packer/basic/aws-ubuntu.pkr.hcl new file mode 100644 index 0000000..43e4dac --- /dev/null +++ b/topics/packer/basic/aws-ubuntu.pkr.hcl @@ -0,0 +1,57 @@ +packer { + required_plugins { + amazon = { + version = ">= 1.2.8" + source = "github.com/hashicorp/amazon" + } + } +} + +source "amazon-ebs" "ubuntu" { + ami_name = "${var.ami_prefix}-${local.timestamp}" + instance_type = "t2.micro" + region = "us-west-2" + source_ami_filter { + filters = { + name = "ubuntu/images/*ubuntu-jammy-22.04-amd64-server-*" + root-device-type = "ebs" + virtualization-type = "hvm" + } + most_recent = true + owners = ["099720109477"] + } + ssh_username = "ubuntu" +} + +build { + name = "learn-packer" + sources = [ + "source.amazon-ebs.ubuntu" + ] + + provisioner "shell" { + environment_vars = [ + "FOO=hello world", + ] + inline = [ + "echo Installing Redis", + "sleep 30", + "sudo apt-get update", + "sudo apt-get install -y redis-server", + "echo \"FOO is $FOO\" > example.txt", + ] + } + + provisioner "shell" { + inline = ["echo This provisioner runs last"] + } +} + +variable "ami_prefix" { + type = string + default = "learn-packer-linux-aws-redis" +} + +locals { + timestamp = regex_replace(timestamp(), "[- TZ:]", "") +} From 3cae143b4671f736fc50edd29231cd8ebbbda52d Mon Sep 17 00:00:00 2001 From: Tung Bui Date: Tue, 30 Jul 2024 23:08:15 +0700 Subject: [PATCH 2/2] packer: add content and hands on.1 --- topics/packer/basic/README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/topics/packer/basic/README.md b/topics/packer/basic/README.md index af86c58..9f18b36 100644 --- a/topics/packer/basic/README.md +++ b/topics/packer/basic/README.md @@ -1,9 +1,15 @@ # Build an Ubuntu machine image on AWS with Packer -## Pre +## Prerequisites - AWS account - Packer installed +- Authenticate to AWS + ```bash + export AWS_ACCESS_KEY_ID="" + export AWS_SECRET_ACCESS_KEY="" + ``` +- Doc: https://developer.hashicorp.com/packer/integrations/hashicorp/amazon#iam-task-or-instance-role ## Init