Skip to content

Commit 1848740

Browse files
initalized aws s3 terraform via nix (#44)
* tf * s3 * backend state * backend * clean up * fixed PR * anti hack * update name of bucket * fixed build input * cleam
1 parent 2ddcea6 commit 1848740

File tree

10 files changed

+311
-74
lines changed

10 files changed

+311
-74
lines changed

.github/mergify.yml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,6 @@ pull_request_rules:
55
- "#approved-reviews-by>=1"
66
- check-success=build-and-publish-draft
77
- base=main
8-
actions:
9-
merge:
10-
method: merge
11-
- name: automatic merge documentation when CI passes and 1 reviews
12-
conditions:
13-
- files=(\.md|\.MD)$
14-
- "#approved-reviews-by>=1"
15-
- check-success=lint-documentation
16-
- base=main
17-
actions:
18-
merge:
19-
method: merge
20-
- name: automatic merge code changes with documentation when CI passes and 1 reviews
21-
conditions:
22-
- "#approved-reviews-by>=1"
23-
- check-success=build-runtime
24-
- check-success=lint-documentation
25-
- base=main
268
actions:
279
merge:
2810
method: merge

.github/workflows/pull-request-documentation.yml

Lines changed: 0 additions & 30 deletions
This file was deleted.

.github/workflows/pull-request-write.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,8 @@ on:
33
push:
44
branches:
55
- main
6-
paths-ignore:
7-
- "**/*.md"
8-
- "**/*.MD"
96

107
pull_request:
11-
paths-ignore:
12-
- "**/*.md"
13-
- "**/*.MD"
148

159
permissions:
1610
pull-requests: write
@@ -20,6 +14,7 @@ env:
2014
NIX_VERSION: nix-2.13.2
2115
NIXPKGS_CHANNEL: nixos-22.11
2216
CACHIX_NAME: golden-gate-ggx
17+
OCTOLYTICS_DIMENSION_REPOSITORY_ID: 590614152
2318

2419
jobs:
2520
build-and-publish-draft:
@@ -64,10 +59,13 @@ jobs:
6459
nix build --print-build-logs --show-trace --no-update-lock-file
6560
cp ./result/lib/golden_gate_runtime.compact.compressed.wasm ./out
6661
nix build .#golden-gate-node --print-build-logs --show-trace --no-update-lock-file
67-
cp ./result/bin/golden-gate-node ./out
68-
# can add here contracts and oci image, etc
62+
cp ./result/bin/golden-gate-node ./out
63+
# can add here contracts and oci image, etc
64+
nix run .#lint
6965
7066
- name: action-gh-release
67+
# so we do not allow non team members to do releases
68+
if: ${{ github.event_name == 'push' || (github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.id != env.OCTOLYTICS_DIMENSION_REPOSITORY_ID) || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.id == env.OCTOLYTICS_DIMENSION_REPOSITORY_ID) }}
7169
uses: softprops/action-gh-release@v1
7270
with:
7371
draft: true

.gitignore

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,42 @@ result
2929

