Skip to content

Commit 0f9ab13

Browse files
committed
proxy ami building
1 parent e522a4a commit 0f9ab13

3 files changed

Lines changed: 190 additions & 90 deletions

File tree

.github/workflows/release.yml

Lines changed: 115 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -2,84 +2,92 @@ name: Make a new release
22

33
on:
44
push:
5-
tags:
6-
- v*.*.*
5+
# tags:
6+
# - v*.*.*
7+
branches:
8+
- proxy-ami
79

810
concurrency:
911
group: ${{ github.workflow }}-${{ github.ref }}
1012
cancel-in-progress: true
1113

1214
jobs:
13-
build-docker-release:
14-
# Ignore tags with -, like v1.0.0-alpha
15-
# This job will build the docker container with the "latest" tag which
16-
# is a tag used in production, thus it should only be run for full releases.
17-
if: startsWith(github.ref, 'refs/tags/') && !contains(github.ref, '-')
18-
name: Build Release Docker image
19-
uses: ./.github/workflows/build-docker.yml
20-
with:
21-
tags: |
22-
type=raw,value=latest
23-
type=semver,pattern={{version}}
24-
type=semver,pattern={{major}}.{{minor}}
25-
type=sha
26-
27-
build-docker-prerelease:
28-
# Only build tags with -, like v1.0.0-alpha
29-
if: startsWith(github.ref, 'refs/tags/') && contains(github.ref, '-')
30-
name: Build Pre-release Docker image
31-
uses: ./.github/workflows/build-docker.yml
32-
with:
33-
tags: |
34-
type=raw,value=pre-release
35-
type=semver,pattern={{version}}
36-
type=sha
37-
# Explicitly disable latest tag. It will be added otherwise.
38-
flavor: |
39-
latest=false
40-
41-
create-release:
42-
name: create-release
43-
runs-on: self-hosted
44-
outputs:
45-
upload_url: ${{ steps.release.outputs.upload_url }}
46-
steps:
47-
- name: Create GitHub release
48-
id: release
49-
uses: softprops/action-gh-release@v1
50-
if: startsWith(github.ref, 'refs/tags/')
51-
with:
52-
draft: true
53-
generate_release_notes: true
15+
# build-docker-release:
16+
# # Ignore tags with -, like v1.0.0-alpha
17+
# # This job will build the docker container with the "latest" tag which
18+
# # is a tag used in production, thus it should only be run for full releases.
19+
# if: startsWith(github.ref, 'refs/tags/') && !contains(github.ref, '-')
20+
# name: Build Release Docker image
21+
# uses: ./.github/workflows/build-docker.yml
22+
# with:
23+
# tags: |
24+
# type=raw,value=latest
25+
# type=semver,pattern={{version}}
26+
# type=semver,pattern={{major}}.{{minor}}
27+
# type=sha
28+
29+
# build-docker-prerelease:
30+
# # Only build tags with -, like v1.0.0-alpha
31+
# if: startsWith(github.ref, 'refs/tags/') && contains(github.ref, '-')
32+
# name: Build Pre-release Docker image
33+
# uses: ./.github/workflows/build-docker.yml
34+
# with:
35+
# tags: |
36+
# type=raw,value=pre-release
37+
# type=semver,pattern={{version}}
38+
# type=sha
39+
# # Explicitly disable latest tag. It will be added otherwise.
40+
# flavor: |
41+
# latest=false
42+
43+
# create-release:
44+
# name: create-release
45+
# runs-on: self-hosted
46+
# outputs:
47+
# upload_url: ${{ steps.release.outputs.upload_url }}
48+
# steps:
49+
# - name: Create GitHub release
50+
# id: release
51+
# uses: softprops/action-gh-release@v1
52+
# if: startsWith(github.ref, 'refs/tags/')
53+
# with:
54+
# draft: true
55+
# generate_release_notes: true
5456

