Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Db creation 2 #1444

Merged
merged 38 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
538961c
Added db-creation model with a README.md
Oct 6, 2023
4ba1e34
Made changes to some API keys and some robustnesss built in to hopefu…
Oct 10, 2023
06c74ca
Testing setup for ZITI_VERSION added to model for dynamic version pul…
Oct 11, 2023
477a6d5
Installed ziti-ci and pulled ziti version for later use
Oct 12, 2023
1523f27
Added some logging
Oct 12, 2023
1f2fa16
Removed echo
Oct 12, 2023
1bd470e
Checking to see if ziti-ci folder is where it is expected.
Oct 12, 2023
7c6e473
checking if this ziti-ci is a folder or not
Oct 12, 2023
4cde113
checking to see if version file is found
Oct 12, 2023
94c566e
checking if this ziti is a directory
Oct 12, 2023
6d5c95f
Cd into ziti directories to pickup the version file, also removed an …
Oct 12, 2023
026b718
Added missing $
Oct 12, 2023
44c5220
Removing the v as I think this is needed.
Oct 12, 2023
05562ec
Testing this github tag_name thing
Oct 12, 2023
5ea75dc
Checking executable name
Oct 12, 2023
081840e
Trying this
Oct 13, 2023
3b7bc14
Trying this
Oct 13, 2023
0f6d7c1
Trying this
Oct 13, 2023
78a3f0a
Trying this
Oct 13, 2023
141369d
Seeing what is in the fablab.yml
Oct 13, 2023
805bbfa
Hoping to see directory structure
Oct 13, 2023
82628ee
Hoping to see directory structure
Oct 13, 2023
41972c4
Hoping to see directory structure, fer reals
Oct 13, 2023
a48112a
Adding in ls
Oct 13, 2023
95a16e6
Moving up a bit in directory structure
Oct 13, 2023
542b4c7
Showing only 2 nodes deep
Oct 13, 2023
bd9b8b0
Moved tree to hopefully see fablab directory
Oct 13, 2023
1ccaa19
Going a couple nodes deeper
Oct 13, 2023
8ba298c
Running tree in teardown, which in theory should show .fablab directory?
Oct 13, 2023
1599bee
Adding -a flag for tree to see .fablab directory :)
Oct 13, 2023
5d9de34
Digging into db-creation directory
Oct 13, 2023
16ca5aa
Adding v back
Oct 13, 2023
4f7fbd2
Testing change to github.go to fix issues with fablab ziti binary loc…
Oct 13, 2023
3e8a23a
Clean up and logging for bootstrap/workflow file
Oct 13, 2023
723686d
Added Binary location and different Terraform resource
Oct 14, 2023
b58f017
Set back to 4000 identities and services, as well as set trigger to m…
Oct 16, 2023
1fc3491
Removing ami directory as it is now in its own repo
Oct 16, 2023
a82a4d0
Removed unnecessary ES/Consul/Beats things (in AMI now), and removed …
Oct 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions .github/workflows/fablab-db-creation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: fablab db-creation workflow

on:
workflow_dispatch:
push:
branches:
- main
env:
GOFLAGS: "-trimpath"
GOX_OUTPUT: "release/{{.Arch}}/{{.OS}}/{{.Dir}}"
GOX_TEST_OUTPUT: "test/{{.Arch}}/{{.OS}}/bin/{{.Dir}}"
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: "us-east-1"
gh_ci_key: ${{ secrets.GH_CI_KEY }}
S3_KEY: ${{ secrets.AWS_ACCESS_KEY_ID }}
S3_SECRET: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

jobs:
build:
name: Build and Run
runs-on: ubuntu-latest
steps:
- name: Checkout ziti
uses: actions/checkout@v3
with:
path: ziti

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.20.x'

- name: Install Ziti CI
uses: openziti/ziti-ci@v1

- name: Configure Git
run: |
cd ziti
$(go env GOPATH)/bin/ziti-ci configure-git

- name: Pull ZITI_VERSION and set as $GITHUB_ENV for use with fablab
run: |
cd ziti
version="$($(go env GOPATH)/bin/ziti-ci -q get-current-version)"
echo "Ziti Version: $version"
echo "ZITI_VERSION=$version" >> $GITHUB_ENV

- name: Build and Run
run: |
cd ziti/zititest/models/db-creation
go build -o db-creation main.go
echo "ZITI_ROOT=$(go env GOPATH)/bin" >> "$GITHUB_ENV"
./db-creation create db-creation
./db-creation up

