Skip to content

Commit 5823416

Browse files
committed
Use podman to install proxy on test ec2
1 parent 0b5f053 commit 5823416

File tree

8 files changed

+94
-17
lines changed

8 files changed

+94
-17
lines changed
File renamed without changes.

scripts/mks/Makefile renamed to scripts/msk/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ tf-apply: tf-init
2626
tf-destroy:
2727
terraform destroy -input=false -auto-approve
2828

29+
.PHONY: tf-output
30+
tf-output:
31+
terraform output
32+
2933
.PHONY: sso-login
3034
sso-login:
3135
aws sso login --profile $(SSO_PROFILE)
File renamed without changes.
File renamed without changes.
File renamed without changes.

scripts/mks/mks.tf renamed to scripts/msk/msk.tf

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,10 @@ resource "aws_msk_cluster" "mqtt-proxy-cluster" {
3535
security_groups = [ aws_security_group.mqtt-proxy-cluster-security-group.id]
3636
ebs_volume_size = var.kafka_broker_ebs_volume_size
3737
}
38-
# https://docs.aws.amazon.com/msk/latest/developerguide/msk-authentication.html
39-
client_authentication {
40-
tls {
41-
certificate_authority_arns = [
4238

43-
]
39+
encryption_info {
40+
encryption_in_transit {
41+
client_broker = "TLS_PLAINTEXT"
4442
}
4543
}
4644
}

scripts/mks/proxy.tf renamed to scripts/msk/proxy.tf

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
data "template_file" "mqtt-proxy-init" {
2+
template = file("${path.module}/proxy.tpl")
3+
4+
vars = {
5+
mqtt_proxy_version = var.mqtt_proxy_version
6+
kafka_proxy_version = var.kafka_proxy_version
7+
bootstrap_servers = aws_msk_cluster.mqtt-proxy-cluster.bootstrap_brokers
8+
}
9+
}
10+
111
resource "aws_instance" "mqtt-proxy" {
212
count = var.mqtt_proxy_enable ? 1 : 0
313
ami = data.aws_ami.ubuntu-focal.id
@@ -6,16 +16,7 @@ resource "aws_instance" "mqtt-proxy" {
616
iam_instance_profile = aws_iam_instance_profile.mqtt-proxy-profile.id
717
vpc_security_group_ids = [aws_security_group.mqtt-proxy-security-group.id]
818
key_name = aws_key_pair.mqtt-proxy-key-pair.key_name
9-
user_data = <<EOF
10-
#!/usr/bin/env bash
11-
curl -Ls https://github.com/grepplabs/mqtt-proxy/releases/download/${var.mqtt_proxy_version}/mqtt-proxy-${var.mqtt_proxy_version}-linux-amd64.tar.gz | tar xz
12-
mv ./mqtt-proxy /usr/local/bin/mqtt-proxy
13-
14-
# kafka-proxy is not required by mqtt-proxy
15-
curl -Ls https://github.com/grepplabs/kafka-proxy/releases/download/${var.kafka_proxy_version}/kafka-proxy-${var.kafka_proxy_version}-linux-amd64.tar.gz | tar xz
16-
mv ./kafka-proxy /usr/local/bin/kafka-proxy
17-
18-
EOF
19+
user_data = data.template_file.mqtt-proxy-init.rendered
1920
}
2021

2122
data "aws_ami" "ubuntu-focal" {
@@ -26,7 +27,11 @@ data "aws_ami" "ubuntu-focal" {
2627
values = [
2728
"*ubuntu-focal-*"]
2829
}
29-
30+
filter {
31+
name = "architecture"
32+
values = [
33+
"x86_64"]
34+
}
3035
filter {
3136
name = "virtualization-type"
3237
values = [
@@ -114,4 +119,4 @@ resource "aws_security_group" "mqtt-proxy-security-group" {
114119

115120
output "mqtt_proxy_ip" {
116121
value = var.mqtt_proxy_enable ? aws_instance.mqtt-proxy.0.public_ip : ""
117-
}
122+
}

scripts/msk/proxy.tpl

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env bash
2+
curl -Ls https://github.com/grepplabs/mqtt-proxy/releases/download/${mqtt_proxy_version}/mqtt-proxy-${mqtt_proxy_version}-linux-amd64.tar.gz | tar xz
3+
mv ./mqtt-proxy /usr/local/bin/mqtt-proxy
4+
5+
# kafka-proxy is not required by mqtt-proxy
6+
curl -Ls https://github.com/grepplabs/kafka-proxy/releases/download/${kafka_proxy_version}/kafka-proxy-${kafka_proxy_version}-linux-amd64.tar.gz | tar xz
7+
mv ./kafka-proxy /usr/local/bin/kafka-proxy
8+
9+
# run mqtt-proxy in podman
10+
. /etc/os-release
11+
sh -c "echo 'deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_$${VERSION_ID}/ /' > /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list"
12+
curl -L https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_$${VERSION_ID}/Release.key | apt-key add -
13+
apt-get update -qq
14+
apt-get -qq -y install podman
15+
16+
mkdir -p /mqtt-proxy
17+
18+
tee /mqtt-proxy/mqtt-proxy.yml <<POD_FILE
19+
---
20+
apiVersion: v1
21+
kind: Pod
22+
metadata:
23+
labels:
24+
app: mqtt-proxy
25+
name: mqtt-proxy
26+
spec:
27+
containers:
28+
- command:
29+
- server
30+
- --mqtt.publisher.name=kafka
31+
- --mqtt.publisher.kafka.bootstrap-servers=${bootstrap_servers}
32+
- --mqtt.publisher.kafka.default-topic=mqtt-test
33+
env:
34+
- name: HOSTNAME
35+
- name: container
36+
value: podman
37+
image: docker.io/grepplabs/mqtt-proxy:latest
38+
name: mqtt-proxy
39+
ports:
40+
- containerPort: 9090
41+
hostPort: 9090
42+
protocol: TCP
43+
- containerPort: 1883
44+
hostPort: 1883
45+
protocol: TCP
46+
47+
POD_FILE
48+
49+
tee /etc/systemd/system/mqtt-proxy.service <<SYSTEMD_FILE
50+
[Unit]
51+
Description=MQTT Proxy
52+
53+
[Service]
54+
Restart=always
55+
ExecStartPre=/usr/bin/podman pod rm -i -f mqtt-proxy_pod
56+
ExecStartPre=/usr/bin/podman rm -i -f mqtt-proxy
57+
ExecStart=/usr/bin/podman play kube /mqtt-proxy/mqtt-proxy.yml
58+
ExecStop=/usr/bin/podman stop -t 10 mqtt-proxy
59+
KillMode=none
60+
Type=forking
61+
62+
[Install]
63+
WantedBy=multi-user.target
64+
65+
SYSTEMD_FILE
66+
67+
systemctl daemon-reload
68+
systemctl start mqtt-proxy
69+
systemctl status mqtt-proxy
70+
systemctl enable mqtt-proxy

0 commit comments

Comments
 (0)