5557
build-binaries:
56-
needs: [create-release]
58+
# needs: [create-release]
5759
runs-on:
5860
- self-hosted
5961
- ${{ matrix.os }}
6062
- X64
6163
strategy:
6264
fail-fast: false
6365
matrix:
64-
build: [linux, linux-arm64, freebsd]
66+
# build: [linux, linux-arm64, freebsd]
67+
build: [linux]
6568
include:
6669
- build: linux
6770
arch: amd64
6871
os: Linux
6972
target: x86_64-unknown-linux-gnu
70-
- build: linux-arm64
71-
arch: arm64
72-
os: Linux
73-
target: aarch64-unknown-linux-gnu
74-
- build: freebsd
75-
arch: amd64
76-
os: Linux
77-
target: x86_64-unknown-freebsd
73+
# - build: linux-arm64
74+
# arch: arm64
75+
# os: Linux
76+
# target: aarch64-unknown-linux-gnu
77+
# - build: freebsd
78+
# arch: amd64
79+
# os: Linux
80+
# target: x86_64-unknown-freebsd
7881
steps:
7982
# Store the version, stripping any v-prefix
83+
# - name: Write release version
84+
# run: |
85+
# VERSION=${GITHUB_REF_NAME#v}
86+
# echo Version: $VERSION
87+
# echo "VERSION=$VERSION" >> $GITHUB_ENV
8088
- name: Write release version
8189
run: |
82-
VERSION=${GITHUB_REF_NAME#v}
90+
VERSION=1.5.0
8391
echo Version: $VERSION
8492
echo "VERSION=$VERSION" >> $GITHUB_ENV
8593
@@ -140,15 +148,15 @@ jobs:
140148
defguard-proxy-${{ github.ref_name }}-${{ matrix.target }}
141149
outPath: defguard-proxy-${{ github.ref_name }}-${{ matrix.target }}.tar.gz
142150

143-
- name: Upload release archive
144-
uses: actions/upload-release-asset@v1.0.2
145-
env:
146-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
147-
with:
148-
upload_url: ${{ needs.create-release.outputs.upload_url }}
149-
asset_path: defguard-proxy-${{ github.ref_name }}-${{ matrix.target }}.tar.gz
150-
asset_name: defguard-proxy-${{ github.ref_name }}-${{ matrix.target }}.tar.gz
151-
asset_content_type: application/octet-stream
151+
# - name: Upload release archive
152+
# uses: actions/upload-release-asset@v1.0.2
153+
# env:
154+
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
155+
# with:
156+
# upload_url: ${{ needs.create-release.outputs.upload_url }}
157+
# asset_path: defguard-proxy-${{ github.ref_name }}-${{ matrix.target }}.tar.gz
158+
# asset_name: defguard-proxy-${{ github.ref_name }}-${{ matrix.target }}.tar.gz
159+
# asset_content_type: application/octet-stream
152160

153161
- name: Build DEB package
154162
if: matrix.build == 'linux'
@@ -157,31 +165,48 @@ jobs:
157165
fpm_args: "defguard-proxy-${{ github.ref_name }}-${{ matrix.target }}=/usr/bin/defguard-proxy defguard-proxy.service=/usr/lib/systemd/system/defguard-proxy.service example-config.toml=/etc/defguard/proxy.toml"
158166
fpm_opts: "--architecture ${{ matrix.arch }} --debug --output-type deb --version ${{ env.VERSION }} --package defguard-proxy-${{ env.VERSION }}-${{ matrix.target }}.deb"
159167

160-
- name: Upload DEB
161-
if: matrix.build == 'linux'
162-
uses: actions/upload-release-asset@v1.0.2
163-
env:
164-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
165-
with:
166-
upload_url: ${{ needs.create-release.outputs.upload_url }}
167-
asset_path: defguard-proxy-${{ env.VERSION }}-${{ matrix.target }}.deb
168-
asset_name: defguard-proxy-${{ env.VERSION }}-${{ matrix.target }}.deb
169-
asset_content_type: application/octet-stream
170-
171-
- name: Build RPM package
172-
if: matrix.build == 'linux'
173-
uses: bpicode/github-action-fpm@master
174-
with:
175-
fpm_args: "defguard-proxy-${{ github.ref_name }}-${{ matrix.target }}=/usr/bin/defguard-proxy defguard-proxy.service=/usr/lib/systemd/system/defguard-proxy.service example-config.toml=/etc/defguard/proxy.toml"
176-
fpm_opts: "--architecture ${{ matrix.arch }} --debug --output-type rpm --version ${{ env.VERSION }} --package defguard-proxy-${{ env.VERSION }}-${{ matrix.target }}.rpm"
177-
178-
- name: Upload RPM
179-
if: matrix.build == 'linux'
180-
uses: actions/upload-release-asset@v1.0.2
168+
# - name: Upload DEB
169+
# if: matrix.build == 'linux'
170+
# uses: actions/upload-release-asset@v1.0.2
171+
# env:
172+
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
173+
# with:
174+
# upload_url: ${{ needs.create-release.outputs.upload_url }}
175+
# asset_path: defguard-proxy-${{ env.VERSION }}-${{ matrix.target }}.deb
176+
# asset_name: defguard-proxy-${{ env.VERSION }}-${{ matrix.target }}.deb
177+
# asset_content_type: application/octet-stream
178+
179+
- name: Run `packer init`
180+
if: matrix.build == 'linux' && matrix.arch == 'amd64'
181+
id: init
182+
run: "packer init ./images/ami/proxy.pkr.hcl"
183+
184+
- name: Run `packer validate`
185+
if: matrix.build == 'linux' && matrix.arch == 'amd64'
186+
id: validate
187+
run: packer validate --var "package_version=${{ env.VERSION }}" ./images/ami/proxy.pkr.hcl
188+
189+
- name: Build AMI image
190+
if: matrix.build == 'linux' && matrix.arch == 'amd64'
191+
run: packer build -color=false -on-error=abort --var "package_version=${{ env.VERSION }}" ./images/ami/proxy.pkr.hcl
181192
env:
182-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
183-
with:
184-
upload_url: ${{ needs.create-release.outputs.upload_url }}
185-
asset_path: defguard-proxy-${{ env.VERSION }}-${{ matrix.target }}.rpm
186-
asset_name: defguard-proxy-${{ env.VERSION }}-${{ matrix.target }}.rpm
187-
asset_content_type: application/octet-stream
193+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
194+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
195+
196+
# - name: Build RPM package
197+
# if: matrix.build == 'linux'
198+
# uses: bpicode/github-action-fpm@master
199+
# with:
200+
# fpm_args: "defguard-proxy-${{ github.ref_name }}-${{ matrix.target }}=/usr/bin/defguard-proxy defguard-proxy.service=/usr/lib/systemd/system/defguard-proxy.service example-config.toml=/etc/defguard/proxy.toml"
201+
# fpm_opts: "--architecture ${{ matrix.arch }} --debug --output-type rpm --version ${{ env.VERSION }} --package defguard-proxy-${{ env.VERSION }}-${{ matrix.target }}.rpm"
202+
203+
# - name: Upload RPM
204+
# if: matrix.build == 'linux'
205+
# uses: actions/upload-release-asset@v1.0.2
206+
# env:
207+
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
208+
# with:
209+
# upload_url: ${{ needs.create-release.outputs.upload_url }}
210+
# asset_path: defguard-proxy-${{ env.VERSION }}-${{ matrix.target }}.rpm
211+
# asset_name: defguard-proxy-${{ env.VERSION }}-${{ matrix.target }}.rpm
212+
# asset_content_type: application/octet-stream

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)