3030
# devops
3131
*.log
32-
out
32+
out
33+
.secret
34+
35+
# Local .terraform directories
36+
**/.terraform/*
37+
38+
# .tfstate files
39+
*.tfstate
40+
*.tfstate.*
41+
42+
# Crash log files
43+
crash.log
44+
crash.*.log
45+
46+
# Exclude all .tfvars files, which are likely to contain sensitive data, such as
47+
# password, private keys, and other secrets. These should not be part of version
48+
# control as they are data points which are potentially sensitive and subject
49+
# to change depending on the environment.
50+
*.tfvars
51+
*.tfvars.json
52+
53+
# Ignore override files as they are usually used to override resources locally and so
54+
# are not checked in
55+
override.tf
56+
override.tf.json
57+
*_override.tf
58+
*_override.tf.json
59+
60+
# Include override files you do wish to add to version control using negated pattern
61+
# !example_override.tf
62+
63+
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
64+
# example: *tfplan*
65+
66+
# Ignore CLI configuration files
67+
.terraformrc
68+
terraform.rc
69+
70+
!terraform.tfstate.sops

flake.lock

Lines changed: 88 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 75 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727
inputs.nixpkgs.follows = "nixpkgs";
2828
};
2929

30+
# terraform generator to manage clouds/managed services
31+
terranix = {
32+
url = "github:terranix/terranix";
33+
inputs.nixpkgs.follows = "nixpkgs";
34+
};
35+
3036
};
3137

3238
nixConfig = {
@@ -36,7 +42,7 @@
3642
};
3743

3844
# inputs and systems are know ahead of time -> we can evalute all nix -> flake make nix """statically typed"""
39-
outputs = { self, nixpkgs, devenv, rust-overlay, crane, flake-utils, ... } @ inputs:
45+
outputs = { self, nixpkgs, devenv, rust-overlay, crane, flake-utils, terranix, ... } @ inputs:
4046
flake-utils.lib.eachDefaultSystem (system:
4147
let
4248

@@ -114,6 +120,10 @@
114120
== false
115121
&&
116122
(type == "directory" && ".github" == name) == false
123+
&& (type == "directory" && "terraform" == name) == false
124+
125+
# risky, until we move code into separate repo as rust can do include_str! as doc, but good optimization
126+
&& (type == "regular" && pkgs.lib.strings.hasSuffix ".md" name) == false
117127
)
118128
)
119129

@@ -168,11 +178,63 @@
168178
'';
169179
};
170180

181+
lint = pkgs.writeShellApplication rec {
182+
name = "lint";
183+
text = ''
184+
${pkgs.lib.meta.getExe pkgs.nodePackages.markdownlint-cli2} "**/*.md" "#.devenv" "#target"
185+
'';
186+
};
187+
188+
189+
tf-init = pkgs.writeShellApplication rec {
190+
name = "tf-init";
191+
text = ''
192+
# here you manually obtain login key
193+
aws configure
194+
'';
195+
};
196+
197+
# can use envvars override to allow run non shared "cloud" for tests
198+
age-pub = "age1a8k02z579lr0qr79pjhlneffjw3dvy3a8j5r4fw3zlphd6cyaf5qukkat5";
199+
cloud-tools = with pkgs; [
200+
awscli2
201+
terraform
202+
sops
203+
age
204+
];
205+
tf-apply = pkgs.writeShellApplication rec {
206+
name = "tf-apply";
207+
runtimeInputs = cloud-tools;
208+
text = ''
209+
cd ./terraform
210+
# generate terraform input from nix
211+
cp --force ${tf-config} config.tf.json
212+
terraform init --upgrade
213+
214+
# decrypt secret state (should run only on CI eventually for safety)
215+
# if there is encrypted state, decrypt it
216+
if [[ -f terraform.tfstate.sops ]]; then
217+
# uses age, so can use any of many providers (including aws)
218+
sops --decrypt --age ${age-pub} terraform.tfstate.sops > terraform.tfstate
219+
fi
220+
221+
# apply state to cloud, eventually should manually approve in CI
222+
terraform apply -auto-approve
223+
# encrypt update state back and push it (later in CI special job)
224+
sops --encrypt --age ${age-pub} terraform.tfstate > terraform.tfstate.sops
225+
# seems good idea to encrypt backup here too
226+
'';
227+
};
228+
171229

230+
tf-config = terranix.lib.terranixConfiguration {
231+
inherit system;
232+
modules = [ ./flake/terraform.nix ];
233+
};
172234
in
173235
rec {
174236
packages = flake-utils.lib.flattenTree {
175-
inherit golden-gate-runtime golden-gate-node single-fast multi-fast;
237+
inherit golden-gate-runtime golden-gate-node single-fast multi-fast tf-config tf-apply lint;
176238
node = golden-gate-node;
177239
runtime = golden-gate-runtime;
178240
default = golden-gate-runtime;
@@ -231,7 +293,17 @@
231293
in
232294
[
233295
{
234-
packages = with pkgs;[ rust-toolchain binaryen llvmPackages.bintools dylint-link ] ++ rust-native-build-inputs ++ darwin;
296+
packages = with pkgs;
297+
[
298+
rust-toolchain
299+
binaryen
300+
llvmPackages.bintools
301+
dylint-link
302+
nodejs-18_x
303+
nodePackages.markdownlint-cli2
304+
305+
]
306+
++ rust-native-build-inputs ++ darwin ++ cloud-tools;
235307
env = rust-env;
236308
# can do systemd/docker stuff here
237309
enterShell = ''
@@ -243,19 +315,6 @@
243315
}
244316
];
245317
};
246-
doc-linter = devenv.lib.mkShell {
247-
inherit inputs pkgs;
248-
modules = [
249-
{
250-
packages = with pkgs; [ nodejs-18_x nodePackages.markdownlint-cli2 ];
251-
env = rust-env;
252-
enterShell = ''
253-
markdownlint-cli2 "**/*.md" "#.devenv" "#target"
254-
exit
255-
'';
256-
}
257-
];
258-
};
259318
};
260319
}
261320
);

0 commit comments

Comments
 (0)