Skip to content
This repository was archived by the owner on Aug 17, 2023. It is now read-only.

Commit a9fff9a

Browse files
committed
infra: Attempt to remove hard-coded IP address with better GCE
1 parent 91ed574 commit a9fff9a

File tree

2 files changed

+59
-22
lines changed

2 files changed

+59
-22
lines changed

infra/dns.nix

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,4 @@
1212
"md"
1313
"monitoring"
1414
] (host: "${host}.${zone}");
15-
16-
# hardcoded because I don't know how to get it from nixops!
17-
ipv4.gce-mob-dev = "34.151.124.220";
1815
}

infra/flake.nix

Lines changed: 59 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,13 @@
173173
nixosSystem = final.nodelib.specialNixosSystem prev.nixosSystem specialArgs';
174174
};
175175
inherit (specialArgs') dns creds;
176+
gceProps = {
177+
region = "australia-southeast1";
178+
tags = [
179+
"iohk"
180+
"adrestia"
181+
];
182+
};
176183
in {
177184
nixpkgs = mylib.lib.extendNixpkgs
178185
(nixpkgs.lib.composeExtensions self.libOverlay hackNixopsLib)
@@ -187,42 +194,39 @@
187194

188195
defaults = {
189196
deployment.targetEnv = "gce";
190-
deployment.gce = {
191-
# credentials
192-
inherit (creds.gce) project serviceAccount accessKey;
193-
197+
deployment.gce = creds.gce // {
194198
# instance properties
195-
region = "australia-southeast1-a";
196-
197-
# VPC Firewall rules are controlled by tags.
198-
# gcloud compute --project=iohk-323702 firewall-rules create jitsi-videobridge --description="Allow incoming connections for jitsi-meet calls" --direction=INGRESS --priority=1000 --network=default --action=ALLOW --rules=tcp:4443,udp:10000 --source-ranges=0.0.0.0/0 --target-tags=iohk,adrestia
199-
# gcloud compute --project=iohk-323702 firewall-rules create emacs-crdt --description="Allow incoming connections for crdt.el sessions." --direction=INGRESS --priority=1000 --network=default --action=ALLOW --rules=tcp:6530-6539 --source-ranges=0.0.0.0/0 --target-tags=iohk,adrestia
200-
tags = [
201-
"iohk"
202-
"adrestia"
203-
];
199+
region = "${gceProps.region}-a";
200+
inherit (gceProps) tags;
201+
# network = resources.gceNetworks.adp-net;
204202
};
205203
imports = [
206204
self.nixosModules.gce-serial-console
207205
];
208206
nixpkgs.overlays = [(self: super: (super.prefer-remote-fetch self super))];
209207
};
210208

211-
gce-mob-dev = { resources, ... }: {
209+
gce-adp-web = { resources, ... }: {
212210
deployment.gce = {
211+
machineName = "n-048aa26e7caa11e58b4cda214536e17f-gce-mob-dev";
212+
213213
# instance properties
214-
instanceType = "e2-standard-4";
214+
instanceType = "e2-small";
215215

216216
# This should be plenty for the rootfs.
217217
# /nix/store is mounted with a separate disk.
218218
rootDiskSize = 30;
219219

220220
# VPC Firewall rules are controlled by tags.
221-
# This allows HTTP(s) traffic to reach the instance.
222221
tags = [
223-
"http-server"
224-
"https-server"
222+
# This allows HTTP(s) traffic to reach the instance.
223+
"web-server"
224+
# Allow jitsi videobridge traffic
225+
# "jitsi-videobridge"
226+
# Open ports for emacs crdt.el
227+
"emacs-crdt"
225228
];
229+
226230
scheduling.automaticRestart = true;
227231
scheduling.onHostMaintenance = "MIGRATE";
228232
};
@@ -247,6 +251,41 @@
247251
};
248252
};
249253

254+
resources.gceNetworks.adp-net = creds.gce // {
255+
name = "default";
256+
firewall = {
257+
web-server = {
258+
targetTags = [ "web-server" ];
259+
allowed.tcp = [ 80 443 ];
260+
};
261+
262+
# Allow incoming connections for jitsi-meet calls.
263+
jitsi-videobridge = {
264+
targetTags = [ "jitsi-videobridge" ];
265+
allowed.tcp = [ 4443 ];
266+
allowed.udp = [ 10000 ];
267+
# gcloud compute --project=iohk-323702 firewall-rules create jitsi-videobridge --description="Allow incoming connections for jitsi-meet calls" --direction=INGRESS --priority=1000 --network=default --action=ALLOW --rules=tcp:4443,udp:10000 --source-ranges=0.0.0.0/0 --target-tags=iohk,adrestia
268+
};
269+
# Allow incoming connections for crdt.el sessions.
270+
emacs-crdt = {
271+
# gcloud compute --project=iohk-323702 firewall-rules create emacs-crdt --description="Allow incoming connections for crdt.el sessions." --direction=INGRESS --priority=1000 --network=default --action=ALLOW --rules=tcp:6530-6539 --source-ranges=0.0.0.0/0 --target-tags=iohk,adrestia
272+
targetTags = [ "emacs-crdt" ];
273+
allowed.tcp = [ "6530-6539" ];
274+
};
275+
};
276+
};
277+
resources.gceStaticIPs = {
278+
adp-web-ip = { resources, lib, ... }: creds.gce // {
279+
inherit (resources.machines.gce-mob-dev.deployment.gce) labels;
280+
inherit (gceProps) region;
281+
282+
# name = "${namespace.machineName}-ip";
283+
name = "adp-web";
284+
ipAddress = "34.151.90.232";
285+
publicIPv4 = resources.gceStaticIPs.adp-web-ip.ipAddress;
286+
};
287+
};
288+
250289
resources.route53HostedZones.${dns.zone} = {
251290
name = "${dns.zone}.";
252291
comment = "Adrestia dev hosted zone";
@@ -259,7 +298,8 @@
259298
ttl = 60;
260299
# fixme: how to get config.networking.publicIPv4 from nixops-gcp?
261300
# recordValues = [ resources.machines.gce-mob-dev.publicIpv4 ];
262-
recordValues = [ dns.ipv4.gce-mob-dev ];
301+
# like this?
302+
recordValues = [ resources.gceStaticIPs.adp-web-ip.publicIPv4 ];
263303
inherit recordType domainName;
264304
inherit (creds.aws) accessKeyId;
265305
};

0 commit comments

Comments
 (0)