Skip to content

Commit 3f22a51

Browse files
committed
all in one ami
1 parent 933a31c commit 3f22a51

File tree

4 files changed

+155
-1
lines changed

4 files changed

+155
-1
lines changed

.github/workflows/ami.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Build Defguard AMI
2+
3+
on:
4+
push:
5+
tags:
6+
- "ami_c-*_px-*_gw-*"
7+
8+
jobs:
9+
build-ami:
10+
name: Build Defguard AMI
11+
runs-on: [self-hosted, Linux, X64]
12+
13+
steps:
14+
- name: Extract versions
15+
id: versions
16+
run: |
17+
TAG="${GITHUB_REF#refs/tags/}"
18+
CORE_VERSION=$(echo $TAG | sed 's/.*c-\([^_]*\).*/\1/')
19+
PROXY_VERSION=$(echo $TAG | sed 's/.*px-\([^_]*\).*/\1/')
20+
GATEWAY_VERSION=$(echo $TAG | sed 's/.*gw-\(.*\)/\1/')
21+
echo "CORE_VERSION=$CORE_VERSION" >> $GITHUB_OUTPUT
22+
echo "PROXY_VERSION=$PROXY_VERSION" >> $GITHUB_OUTPUT
23+
echo "GATEWAY_VERSION=$GATEWAY_VERSION" >> $GITHUB_OUTPUT
24+
echo "Core version: $CORE_VERSION"
25+
echo "Proxy version: $PROXY_VERSION"
26+
echo "Gateway version: $GATEWAY_VERSION"
27+
- name: Checkout repository
28+
uses: actions/checkout@v4
29+
30+
- name: Setup `packer`
31+
uses: hashicorp/setup-packer@main
32+
33+
- name: Run `packer init`
34+
run: "packer init ./cloudformation/ami/defguard.pkr.hcl"
35+
36+
- name: Build AMI with `packer`
37+
run: |
38+
packer validate --var "core_version=${{ steps.versions.outputs.CORE_VERSION }}" \
39+
--var "proxy_version=${{ steps.versions.outputs.PROXY_VERSION }}" \
40+
--var "gateway_version=${{ steps.versions.outputs.GATEWAY_VERSION }}" \
41+
./cloudformation/ami/defguard.pkr.hcl
42+
packer build --var "core_version=${{ steps.versions.outputs.CORE_VERSION }}" \
43+
--var "proxy_version=${{ steps.versions.outputs.PROXY_VERSION }}" \
44+
--var "gateway_version=${{ steps.versions.outputs.GATEWAY_VERSION }}" \
45+
./cloudformation/ami/defguard.pkr.hcl
46+
env:
47+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
48+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

.github/workflows/release.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ on:
44
push:
55
branches:
66
- main
7-
- fix-gateway-chart
87

98
jobs:
109
release:
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
echo "Updating apt repositories..."
5+
sudo apt update
6+
7+
echo "Installing dependencies..."
8+
sudo apt install -y ca-certificates curl
9+
10+
echo "Adding Defguard GPG key..."
11+
sudo install -m 0755 -d /etc/apt/keyrings
12+
sudo curl -fsSL https://apt.defguard.net/defguard.asc -o /etc/apt/keyrings/defguard.asc
13+
sudo chmod a+r /etc/apt/keyrings/defguard.asc
14+
15+
echo "Adding Defguard repository..."
16+
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/defguard.asc] https://apt.defguard.net/ trixie release " | \
17+
sudo tee /etc/apt/sources.list.d/defguard.list > /dev/null
18+
19+
echo "Updating apt repositories after adding Defguard repo..."
20+
sudo apt update
21+
22+
echo "Installing Defguard packages with specific versions..."
23+
echo " defguard version: ${CORE_VERSION}"
24+
echo " defguard-proxy version: ${PROXY_VERSION}"
25+
echo " defguard-gateway version: ${GATEWAY_VERSION}"
26+
27+
sudo apt install -y \
28+
defguard=${CORE_VERSION} \
29+
defguard-proxy=${PROXY_VERSION} \
30+
defguard-gateway=${GATEWAY_VERSION}
31+
32+
sudo systemctl stop defguard
33+
sudo systemctl disable defguard
34+
sudo systemctl stop defguard-proxy
35+
sudo systemctl disable defguard-proxy
36+
sudo systemctl stop defguard-gateway
37+
sudo systemctl disable defguard-gateway
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
packer {
2+
required_plugins {
3+
amazon = {
4+
version = ">= 1.6.0"
5+
source = "github.com/hashicorp/amazon"
6+
}
7+
}
8+
}
9+
10+
variable "core_version" {
11+
type = string
12+
}
13+
14+
variable "gateway_version" {
15+
type = string
16+
}
17+
18+
variable "proxy_version" {
19+
type = string
20+
}
21+
22+
variable "region" {
23+
type = string
24+
default = "us-east-1"
25+
}
26+
27+
variable "instance_type" {
28+
type = string
29+
default = "t3.micro"
30+
}
31+
32+
source "amazon-ebs" "defguard" {
33+
ami_name = "defguard-C-${var.core_version}-PX-${var.gateway_version}-GW-${var.proxy_version}-amd64"
34+
instance_type = var.instance_type
35+
region = var.region
36+
source_ami_filter {
37+
filters = {
38+
name = "debian-13-amd64-*"
39+
root-device-type = "ebs"
40+
virtualization-type = "hvm"
41+
}
42+
most_recent = true
43+
owners = ["136693071363"]
44+
}
45+
ssh_username = "admin"
46+
}
47+
48+
build {
49+
name = "defguard"
50+
sources = [
51+
"source.amazon-ebs.defguard"
52+
]
53+
54+
provisioner "shell" {
55+
script = "./defguard-install.sh"
56+
environment_vars = [
57+
"CORE_VERSION=${var.core_version}",
58+
"PROXY_VERSION=${var.proxy_version}",
59+
"GATEWAY_VERSION=${var.gateway_version}"
60+
]
61+
}
62+
63+
provisioner "shell" {
64+
inline = ["rm /home/admin/.ssh/authorized_keys"]
65+
}
66+
67+
provisioner "shell" {
68+
inline = ["sudo rm /root/.ssh/authorized_keys"]
69+
}
70+
}

0 commit comments

Comments
 (0)