- name: Teardown
if: always()
run: |
cd ziti/zititest/models/db-creation
./db-creation dispose
12 changes: 11 additions & 1 deletion common/getziti/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/blang/semver"
"github.com/go-resty/resty/v2"
"github.com/michaelquigley/pfxlog"
"github.com/openziti/foundation/v2/versions"
c "github.com/openziti/ziti/ziti/constants"
"github.com/pkg/errors"
"net/http"
Expand Down Expand Up @@ -247,8 +248,17 @@ func InstallGitHubRelease(zitiApp string, release *GitHubReleasesData, binDir st
if zitiApp == c.ZITI {
count := 0
zitiFileName := "ziti-" + version
semVer, err := versions.ParseSemVer(version)
if err != nil {
return err
}
expectedPath := "ziti"
pathChangedVersion := versions.MustParseSemVer("0.29.0")
if semVer.CompareTo(pathChangedVersion) < 0 {
expectedPath = "ziti/ziti"
}
err = UnTarGz(fullPath, binDir, func(path string) (string, bool) {
if path == "ziti/ziti" {
if path == expectedPath {
count++
return zitiFileName, true
}
Expand Down
17 changes: 0 additions & 17 deletions zititest/ami/README.md

This file was deleted.

18 changes: 0 additions & 18 deletions zititest/ami/cleanup-old-images.sh

This file was deleted.

2 changes: 0 additions & 2 deletions zititest/ami/etc/apt/apt.conf.d/99remote-not-fancy

This file was deleted.

9 changes: 0 additions & 9 deletions zititest/ami/etc/sysctl.d/51-network-tuning.conf

This file was deleted.

2 changes: 0 additions & 2 deletions zititest/ami/etc/systemd/resolved.conf.d/ziti-tunnel.conf

This file was deleted.

11 changes: 0 additions & 11 deletions zititest/ami/list-images.sh

This file was deleted.

76 changes: 0 additions & 76 deletions zititest/ami/ziti-ami.pkr.hcl

This file was deleted.

50 changes: 50 additions & 0 deletions zititest/models/db-creation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# db-creation model

### This model is designed to be used for GitHub Actions to create a test DB and export the pki/identities/DB to s3 buckets for later testing usage. ###

- Only setup for AWS.
- Designed to work with the pete-iperf branch of fablab.
- You will need to supply your own keys/secrets.
- Infrastructure is configured in the main.go in the model.
- This is a very alpha release, minimal features.

### There are several files that will likely need to be customized for your setup: ###

- ziti/zititest/models/db-creation/main.go - mainly used to alter the model and also your Rsync and Disposal Actions (removing Route 53 A Record)
- ziti/zititest/models/db-creation/actions/bootstrap.go - This is where the meat of the actions take place. Sets up AWS remotely from the GH Runner (using Fablab executable), then runs the DB Creation Script.
- ziti/zititest/models/db-creation/resources/db_creator_script_external.sh - This is the script that interacts with Ziti and creates all the identities, services and policies.
- ziti/zititest/models/db-creation/resources/aws_setup.sh - This will default to us-east-1 region and use JSON output, if you want to change those values do that here.
- ziti/.github/workflows/fablab-db-creation.yml - This is where you will setup your GitHub workflow specifics, inserting your custom secret variable names, etc. As you can see at the end, the following 3 Fablab commands are all that is needed to run this:
- ```./db-creation create db-creation```
- ```./db-creation up```
- ```./db-creation dispose```

### Once the DB is saved in s3, you will need to pull that and the pki from the proper buckets via the following steps:

#### Non Fablab import (manual) or something designed by you ####
- Make sure AWS CLI is configured on the machine you want the DB imported to.
- cd to the /home/ubuntu/fablab directory which is where the DB lies.
- Stop any existing Ziti processes.
- Simply delete the old DB file or rename it.
- Run the following AWS CLI command to import DB:
- ```aws s3 cp s3://db-bucket-name/ctrl.db-filename ctrl.db ```
- Remove the contents of the entire pki directory using the following:
- ```cd pki```
- ```sudo rm -rf *```
- ```cd ..```
- Run the following to import the pki directory (replacing pki-s3-bucket-name/pki-folder-name with your names) :
- ```aws s3 cp --recursive s3://pki-s3-bucket-name/pki-s3-folder-name/ pki/```
- Run the following command while replacing the ziti version number in filename to start the controller:
- ```nohup /home/ubuntu/fablab/bin/ziti-v0.28.4 controller run --log-formatter pfxlog /home/ubuntu/fablab/cfg/ctrl.yml --cli-agent-alias ctrl > /home/ubuntu/logs/ctrl.log 2>&1 & ```

#### Fablab import ####
- cd into your local ziti/zititest/models/db-creation/resources folder and then import both the DB and PKI from your s3 buckets:
- Command to run for your DB import:
- ```aws s3 cp s3://s3-db-bucket-name/s3-ctrl.db-filename ctrl.db```
- Commands to run for your PKI import:
- ```mkdir pki```
- ```aws s3 cp --recursive s3://pki-s3-bucket-name/pki-s3-folder-name/ pki/```
- Within your main.go for the db-creation model, you should uncomment the 2 following lines within the Distribution portion of the model, around line 123 or so:
- ```rsync.NewRsyncHost("#ctrl", "resources/ctrl.db", "/home/ubuntu/fablab/ctrl.db"),```
- ```rsync.NewRsyncHost("#ctrl", "resources/pki/", "/home/ubuntu/fablab/pki/"),```
- Now you should be able to create a fresh db-creation executable by building and run that, which should have the new DB/PKI.
Loading
Loading