Skip to content

Commit 09c1cd2

Browse files
authored
Add AMI building to the release pipeline (#130)
* proxy ami building * Update release.yml * build ami for multiple regions * revert proxy changes * Update release.yml * tokyo region
1 parent 2fedbfb commit 09c1cd2

3 files changed

Lines changed: 99 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ jobs:
9595
target: ${{ matrix.target }}
9696
override: true
9797

98+
- name: Setup `packer`
99+
uses: hashicorp/setup-packer@main
100+
id: setup
101+
98102
- name: Set up Docker BuildX
99103
uses: docker/setup-buildx-action@v3
100104
with:
@@ -168,6 +172,26 @@ jobs:
168172
asset_name: defguard-proxy-${{ env.VERSION }}-${{ matrix.target }}.deb
169173
asset_content_type: application/octet-stream
170174

175+
- name: Run `packer init`
176+
if: matrix.build == 'linux' && matrix.arch == 'amd64'
177+
id: init
178+
run: "packer init ./images/ami/proxy.pkr.hcl"
179+
180+
- name: Build AMI images for multiple regions
181+
if: matrix.build == 'linux' && matrix.arch == 'amd64'
182+
run: |
183+
regions=(us-east-1 eu-west-1 ap-northeast-1)
184+
for region in "${regions[@]}"; do
185+
echo "Building AMI for region: $region"
186+
echo "Running packer validate for $region..."
187+
packer validate --var "package_version=${{ env.VERSION }}" --var "region=$region" ./images/ami/proxy.pkr.hcl
188+
echo "Building AMI image for $region..."
189+
packer build -color=false -on-error=abort --var "package_version=${{ env.VERSION }}" --var "region=$region" ./images/ami/proxy.pkr.hcl
190+
done
191+
env:
192+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
193+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
194+
171195
- name: Build RPM package
172196
if: matrix.build == 'linux'
173197
uses: bpicode/github-action-fpm@master

images/ami/proxy.pkr.hcl

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
packer {
2+
required_plugins {
3+
amazon = {
4+
version = ">= 1.2.8"
5+
source = "github.com/hashicorp/amazon"
6+
}
7+
}
8+
}
9+
10+
variable "package_version" {
11+
type = string
12+
}
13+
14+
variable "region" {
15+
type = string
16+
default = "eu-north-1"
17+
}
18+
19+
variable "instance_type" {
20+
type = string
21+
default = "t3.micro"
22+
}
23+
24+
source "amazon-ebs" "defguard-proxy" {
25+
ami_name = "defguard-proxy-${var.package_version}-amd64"
26+
instance_type = var.instance_type
27+
region = var.region
28+
source_ami_filter {
29+
filters = {
30+
name = "ubuntu/images/hvm-ssd-gp3/ubuntu-noble-24.04-amd64-server-*"
31+
root-device-type = "ebs"
32+
virtualization-type = "hvm"
33+
}
34+
most_recent = true
35+
owners = ["099720109477"]
36+
}
37+
ssh_username = "ubuntu"
38+
}
39+
40+
build {
41+
name = "defguard-proxy"
42+
sources = [
43+
"source.amazon-ebs.defguard-proxy"
44+
]
45+
46+
provisioner "file" {
47+
source = "defguard-proxy-${var.package_version}-x86_64-unknown-linux-gnu.deb"
48+
destination = "/tmp/defguard-proxy.deb"
49+
}
50+
51+
provisioner "shell" {
52+
script = "./images/ami/proxy.sh"
53+
}
54+
55+
provisioner "shell" {
56+
inline = ["rm /home/ubuntu/.ssh/authorized_keys"]
57+
}
58+
59+
provisioner "shell" {
60+
inline = ["sudo rm /root/.ssh/authorized_keys"]
61+
}
62+
}

images/ami/proxy.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
echo "Updating apt repositories..."
5+
sudo apt update
6+
7+
echo "Installing Defguard Proxy package..."
8+
sudo dpkg -i /tmp/defguard-proxy.deb
9+
10+
echo "Cleaning up..."
11+
sudo rm -f /tmp/defguard-proxy.deb
12+
13+
echo "Defguard Proxy installation completed successfully."

0 commit comments

Comments
 (0)