Archived
Compare commits
77
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
141ea26931 | ||
|
|
55b76b9b57 | ||
|
|
d07a3afd27 | ||
|
|
a5b373da26 | ||
|
|
99db75da19 | ||
|
|
d4e935484f | ||
|
|
4f01054781 | ||
|
|
811bbd9db4 | ||
|
|
8d9682eb47 | ||
|
|
638435873c | ||
|
|
97a85359ff | ||
|
|
ffa00767d4 | ||
|
|
86462c940f | ||
|
|
87db167d7f | ||
|
|
dd856af2d3 | ||
|
|
cd3d908d0d | ||
|
|
03f9acf869 | ||
|
|
ba1aad9fa6 | ||
|
|
dc36a6564a | ||
|
|
c5c3fc1618 | ||
|
|
2e384b7179 | ||
|
|
b708836aa9 | ||
|
|
d8da9b6515 | ||
|
|
5a1399f2b2 | ||
|
|
89db6e1e92 | ||
|
|
9bd59f29d9 | ||
|
|
55d6c5b495 | ||
|
|
f3ef3e9a1f | ||
|
|
1768bd0fe1 | ||
|
|
8afae1904b | ||
|
|
7acabb0743 | ||
|
|
ccccd9f957 | ||
|
|
34f3b719e4 | ||
|
|
0e814bd4da | ||
|
|
873a6d472c | ||
|
|
39df4683ac | ||
|
|
23ca4c4341 | ||
|
|
f64ef5d128 | ||
|
|
5f8e809b2d | ||
|
|
4a7df2de33 | ||
|
|
0c47da42fe | ||
|
|
e290c62aca | ||
|
|
f1fdc48aaa | ||
|
|
a54072de6c | ||
|
|
fa21ff2627 | ||
|
|
33d395e213 | ||
|
|
75ff60752a | ||
|
|
44b9709717 | ||
|
|
e56da7dcc1 | ||
|
|
60d34217f8 | ||
|
|
952389abb0 | ||
|
|
5c275aa622 | ||
|
|
8576137557 | ||
|
|
65c1cdf6b1 | ||
|
|
265699bc38 | ||
|
|
4a7670a5d6 | ||
|
|
6087e1cd31 | ||
|
|
1def279d26 | ||
|
|
64691bd206 | ||
|
|
aef5986135 | ||
|
|
6f8f0340d3 | ||
|
|
7590d6e237 | ||
|
|
573f99dbbe | ||
|
|
8052c1c25e | ||
|
|
a674d13493 | ||
|
|
0d4f4509c8 | ||
|
|
5af27b1b3a | ||
|
|
6c91b87348 | ||
|
|
7d18334953 | ||
|
|
79c1c5ed99 | ||
|
|
dfedd9e9ff | ||
|
|
f64683f03b | ||
|
|
913c3a8557 | ||
|
|
2f5b0cdd13 | ||
|
|
432bd4113d | ||
|
|
b26698b756 | ||
|
|
01deac78c4 |
@@ -1,57 +0,0 @@
|
|||||||
name: Fixturenet-Eth-Plugeth-Test
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: '*'
|
|
||||||
paths:
|
|
||||||
- '!**'
|
|
||||||
- '.gitea/workflows/triggers/fixturenet-eth-plugeth-test'
|
|
||||||
schedule: # Note: coordinate with other tests to not overload runners at the same time of day
|
|
||||||
- cron: '2 14 * * *'
|
|
||||||
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
name: "Run an Ethereum plugeth fixturenet test"
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: "Clone project repository"
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
# At present the stock setup-python action fails on Linux/aarch64
|
|
||||||
# Conditional steps below workaroud this by using deadsnakes for that case only
|
|
||||||
- name: "Install Python for ARM on Linux"
|
|
||||||
if: ${{ runner.arch == 'arm64' && runner.os == 'Linux' }}
|
|
||||||
uses: deadsnakes/action@v3.0.1
|
|
||||||
with:
|
|
||||||
python-version: '3.8'
|
|
||||||
- name: "Install Python cases other than ARM on Linux"
|
|
||||||
if: ${{ ! (runner.arch == 'arm64' && runner.os == 'Linux') }}
|
|
||||||
uses: actions/setup-python@v4
|
|
||||||
with:
|
|
||||||
python-version: '3.8'
|
|
||||||
- name: "Print Python version"
|
|
||||||
run: python3 --version
|
|
||||||
- name: "Install shiv"
|
|
||||||
run: pip install shiv
|
|
||||||
- name: "Generate build version file"
|
|
||||||
run: ./scripts/create_build_tag_file.sh
|
|
||||||
- name: "Build local shiv package"
|
|
||||||
run: ./scripts/build_shiv_package.sh
|
|
||||||
- name: "Run fixturenet-eth tests"
|
|
||||||
run: ./tests/fixturenet-eth-plugeth/run-test.sh
|
|
||||||
- name: Notify Vulcanize Slack on CI failure
|
|
||||||
if: ${{ always() && github.ref_name == 'main' }}
|
|
||||||
uses: ravsamhq/notify-slack-action@v2
|
|
||||||
with:
|
|
||||||
status: ${{ job.status }}
|
|
||||||
notify_when: 'failure'
|
|
||||||
env:
|
|
||||||
SLACK_WEBHOOK_URL: ${{ secrets.VULCANIZE_SLACK_CI_ALERTS }}
|
|
||||||
- name: Notify DeepStack Slack on CI failure
|
|
||||||
if: ${{ always() && github.ref_name == 'main' }}
|
|
||||||
uses: ravsamhq/notify-slack-action@v2
|
|
||||||
with:
|
|
||||||
status: ${{ job.status }}
|
|
||||||
notify_when: 'failure'
|
|
||||||
env:
|
|
||||||
SLACK_WEBHOOK_URL: ${{ secrets.DEEPSTACK_SLACK_CI_ALERTS }}
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
name: Fixturenet-Eth-Test
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: '*'
|
|
||||||
paths:
|
|
||||||
- '!**'
|
|
||||||
- '.gitea/workflows/triggers/fixturenet-eth-test'
|
|
||||||
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
name: "Run an Ethereum fixturenet test"
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: "Clone project repository"
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
# At present the stock setup-python action fails on Linux/aarch64
|
|
||||||
# Conditional steps below workaroud this by using deadsnakes for that case only
|
|
||||||
- name: "Install Python for ARM on Linux"
|
|
||||||
if: ${{ runner.arch == 'arm64' && runner.os == 'Linux' }}
|
|
||||||
uses: deadsnakes/action@v3.0.1
|
|
||||||
with:
|
|
||||||
python-version: '3.8'
|
|
||||||
- name: "Install Python cases other than ARM on Linux"
|
|
||||||
if: ${{ ! (runner.arch == 'arm64' && runner.os == 'Linux') }}
|
|
||||||
uses: actions/setup-python@v4
|
|
||||||
with:
|
|
||||||
python-version: '3.8'
|
|
||||||
- name: "Print Python version"
|
|
||||||
run: python3 --version
|
|
||||||
- name: "Install shiv"
|
|
||||||
run: pip install shiv
|
|
||||||
- name: "Generate build version file"
|
|
||||||
run: ./scripts/create_build_tag_file.sh
|
|
||||||
- name: "Build local shiv package"
|
|
||||||
run: ./scripts/build_shiv_package.sh
|
|
||||||
- name: "Run fixturenet-eth tests"
|
|
||||||
run: ./tests/fixturenet-eth/run-test.sh
|
|
||||||
- name: Notify Vulcanize Slack on CI failure
|
|
||||||
if: ${{ always() && github.ref_name == 'main' }}
|
|
||||||
uses: ravsamhq/notify-slack-action@v2
|
|
||||||
with:
|
|
||||||
status: ${{ job.status }}
|
|
||||||
notify_when: 'failure'
|
|
||||||
env:
|
|
||||||
SLACK_WEBHOOK_URL: ${{ secrets.VULCANIZE_SLACK_CI_ALERTS }}
|
|
||||||
- name: Notify DeepStack Slack on CI failure
|
|
||||||
if: ${{ always() && github.ref_name == 'main' }}
|
|
||||||
uses: ravsamhq/notify-slack-action@v2
|
|
||||||
with:
|
|
||||||
status: ${{ job.status }}
|
|
||||||
notify_when: 'failure'
|
|
||||||
env:
|
|
||||||
SLACK_WEBHOOK_URL: ${{ secrets.DEEPSTACK_SLACK_CI_ALERTS }}
|
|
||||||
@@ -39,7 +39,7 @@ jobs:
|
|||||||
- name: "Print Python version"
|
- name: "Print Python version"
|
||||||
run: python3 --version
|
run: python3 --version
|
||||||
- name: "Install shiv"
|
- name: "Install shiv"
|
||||||
run: pip install shiv
|
run: pip install shiv==1.0.6
|
||||||
- name: "Generate build version file"
|
- name: "Generate build version file"
|
||||||
run: ./scripts/create_build_tag_file.sh
|
run: ./scripts/create_build_tag_file.sh
|
||||||
- name: "Build local shiv package"
|
- name: "Build local shiv package"
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ jobs:
|
|||||||
- name: "Print Python version"
|
- name: "Print Python version"
|
||||||
run: python3 --version
|
run: python3 --version
|
||||||
- name: "Install shiv"
|
- name: "Install shiv"
|
||||||
run: pip install shiv
|
run: pip install shiv==1.0.6
|
||||||
- name: "Build local shiv package"
|
- name: "Build local shiv package"
|
||||||
id: build
|
id: build
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ jobs:
|
|||||||
- name: "Print Python version"
|
- name: "Print Python version"
|
||||||
run: python3 --version
|
run: python3 --version
|
||||||
- name: "Install shiv"
|
- name: "Install shiv"
|
||||||
run: pip install shiv
|
run: pip install shiv==1.0.6
|
||||||
- name: "Generate build version file"
|
- name: "Generate build version file"
|
||||||
run: ./scripts/create_build_tag_file.sh
|
run: ./scripts/create_build_tag_file.sh
|
||||||
- name: "Build local shiv package"
|
- name: "Build local shiv package"
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ jobs:
|
|||||||
- name: "Print Python version"
|
- name: "Print Python version"
|
||||||
run: python3 --version
|
run: python3 --version
|
||||||
- name: "Install shiv"
|
- name: "Install shiv"
|
||||||
run: pip install shiv
|
run: pip install shiv==1.0.6
|
||||||
- name: "Generate build version file"
|
- name: "Generate build version file"
|
||||||
run: ./scripts/create_build_tag_file.sh
|
run: ./scripts/create_build_tag_file.sh
|
||||||
- name: "Build local shiv package"
|
- name: "Build local shiv package"
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ name: Deploy Test
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: '*'
|
branches:
|
||||||
|
- main
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
@@ -33,7 +34,7 @@ jobs:
|
|||||||
- name: "Print Python version"
|
- name: "Print Python version"
|
||||||
run: python3 --version
|
run: python3 --version
|
||||||
- name: "Install shiv"
|
- name: "Install shiv"
|
||||||
run: pip install shiv
|
run: pip install shiv==1.0.6
|
||||||
- name: "Generate build version file"
|
- name: "Generate build version file"
|
||||||
run: ./scripts/create_build_tag_file.sh
|
run: ./scripts/create_build_tag_file.sh
|
||||||
- name: "Build local shiv package"
|
- name: "Build local shiv package"
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ jobs:
|
|||||||
- name: "Print Python version"
|
- name: "Print Python version"
|
||||||
run: python3 --version
|
run: python3 --version
|
||||||
- name: "Install shiv"
|
- name: "Install shiv"
|
||||||
run: pip install shiv
|
run: pip install shiv==1.0.6
|
||||||
- name: "Generate build version file"
|
- name: "Generate build version file"
|
||||||
run: ./scripts/create_build_tag_file.sh
|
run: ./scripts/create_build_tag_file.sh
|
||||||
- name: "Build local shiv package"
|
- name: "Build local shiv package"
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ name: K8s Deploy Test
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: '*'
|
branches:
|
||||||
|
- main
|
||||||
push:
|
push:
|
||||||
branches: '*'
|
branches: '*'
|
||||||
paths:
|
paths:
|
||||||
@@ -35,7 +36,7 @@ jobs:
|
|||||||
- name: "Print Python version"
|
- name: "Print Python version"
|
||||||
run: python3 --version
|
run: python3 --version
|
||||||
- name: "Install shiv"
|
- name: "Install shiv"
|
||||||
run: pip install shiv
|
run: pip install shiv==1.0.6
|
||||||
- name: "Generate build version file"
|
- name: "Generate build version file"
|
||||||
run: ./scripts/create_build_tag_file.sh
|
run: ./scripts/create_build_tag_file.sh
|
||||||
- name: "Build local shiv package"
|
- name: "Build local shiv package"
|
||||||
|
|||||||
+22
-9
@@ -1,19 +1,23 @@
|
|||||||
name: Fixturenet-Eth-Plugeth-Arm-Test
|
name: K8s Deployment Control Test
|
||||||
|
|
||||||
on:
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
push:
|
push:
|
||||||
branches: '*'
|
branches: '*'
|
||||||
paths:
|
paths:
|
||||||
- '!**'
|
- '!**'
|
||||||
- '.gitea/workflows/triggers/fixturenet-eth-plugeth-arm-test'
|
- '.gitea/workflows/triggers/test-k8s-deployment-control'
|
||||||
|
- '.gitea/workflows/test-k8s-deployment-control.yml'
|
||||||
|
- 'tests/k8s-deployment-control/run-test.sh'
|
||||||
schedule: # Note: coordinate with other tests to not overload runners at the same time of day
|
schedule: # Note: coordinate with other tests to not overload runners at the same time of day
|
||||||
- cron: '2 14 * * *'
|
- cron: '3 30 * * *'
|
||||||
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
name: "Run an Ethereum plugeth fixturenet test"
|
name: "Run deployment control suite on kind/k8s"
|
||||||
runs-on: ubuntu-latest-arm
|
runs-on: ubuntu-22.04
|
||||||
steps:
|
steps:
|
||||||
- name: "Clone project repository"
|
- name: "Clone project repository"
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
@@ -32,13 +36,22 @@ jobs:
|
|||||||
- name: "Print Python version"
|
- name: "Print Python version"
|
||||||
run: python3 --version
|
run: python3 --version
|
||||||
- name: "Install shiv"
|
- name: "Install shiv"
|
||||||
run: pip install shiv
|
run: pip install shiv==1.0.6
|
||||||
- name: "Generate build version file"
|
- name: "Generate build version file"
|
||||||
run: ./scripts/create_build_tag_file.sh
|
run: ./scripts/create_build_tag_file.sh
|
||||||
- name: "Build local shiv package"
|
- name: "Build local shiv package"
|
||||||
run: ./scripts/build_shiv_package.sh
|
run: ./scripts/build_shiv_package.sh
|
||||||
- name: "Run fixturenet-eth tests"
|
- name: "Check cgroups version"
|
||||||
run: ./tests/fixturenet-eth-plugeth/run-test.sh
|
run: mount | grep cgroup
|
||||||
|
- name: "Install kind"
|
||||||
|
run: ./tests/scripts/install-kind.sh
|
||||||
|
- name: "Install Kubectl"
|
||||||
|
run: ./tests/scripts/install-kubectl.sh
|
||||||
|
- name: "Run k8s deployment control test"
|
||||||
|
run: |
|
||||||
|
source /opt/bash-utils/cgroup-helper.sh
|
||||||
|
join_cgroup
|
||||||
|
./tests/k8s-deployment-control/run-test.sh
|
||||||
- name: Notify Vulcanize Slack on CI failure
|
- name: Notify Vulcanize Slack on CI failure
|
||||||
if: ${{ always() && github.ref_name == 'main' }}
|
if: ${{ always() && github.ref_name == 'main' }}
|
||||||
uses: ravsamhq/notify-slack-action@v2
|
uses: ravsamhq/notify-slack-action@v2
|
||||||
@@ -2,7 +2,8 @@ name: Webapp Test
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: '*'
|
branches:
|
||||||
|
- main
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
@@ -32,7 +33,7 @@ jobs:
|
|||||||
- name: "Print Python version"
|
- name: "Print Python version"
|
||||||
run: python3 --version
|
run: python3 --version
|
||||||
- name: "Install shiv"
|
- name: "Install shiv"
|
||||||
run: pip install shiv
|
run: pip install shiv==1.0.6
|
||||||
- name: "Generate build version file"
|
- name: "Generate build version file"
|
||||||
run: ./scripts/create_build_tag_file.sh
|
run: ./scripts/create_build_tag_file.sh
|
||||||
- name: "Build local shiv package"
|
- name: "Build local shiv package"
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ jobs:
|
|||||||
- name: "Print Python version"
|
- name: "Print Python version"
|
||||||
run: python3 --version
|
run: python3 --version
|
||||||
- name: "Install shiv"
|
- name: "Install shiv"
|
||||||
run: pip install shiv
|
run: pip install shiv==1.0.6
|
||||||
- name: "Generate build version file"
|
- name: "Generate build version file"
|
||||||
run: ./scripts/create_build_tag_file.sh
|
run: ./scripts/create_build_tag_file.sh
|
||||||
- name: "Build local shiv package"
|
- name: "Build local shiv package"
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
Change this file to trigger running the fixturenet-eth-plugeth-arm-test CI job
|
|
||||||
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
Change this file to trigger running the fixturenet-eth-plugeth-test CI job
|
|
||||||
trigger
|
|
||||||
trigger
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
Change this file to trigger running the fixturenet-eth-test CI job
|
|
||||||
|
|
||||||
@@ -5,3 +5,6 @@ Trigger
|
|||||||
Trigger
|
Trigger
|
||||||
Trigger
|
Trigger
|
||||||
Trigger
|
Trigger
|
||||||
|
Trigger
|
||||||
|
Trigger
|
||||||
|
Trigger
|
||||||
|
|||||||
@@ -1 +1,3 @@
|
|||||||
Change this file to trigger running the test-container-registry CI job
|
Change this file to trigger running the test-container-registry CI job
|
||||||
|
Triggered: 2026-01-21
|
||||||
|
Triggered: 2026-01-21 19:28:29
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
Change this file to trigger running the fixturenet-eth-test CI job
|
Change this file to trigger running the fixturenet-eth-test CI job
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
repos:
|
||||||
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
|
rev: v5.0.0
|
||||||
|
hooks:
|
||||||
|
- id: trailing-whitespace
|
||||||
|
- id: end-of-file-fixer
|
||||||
|
- id: check-yaml
|
||||||
|
args: ['--allow-multiple-documents']
|
||||||
|
- id: check-json
|
||||||
|
- id: check-merge-conflict
|
||||||
|
- id: check-added-large-files
|
||||||
|
|
||||||
|
- repo: https://github.com/psf/black
|
||||||
|
rev: 23.12.1
|
||||||
|
hooks:
|
||||||
|
- id: black
|
||||||
|
language_version: python3
|
||||||
|
|
||||||
|
- repo: https://github.com/PyCQA/flake8
|
||||||
|
rev: 7.1.1
|
||||||
|
hooks:
|
||||||
|
- id: flake8
|
||||||
|
args: ['--max-line-length=88', '--extend-ignore=E203,W503,E402']
|
||||||
|
|
||||||
|
- repo: https://github.com/RobertCraigie/pyright-python
|
||||||
|
rev: v1.1.345
|
||||||
|
hooks:
|
||||||
|
- id: pyright
|
||||||
|
|
||||||
|
- repo: https://github.com/adrienverge/yamllint
|
||||||
|
rev: v1.35.1
|
||||||
|
hooks:
|
||||||
|
- id: yamllint
|
||||||
|
args: [-d, relaxed]
|
||||||
@@ -0,0 +1,151 @@
|
|||||||
|
# Plan: Make Stack-Orchestrator AI-Friendly
|
||||||
|
|
||||||
|
## Goal
|
||||||
|
|
||||||
|
Make the stack-orchestrator repository easier for AI tools (Claude Code, Cursor, Copilot) to understand and use for generating stacks, including adding a `create-stack` command.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Part 1: Documentation & Context Files
|
||||||
|
|
||||||
|
### 1.1 Add CLAUDE.md
|
||||||
|
|
||||||
|
Create a root-level context file for AI assistants.
|
||||||
|
|
||||||
|
**File:** `CLAUDE.md`
|
||||||
|
|
||||||
|
Contents:
|
||||||
|
- Project overview (what stack-orchestrator does)
|
||||||
|
- Stack creation workflow (step-by-step)
|
||||||
|
- File naming conventions
|
||||||
|
- Required vs optional fields in stack.yml
|
||||||
|
- Common patterns and anti-patterns
|
||||||
|
- Links to example stacks (simple, medium, complex)
|
||||||
|
|
||||||
|
### 1.2 Add JSON Schema for stack.yml
|
||||||
|
|
||||||
|
Create formal validation schema.
|
||||||
|
|
||||||
|
**File:** `schemas/stack-schema.json`
|
||||||
|
|
||||||
|
Benefits:
|
||||||
|
- AI tools can validate generated stacks
|
||||||
|
- IDEs provide autocomplete
|
||||||
|
- CI can catch errors early
|
||||||
|
|
||||||
|
### 1.3 Add Template Stack with Comments
|
||||||
|
|
||||||
|
Create an annotated template for reference.
|
||||||
|
|
||||||
|
**File:** `stack_orchestrator/data/stacks/_template/stack.yml`
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
# Stack definition template - copy this directory to create a new stack
|
||||||
|
version: "1.2" # Required: 1.0, 1.1, or 1.2
|
||||||
|
name: my-stack # Required: lowercase, hyphens only
|
||||||
|
description: "Human-readable description" # Optional
|
||||||
|
repos: # Git repositories to clone
|
||||||
|
- github.com/org/repo
|
||||||
|
containers: # Container images to build (must have matching container-build/)
|
||||||
|
- cerc/my-container
|
||||||
|
pods: # Deployment units (must have matching docker-compose-{pod}.yml)
|
||||||
|
- my-pod
|
||||||
|
```
|
||||||
|
|
||||||
|
### 1.4 Document Validation Rules
|
||||||
|
|
||||||
|
Create explicit documentation of constraints currently scattered in code.
|
||||||
|
|
||||||
|
**File:** `docs/stack-format.md`
|
||||||
|
|
||||||
|
Contents:
|
||||||
|
- Container names must start with `cerc/`
|
||||||
|
- Pod names must match compose file: `docker-compose-{pod}.yml`
|
||||||
|
- Repository format: `host/org/repo[@ref]`
|
||||||
|
- Stack directory name should match `name` field
|
||||||
|
- Version field options and differences
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Part 2: Add `create-stack` Command
|
||||||
|
|
||||||
|
### 2.1 Command Overview
|
||||||
|
|
||||||
|
```bash
|
||||||
|
laconic-so create-stack --repo github.com/org/my-app [--name my-app] [--type webapp]
|
||||||
|
```
|
||||||
|
|
||||||
|
**Behavior:**
|
||||||
|
1. Parse repo URL to extract app name (if --name not provided)
|
||||||
|
2. Create `stacks/{name}/stack.yml`
|
||||||
|
3. Create `container-build/cerc-{name}/Dockerfile` and `build.sh`
|
||||||
|
4. Create `compose/docker-compose-{name}.yml`
|
||||||
|
5. Update list files (repository-list.txt, container-image-list.txt, pod-list.txt)
|
||||||
|
|
||||||
|
### 2.2 Files to Create
|
||||||
|
|
||||||
|
| File | Purpose |
|
||||||
|
|------|---------|
|
||||||
|
| `stack_orchestrator/create/__init__.py` | Package init |
|
||||||
|
| `stack_orchestrator/create/create_stack.py` | Command implementation |
|
||||||
|
|
||||||
|
### 2.3 Files to Modify
|
||||||
|
|
||||||
|
| File | Change |
|
||||||
|
|------|--------|
|
||||||
|
| `stack_orchestrator/main.py` | Add import and `cli.add_command()` |
|
||||||
|
|
||||||
|
### 2.4 Command Options
|
||||||
|
|
||||||
|
| Option | Required | Description |
|
||||||
|
|--------|----------|-------------|
|
||||||
|
| `--repo` | Yes | Git repository URL (e.g., github.com/org/repo) |
|
||||||
|
| `--name` | No | Stack name (defaults to repo name) |
|
||||||
|
| `--type` | No | Template type: webapp, service, empty (default: webapp) |
|
||||||
|
| `--force` | No | Overwrite existing files |
|
||||||
|
|
||||||
|
### 2.5 Template Types
|
||||||
|
|
||||||
|
| Type | Base Image | Port | Use Case |
|
||||||
|
|------|------------|------|----------|
|
||||||
|
| webapp | node:20-bullseye-slim | 3000 | React/Vue/Next.js apps |
|
||||||
|
| service | python:3.11-slim | 8080 | Python backend services |
|
||||||
|
| empty | none | none | Custom from scratch |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Part 3: Implementation Summary
|
||||||
|
|
||||||
|
### New Files (6)
|
||||||
|
|
||||||
|
1. `CLAUDE.md` - AI assistant context
|
||||||
|
2. `schemas/stack-schema.json` - Validation schema
|
||||||
|
3. `stack_orchestrator/data/stacks/_template/stack.yml` - Annotated template
|
||||||
|
4. `docs/stack-format.md` - Stack format documentation
|
||||||
|
5. `stack_orchestrator/create/__init__.py` - Package init
|
||||||
|
6. `stack_orchestrator/create/create_stack.py` - Command implementation
|
||||||
|
|
||||||
|
### Modified Files (1)
|
||||||
|
|
||||||
|
1. `stack_orchestrator/main.py` - Register create-stack command
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Verification
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 1. Command appears in help
|
||||||
|
laconic-so --help | grep create-stack
|
||||||
|
|
||||||
|
# 2. Dry run works
|
||||||
|
laconic-so --dry-run create-stack --repo github.com/org/test-app
|
||||||
|
|
||||||
|
# 3. Creates all expected files
|
||||||
|
laconic-so create-stack --repo github.com/org/test-app
|
||||||
|
ls stack_orchestrator/data/stacks/test-app/
|
||||||
|
ls stack_orchestrator/data/container-build/cerc-test-app/
|
||||||
|
ls stack_orchestrator/data/compose/docker-compose-test-app.yml
|
||||||
|
|
||||||
|
# 4. Build works with generated stack
|
||||||
|
laconic-so --stack test-app build-containers
|
||||||
|
```
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
# CLAUDE.md
|
||||||
|
|
||||||
|
This file provides guidance to Claude Code when working with the stack-orchestrator project.
|
||||||
|
|
||||||
|
## Some rules to follow
|
||||||
|
NEVER speculate about the cause of something
|
||||||
|
NEVER assume your hypotheses are true without evidence
|
||||||
|
|
||||||
|
ALWAYS clearly state when something is a hypothesis
|
||||||
|
ALWAYS use evidence from the systems your interacting with to support your claims and hypotheses
|
||||||
|
|
||||||
|
## Key Principles
|
||||||
|
|
||||||
|
### Development Guidelines
|
||||||
|
- **Single responsibility** - Each component has one clear purpose
|
||||||
|
- **Fail fast** - Let errors propagate, don't hide failures
|
||||||
|
- **DRY/KISS** - Minimize duplication and complexity
|
||||||
|
|
||||||
|
## Development Philosophy: Conversational Literate Programming
|
||||||
|
|
||||||
|
### Approach
|
||||||
|
This project follows principles inspired by literate programming, where development happens through explanatory conversation rather than code-first implementation.
|
||||||
|
|
||||||
|
### Core Principles
|
||||||
|
- **Documentation-First**: All changes begin with discussion of intent and reasoning
|
||||||
|
- **Narrative-Driven**: Complex systems are explained through conversational exploration
|
||||||
|
- **Justification Required**: Every coding task must have a corresponding TODO.md item explaining the "why"
|
||||||
|
- **Iterative Understanding**: Architecture and implementation evolve through dialogue
|
||||||
|
|
||||||
|
### Working Method
|
||||||
|
1. **Explore and Understand**: Read existing code to understand current state
|
||||||
|
2. **Discuss Architecture**: Workshop complex design decisions through conversation
|
||||||
|
3. **Document Intent**: Update TODO.md with clear justification before coding
|
||||||
|
4. **Explain Changes**: Each modification includes reasoning and context
|
||||||
|
5. **Maintain Narrative**: Conversations serve as living documentation of design evolution
|
||||||
|
|
||||||
|
### Implementation Guidelines
|
||||||
|
- Treat conversations as primary documentation
|
||||||
|
- Explain architectural decisions before implementing
|
||||||
|
- Use TODO.md as the "literate document" that justifies all work
|
||||||
|
- Maintain clear narrative threads across sessions
|
||||||
|
- Workshop complex ideas before coding
|
||||||
|
|
||||||
|
This approach treats the human-AI collaboration as a form of **conversational literate programming** where understanding emerges through dialogue before code implementation.
|
||||||
|
|
||||||
|
## Insights and Observations
|
||||||
|
|
||||||
|
### Design Principles
|
||||||
|
- **When something times out that doesn't mean it needs a longer timeout it means something that was expected never happened, not that we need to wait longer for it.**
|
||||||
|
- **NEVER change a timeout because you believe something truncated, you don't understand timeouts, don't edit them unless told to explicitly by user.**
|
||||||
@@ -78,5 +78,3 @@ See the [CONTRIBUTING.md](/docs/CONTRIBUTING.md) for developer mode install.
|
|||||||
## Platform Support
|
## Platform Support
|
||||||
|
|
||||||
Native aarm64 is _not_ currently supported. x64 emulation on ARM64 macos should work (not yet tested).
|
Native aarm64 is _not_ currently supported. x64 emulation on ARM64 macos should work (not yet tested).
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,413 @@
|
|||||||
|
# Implementing `laconic-so create-stack` Command
|
||||||
|
|
||||||
|
A plan for adding a new CLI command to scaffold stack files automatically.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
|
||||||
|
Add a `create-stack` command that generates all required files for a new stack:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
laconic-so create-stack --name my-stack --type webapp
|
||||||
|
```
|
||||||
|
|
||||||
|
**Output:**
|
||||||
|
```
|
||||||
|
stack_orchestrator/data/
|
||||||
|
├── stacks/my-stack/stack.yml
|
||||||
|
├── container-build/cerc-my-stack/
|
||||||
|
│ ├── Dockerfile
|
||||||
|
│ └── build.sh
|
||||||
|
└── compose/docker-compose-my-stack.yml
|
||||||
|
|
||||||
|
Updated: repository-list.txt, container-image-list.txt, pod-list.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## CLI Architecture Summary
|
||||||
|
|
||||||
|
### Command Registration Pattern
|
||||||
|
|
||||||
|
Commands are Click functions registered in `main.py`:
|
||||||
|
|
||||||
|
```python
|
||||||
|
# main.py (line ~70)
|
||||||
|
from stack_orchestrator.create import create_stack
|
||||||
|
cli.add_command(create_stack.command, "create-stack")
|
||||||
|
```
|
||||||
|
|
||||||
|
### Global Options Access
|
||||||
|
|
||||||
|
```python
|
||||||
|
from stack_orchestrator.opts import opts
|
||||||
|
|
||||||
|
if not opts.o.quiet:
|
||||||
|
print("message")
|
||||||
|
if opts.o.dry_run:
|
||||||
|
print("(would create files)")
|
||||||
|
```
|
||||||
|
|
||||||
|
### Key Utilities
|
||||||
|
|
||||||
|
| Function | Location | Purpose |
|
||||||
|
|----------|----------|---------|
|
||||||
|
| `get_yaml()` | `util.py` | YAML parser (ruamel.yaml) |
|
||||||
|
| `get_stack_path(stack)` | `util.py` | Resolve stack directory path |
|
||||||
|
| `error_exit(msg)` | `util.py` | Print error and exit(1) |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Files to Create
|
||||||
|
|
||||||
|
### 1. Command Module
|
||||||
|
|
||||||
|
**`stack_orchestrator/create/__init__.py`**
|
||||||
|
```python
|
||||||
|
# Empty file to make this a package
|
||||||
|
```
|
||||||
|
|
||||||
|
**`stack_orchestrator/create/create_stack.py`**
|
||||||
|
```python
|
||||||
|
import click
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
from shutil import copy
|
||||||
|
from stack_orchestrator.opts import opts
|
||||||
|
from stack_orchestrator.util import error_exit, get_yaml
|
||||||
|
|
||||||
|
# Template types
|
||||||
|
STACK_TEMPLATES = {
|
||||||
|
"webapp": {
|
||||||
|
"description": "Web application with Node.js",
|
||||||
|
"base_image": "node:20-bullseye-slim",
|
||||||
|
"port": 3000,
|
||||||
|
},
|
||||||
|
"service": {
|
||||||
|
"description": "Backend service",
|
||||||
|
"base_image": "python:3.11-slim",
|
||||||
|
"port": 8080,
|
||||||
|
},
|
||||||
|
"empty": {
|
||||||
|
"description": "Minimal stack with no defaults",
|
||||||
|
"base_image": None,
|
||||||
|
"port": None,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def get_data_dir() -> Path:
|
||||||
|
"""Get path to stack_orchestrator/data directory"""
|
||||||
|
return Path(__file__).absolute().parent.parent.joinpath("data")
|
||||||
|
|
||||||
|
|
||||||
|
def validate_stack_name(name: str) -> None:
|
||||||
|
"""Validate stack name follows conventions"""
|
||||||
|
import re
|
||||||
|
if not re.match(r'^[a-z0-9][a-z0-9-]*[a-z0-9]$', name) and len(name) > 2:
|
||||||
|
error_exit(f"Invalid stack name '{name}'. Use lowercase alphanumeric with hyphens.")
|
||||||
|
if name.startswith("cerc-"):
|
||||||
|
error_exit("Stack name should not start with 'cerc-' (container names will add this prefix)")
|
||||||
|
|
||||||
|
|
||||||
|
def create_stack_yml(stack_dir: Path, name: str, template: dict, repo_url: str) -> None:
|
||||||
|
"""Create stack.yml file"""
|
||||||
|
config = {
|
||||||
|
"version": "1.2",
|
||||||
|
"name": name,
|
||||||
|
"description": template.get("description", f"Stack: {name}"),
|
||||||
|
"repos": [repo_url] if repo_url else [],
|
||||||
|
"containers": [f"cerc/{name}"],
|
||||||
|
"pods": [name],
|
||||||
|
}
|
||||||
|
|
||||||
|
stack_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
with open(stack_dir / "stack.yml", "w") as f:
|
||||||
|
get_yaml().dump(config, f)
|
||||||
|
|
||||||
|
|
||||||
|
def create_dockerfile(container_dir: Path, name: str, template: dict) -> None:
|
||||||
|
"""Create Dockerfile"""
|
||||||
|
base_image = template.get("base_image", "node:20-bullseye-slim")
|
||||||
|
port = template.get("port", 3000)
|
||||||
|
|
||||||
|
dockerfile_content = f'''# Build stage
|
||||||
|
FROM {base_image} AS builder
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
COPY package*.json ./
|
||||||
|
RUN npm ci
|
||||||
|
COPY . .
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
# Production stage
|
||||||
|
FROM {base_image}
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
COPY package*.json ./
|
||||||
|
RUN npm ci --only=production
|
||||||
|
COPY --from=builder /app/dist ./dist
|
||||||
|
|
||||||
|
EXPOSE {port}
|
||||||
|
CMD ["npm", "run", "start"]
|
||||||
|
'''
|
||||||
|
|
||||||
|
container_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
with open(container_dir / "Dockerfile", "w") as f:
|
||||||
|
f.write(dockerfile_content)
|
||||||
|
|
||||||
|
|
||||||
|
def create_build_script(container_dir: Path, name: str) -> None:
|
||||||
|
"""Create build.sh script"""
|
||||||
|
build_script = f'''#!/usr/bin/env bash
|
||||||
|
# Build cerc/{name}
|
||||||
|
|
||||||
|
source ${{CERC_CONTAINER_BASE_DIR}}/build-base.sh
|
||||||
|
|
||||||
|
SCRIPT_DIR=$( cd -- "$( dirname -- "${{BASH_SOURCE[0]}}" )" &> /dev/null && pwd )
|
||||||
|
|
||||||
|
docker build -t cerc/{name}:local \\
|
||||||
|
-f ${{SCRIPT_DIR}}/Dockerfile \\
|
||||||
|
${{build_command_args}} \\
|
||||||
|
${{CERC_REPO_BASE_DIR}}/{name}
|
||||||
|
'''
|
||||||
|
|
||||||
|
build_path = container_dir / "build.sh"
|
||||||
|
with open(build_path, "w") as f:
|
||||||
|
f.write(build_script)
|
||||||
|
|
||||||
|
# Make executable
|
||||||
|
os.chmod(build_path, 0o755)
|
||||||
|
|
||||||
|
|
||||||
|
def create_compose_file(compose_dir: Path, name: str, template: dict) -> None:
|
||||||
|
"""Create docker-compose file"""
|
||||||
|
port = template.get("port", 3000)
|
||||||
|
|
||||||
|
compose_content = {
|
||||||
|
"version": "3.8",
|
||||||
|
"services": {
|
||||||
|
name: {
|
||||||
|
"image": f"cerc/{name}:local",
|
||||||
|
"restart": "unless-stopped",
|
||||||
|
"ports": [f"${{HOST_PORT:-{port}}}:{port}"],
|
||||||
|
"environment": {
|
||||||
|
"NODE_ENV": "${NODE_ENV:-production}",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
with open(compose_dir / f"docker-compose-{name}.yml", "w") as f:
|
||||||
|
get_yaml().dump(compose_content, f)
|
||||||
|
|
||||||
|
|
||||||
|
def update_list_file(data_dir: Path, filename: str, entry: str) -> None:
|
||||||
|
"""Add entry to a list file if not already present"""
|
||||||
|
list_path = data_dir / filename
|
||||||
|
|
||||||
|
# Read existing entries
|
||||||
|
existing = set()
|
||||||
|
if list_path.exists():
|
||||||
|
with open(list_path, "r") as f:
|
||||||
|
existing = set(line.strip() for line in f if line.strip())
|
||||||
|
|
||||||
|
# Add new entry
|
||||||
|
if entry not in existing:
|
||||||
|
with open(list_path, "a") as f:
|
||||||
|
f.write(f"{entry}\n")
|
||||||
|
|
||||||
|
|
||||||
|
@click.command()
|
||||||
|
@click.option("--name", required=True, help="Name of the new stack (lowercase, hyphens)")
|
||||||
|
@click.option("--type", "stack_type", default="webapp",
|
||||||
|
type=click.Choice(list(STACK_TEMPLATES.keys())),
|
||||||
|
help="Stack template type")
|
||||||
|
@click.option("--repo", help="Git repository URL (e.g., github.com/org/repo)")
|
||||||
|
@click.option("--force", is_flag=True, help="Overwrite existing files")
|
||||||
|
@click.pass_context
|
||||||
|
def command(ctx, name: str, stack_type: str, repo: str, force: bool):
|
||||||
|
"""Create a new stack with all required files.
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
|
||||||
|
laconic-so create-stack --name my-app --type webapp
|
||||||
|
|
||||||
|
laconic-so create-stack --name my-service --type service --repo github.com/org/repo
|
||||||
|
"""
|
||||||
|
# Validate
|
||||||
|
validate_stack_name(name)
|
||||||
|
|
||||||
|
template = STACK_TEMPLATES[stack_type]
|
||||||
|
data_dir = get_data_dir()
|
||||||
|
|
||||||
|
# Define paths
|
||||||
|
stack_dir = data_dir / "stacks" / name
|
||||||
|
container_dir = data_dir / "container-build" / f"cerc-{name}"
|
||||||
|
compose_dir = data_dir / "compose"
|
||||||
|
|
||||||
|
# Check for existing files
|
||||||
|
if not force:
|
||||||
|
if stack_dir.exists():
|
||||||
|
error_exit(f"Stack already exists: {stack_dir}\nUse --force to overwrite")
|
||||||
|
if container_dir.exists():
|
||||||
|
error_exit(f"Container build dir exists: {container_dir}\nUse --force to overwrite")
|
||||||
|
|
||||||
|
# Dry run check
|
||||||
|
if opts.o.dry_run:
|
||||||
|
print(f"Would create stack '{name}' with template '{stack_type}':")
|
||||||
|
print(f" - {stack_dir}/stack.yml")
|
||||||
|
print(f" - {container_dir}/Dockerfile")
|
||||||
|
print(f" - {container_dir}/build.sh")
|
||||||
|
print(f" - {compose_dir}/docker-compose-{name}.yml")
|
||||||
|
print(f" - Update repository-list.txt")
|
||||||
|
print(f" - Update container-image-list.txt")
|
||||||
|
print(f" - Update pod-list.txt")
|
||||||
|
return
|
||||||
|
|
||||||
|
# Create files
|
||||||
|
if not opts.o.quiet:
|
||||||
|
print(f"Creating stack '{name}' with template '{stack_type}'...")
|
||||||
|
|
||||||
|
create_stack_yml(stack_dir, name, template, repo)
|
||||||
|
if opts.o.verbose:
|
||||||
|
print(f" Created {stack_dir}/stack.yml")
|
||||||
|
|
||||||
|
create_dockerfile(container_dir, name, template)
|
||||||
|
if opts.o.verbose:
|
||||||
|
print(f" Created {container_dir}/Dockerfile")
|
||||||
|
|
||||||
|
create_build_script(container_dir, name)
|
||||||
|
if opts.o.verbose:
|
||||||
|
print(f" Created {container_dir}/build.sh")
|
||||||
|
|
||||||
|
create_compose_file(compose_dir, name, template)
|
||||||
|
if opts.o.verbose:
|
||||||
|
print(f" Created {compose_dir}/docker-compose-{name}.yml")
|
||||||
|
|
||||||
|
# Update list files
|
||||||
|
if repo:
|
||||||
|
update_list_file(data_dir, "repository-list.txt", repo)
|
||||||
|
if opts.o.verbose:
|
||||||
|
print(f" Added {repo} to repository-list.txt")
|
||||||
|
|
||||||
|
update_list_file(data_dir, "container-image-list.txt", f"cerc/{name}")
|
||||||
|
if opts.o.verbose:
|
||||||
|
print(f" Added cerc/{name} to container-image-list.txt")
|
||||||
|
|
||||||
|
update_list_file(data_dir, "pod-list.txt", name)
|
||||||
|
if opts.o.verbose:
|
||||||
|
print(f" Added {name} to pod-list.txt")
|
||||||
|
|
||||||
|
# Summary
|
||||||
|
if not opts.o.quiet:
|
||||||
|
print(f"\nStack '{name}' created successfully!")
|
||||||
|
print(f"\nNext steps:")
|
||||||
|
print(f" 1. Edit {stack_dir}/stack.yml")
|
||||||
|
print(f" 2. Customize {container_dir}/Dockerfile")
|
||||||
|
print(f" 3. Run: laconic-so --stack {name} build-containers")
|
||||||
|
print(f" 4. Run: laconic-so --stack {name} deploy-system up")
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. Register Command in main.py
|
||||||
|
|
||||||
|
**Edit `stack_orchestrator/main.py`**
|
||||||
|
|
||||||
|
Add import:
|
||||||
|
```python
|
||||||
|
from stack_orchestrator.create import create_stack
|
||||||
|
```
|
||||||
|
|
||||||
|
Add command registration (after line ~78):
|
||||||
|
```python
|
||||||
|
cli.add_command(create_stack.command, "create-stack")
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Implementation Steps
|
||||||
|
|
||||||
|
### Step 1: Create module structure
|
||||||
|
```bash
|
||||||
|
mkdir -p stack_orchestrator/create
|
||||||
|
touch stack_orchestrator/create/__init__.py
|
||||||
|
```
|
||||||
|
|
||||||
|
### Step 2: Create the command file
|
||||||
|
Create `stack_orchestrator/create/create_stack.py` with the code above.
|
||||||
|
|
||||||
|
### Step 3: Register in main.py
|
||||||
|
Add the import and `cli.add_command()` line.
|
||||||
|
|
||||||
|
### Step 4: Test the command
|
||||||
|
```bash
|
||||||
|
# Show help
|
||||||
|
laconic-so create-stack --help
|
||||||
|
|
||||||
|
# Dry run
|
||||||
|
laconic-so --dry-run create-stack --name test-app --type webapp
|
||||||
|
|
||||||
|
# Create a stack
|
||||||
|
laconic-so create-stack --name test-app --type webapp --repo github.com/org/test-app
|
||||||
|
|
||||||
|
# Verify
|
||||||
|
ls -la stack_orchestrator/data/stacks/test-app/
|
||||||
|
cat stack_orchestrator/data/stacks/test-app/stack.yml
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Template Types
|
||||||
|
|
||||||
|
| Type | Base Image | Port | Use Case |
|
||||||
|
|------|------------|------|----------|
|
||||||
|
| `webapp` | node:20-bullseye-slim | 3000 | React/Vue/Next.js apps |
|
||||||
|
| `service` | python:3.11-slim | 8080 | Python backend services |
|
||||||
|
| `empty` | none | none | Custom from scratch |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Future Enhancements
|
||||||
|
|
||||||
|
1. **Interactive mode** - Prompt for values if not provided
|
||||||
|
2. **More templates** - Go, Rust, database stacks
|
||||||
|
3. **Template from existing** - `--from-stack existing-stack`
|
||||||
|
4. **External stack support** - Create in custom directory
|
||||||
|
5. **Validation command** - `laconic-so validate-stack --name my-stack`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Files Modified
|
||||||
|
|
||||||
|
| File | Change |
|
||||||
|
|------|--------|
|
||||||
|
| `stack_orchestrator/create/__init__.py` | New (empty) |
|
||||||
|
| `stack_orchestrator/create/create_stack.py` | New (command implementation) |
|
||||||
|
| `stack_orchestrator/main.py` | Add import and `cli.add_command()` |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Verification
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 1. Command appears in help
|
||||||
|
laconic-so --help | grep create-stack
|
||||||
|
|
||||||
|
# 2. Dry run works
|
||||||
|
laconic-so --dry-run create-stack --name verify-test --type webapp
|
||||||
|
|
||||||
|
# 3. Full creation works
|
||||||
|
laconic-so create-stack --name verify-test --type webapp
|
||||||
|
ls stack_orchestrator/data/stacks/verify-test/
|
||||||
|
ls stack_orchestrator/data/container-build/cerc-verify-test/
|
||||||
|
ls stack_orchestrator/data/compose/docker-compose-verify-test.yml
|
||||||
|
|
||||||
|
# 4. Build works
|
||||||
|
laconic-so --stack verify-test build-containers
|
||||||
|
|
||||||
|
# 5. Cleanup
|
||||||
|
rm -rf stack_orchestrator/data/stacks/verify-test
|
||||||
|
rm -rf stack_orchestrator/data/container-build/cerc-verify-test
|
||||||
|
rm stack_orchestrator/data/compose/docker-compose-verify-test.yml
|
||||||
|
```
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
# TODO
|
||||||
|
|
||||||
|
## Features Needed
|
||||||
|
|
||||||
|
### Update Stack Command
|
||||||
|
We need an "update stack" command in stack orchestrator and cleaner documentation regarding how to do continuous deployment with and without payments.
|
||||||
|
|
||||||
|
**Context**: Currently, `deploy init` generates a spec file and `deploy create` creates a deployment directory. The `deployment update` command (added by Thomas Lackey) only syncs env vars and restarts - it doesn't regenerate configurations. There's a gap in the workflow for updating stack configurations after initial deployment.
|
||||||
|
|
||||||
|
## Architecture Refactoring
|
||||||
|
|
||||||
|
### Separate Deployer from Stack Orchestrator CLI
|
||||||
|
The deployer logic should be decoupled from the CLI tool to allow independent development and reuse.
|
||||||
|
|
||||||
|
### Separate Stacks from Stack Orchestrator Repo
|
||||||
|
Stacks should live in their own repositories, not bundled with the orchestrator tool. This allows stacks to evolve independently and be maintained by different teams.
|
||||||
+1
-1
@@ -51,7 +51,7 @@ $ laconic-so build-npms --include <package-name>
|
|||||||
```
|
```
|
||||||
e.g.
|
e.g.
|
||||||
```
|
```
|
||||||
$ laconic-so build-npms --include laconic-sdk
|
$ laconic-so build-npms --include registry-sdk
|
||||||
```
|
```
|
||||||
Build the packages for a stack:
|
Build the packages for a stack:
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -0,0 +1,550 @@
|
|||||||
|
# Docker Compose Deployment Guide
|
||||||
|
|
||||||
|
## Introduction
|
||||||
|
|
||||||
|
### What is a Deployer?
|
||||||
|
|
||||||
|
In stack-orchestrator, a **deployer** provides a uniform interface for orchestrating containerized applications. This guide focuses on Docker Compose deployments, which is the default and recommended deployment mode.
|
||||||
|
|
||||||
|
While stack-orchestrator also supports Kubernetes (`k8s`) and Kind (`k8s-kind`) deployments, those are out of scope for this guide. See the [Kubernetes Enhancements](./k8s-deployment-enhancements.md) documentation for advanced deployment options.
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
|
||||||
|
To deploy stacks using Docker Compose, you need:
|
||||||
|
|
||||||
|
- Docker Engine (20.10+)
|
||||||
|
- Docker Compose plugin (v2.0+)
|
||||||
|
- Python 3.8+
|
||||||
|
- stack-orchestrator installed (`laconic-so`)
|
||||||
|
|
||||||
|
**That's it!** No additional infrastructure is required. If you have Docker installed, you're ready to deploy.
|
||||||
|
|
||||||
|
## Deployment Workflow
|
||||||
|
|
||||||
|
The typical deployment workflow consists of four main steps:
|
||||||
|
|
||||||
|
1. **Setup repositories and build containers** (first time only)
|
||||||
|
2. **Initialize deployment specification**
|
||||||
|
3. **Create deployment directory**
|
||||||
|
4. **Start and manage services**
|
||||||
|
|
||||||
|
## Quick Start Example
|
||||||
|
|
||||||
|
Here's a complete example using the built-in `test` stack:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Step 1: Setup (first time only)
|
||||||
|
laconic-so --stack test setup-repositories
|
||||||
|
laconic-so --stack test build-containers
|
||||||
|
|
||||||
|
# Step 2: Initialize deployment spec
|
||||||
|
laconic-so --stack test deploy init --output test-spec.yml
|
||||||
|
|
||||||
|
# Step 3: Create deployment directory
|
||||||
|
laconic-so --stack test deploy create \
|
||||||
|
--spec-file test-spec.yml \
|
||||||
|
--deployment-dir test-deployment
|
||||||
|
|
||||||
|
# Step 4: Start services
|
||||||
|
laconic-so deployment --dir test-deployment start
|
||||||
|
|
||||||
|
# View running services
|
||||||
|
laconic-so deployment --dir test-deployment ps
|
||||||
|
|
||||||
|
# View logs
|
||||||
|
laconic-so deployment --dir test-deployment logs
|
||||||
|
|
||||||
|
# Stop services (preserves data)
|
||||||
|
laconic-so deployment --dir test-deployment stop
|
||||||
|
```
|
||||||
|
|
||||||
|
## Deployment Workflows
|
||||||
|
|
||||||
|
Stack-orchestrator supports two deployment workflows:
|
||||||
|
|
||||||
|
### 1. Deployment Directory Workflow (Recommended)
|
||||||
|
|
||||||
|
This workflow creates a persistent deployment directory that contains all configuration and data.
|
||||||
|
|
||||||
|
**When to use:**
|
||||||
|
- Production deployments
|
||||||
|
- When you need to preserve configuration
|
||||||
|
- When you want to manage multiple deployments
|
||||||
|
- When you need persistent volume data
|
||||||
|
|
||||||
|
**Example:**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Initialize deployment spec
|
||||||
|
laconic-so --stack fixturenet-eth deploy init --output eth-spec.yml
|
||||||
|
|
||||||
|
# Optionally edit eth-spec.yml to customize configuration
|
||||||
|
|
||||||
|
# Create deployment directory
|
||||||
|
laconic-so --stack fixturenet-eth deploy create \
|
||||||
|
--spec-file eth-spec.yml \
|
||||||
|
--deployment-dir my-eth-deployment
|
||||||
|
|
||||||
|
# Start the deployment
|
||||||
|
laconic-so deployment --dir my-eth-deployment start
|
||||||
|
|
||||||
|
# Manage the deployment
|
||||||
|
laconic-so deployment --dir my-eth-deployment ps
|
||||||
|
laconic-so deployment --dir my-eth-deployment logs
|
||||||
|
laconic-so deployment --dir my-eth-deployment stop
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. Quick Deploy Workflow
|
||||||
|
|
||||||
|
This workflow deploys directly without creating a persistent deployment directory.
|
||||||
|
|
||||||
|
**When to use:**
|
||||||
|
- Quick testing
|
||||||
|
- Temporary deployments
|
||||||
|
- Simple stacks that don't require customization
|
||||||
|
|
||||||
|
**Example:**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Start the stack directly
|
||||||
|
laconic-so --stack test deploy up
|
||||||
|
|
||||||
|
# Check service status
|
||||||
|
laconic-so --stack test deploy port test 80
|
||||||
|
|
||||||
|
# View logs
|
||||||
|
laconic-so --stack test deploy logs
|
||||||
|
|
||||||
|
# Stop (preserves volumes)
|
||||||
|
laconic-so --stack test deploy down
|
||||||
|
|
||||||
|
# Stop and remove volumes
|
||||||
|
laconic-so --stack test deploy down --delete-volumes
|
||||||
|
```
|
||||||
|
|
||||||
|
## Real-World Example: Ethereum Fixturenet
|
||||||
|
|
||||||
|
Deploy a local Ethereum testnet with Geth and Lighthouse:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Setup (first time only)
|
||||||
|
laconic-so --stack fixturenet-eth setup-repositories
|
||||||
|
laconic-so --stack fixturenet-eth build-containers
|
||||||
|
|
||||||
|
# Initialize with default configuration
|
||||||
|
laconic-so --stack fixturenet-eth deploy init --output eth-spec.yml
|
||||||
|
|
||||||
|
# Create deployment
|
||||||
|
laconic-so --stack fixturenet-eth deploy create \
|
||||||
|
--spec-file eth-spec.yml \
|
||||||
|
--deployment-dir fixturenet-eth-deployment
|
||||||
|
|
||||||
|
# Start the network
|
||||||
|
laconic-so deployment --dir fixturenet-eth-deployment start
|
||||||
|
|
||||||
|
# Check status
|
||||||
|
laconic-so deployment --dir fixturenet-eth-deployment ps
|
||||||
|
|
||||||
|
# Access logs from specific service
|
||||||
|
laconic-so deployment --dir fixturenet-eth-deployment logs fixturenet-eth-geth-1
|
||||||
|
|
||||||
|
# Stop the network (preserves blockchain data)
|
||||||
|
laconic-so deployment --dir fixturenet-eth-deployment stop
|
||||||
|
|
||||||
|
# Start again - blockchain data is preserved
|
||||||
|
laconic-so deployment --dir fixturenet-eth-deployment start
|
||||||
|
|
||||||
|
# Clean up everything including data
|
||||||
|
laconic-so deployment --dir fixturenet-eth-deployment stop --delete-volumes
|
||||||
|
```
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
### Passing Configuration Parameters
|
||||||
|
|
||||||
|
Configuration can be passed in three ways:
|
||||||
|
|
||||||
|
**1. At init time via `--config` flag:**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
laconic-so --stack test deploy init --output spec.yml \
|
||||||
|
--config PARAM1=value1,PARAM2=value2
|
||||||
|
```
|
||||||
|
|
||||||
|
**2. Edit the spec file after init:**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Initialize
|
||||||
|
laconic-so --stack test deploy init --output spec.yml
|
||||||
|
|
||||||
|
# Edit spec.yml
|
||||||
|
vim spec.yml
|
||||||
|
```
|
||||||
|
|
||||||
|
Example spec.yml:
|
||||||
|
```yaml
|
||||||
|
stack: test
|
||||||
|
config:
|
||||||
|
PARAM1: value1
|
||||||
|
PARAM2: value2
|
||||||
|
```
|
||||||
|
|
||||||
|
**3. Docker Compose defaults:**
|
||||||
|
|
||||||
|
Environment variables defined in the stack's `docker-compose-*.yml` files are used as defaults. Configuration from the spec file overrides these defaults.
|
||||||
|
|
||||||
|
### Port Mapping
|
||||||
|
|
||||||
|
By default, services are accessible on randomly assigned host ports. To find the mapped port:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Find the host port for container port 80 on service 'webapp'
|
||||||
|
laconic-so deployment --dir my-deployment port webapp 80
|
||||||
|
|
||||||
|
# Output example: 0.0.0.0:32768
|
||||||
|
```
|
||||||
|
|
||||||
|
To configure fixed ports, edit the spec file before creating the deployment:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
network:
|
||||||
|
ports:
|
||||||
|
webapp:
|
||||||
|
- '8080:80' # Maps host port 8080 to container port 80
|
||||||
|
api:
|
||||||
|
- '3000:3000'
|
||||||
|
```
|
||||||
|
|
||||||
|
Then create the deployment:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
laconic-so --stack my-stack deploy create \
|
||||||
|
--spec-file spec.yml \
|
||||||
|
--deployment-dir my-deployment
|
||||||
|
```
|
||||||
|
|
||||||
|
### Volume Persistence
|
||||||
|
|
||||||
|
Volumes are preserved between stop/start cycles by default:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Stop but keep data
|
||||||
|
laconic-so deployment --dir my-deployment stop
|
||||||
|
|
||||||
|
# Start again - data is still there
|
||||||
|
laconic-so deployment --dir my-deployment start
|
||||||
|
```
|
||||||
|
|
||||||
|
To completely remove all data:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Stop and delete all volumes
|
||||||
|
laconic-so deployment --dir my-deployment stop --delete-volumes
|
||||||
|
```
|
||||||
|
|
||||||
|
Volume data is stored in `<deployment-dir>/data/`.
|
||||||
|
|
||||||
|
## Common Operations
|
||||||
|
|
||||||
|
### Viewing Logs
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# All services, continuous follow
|
||||||
|
laconic-so deployment --dir my-deployment logs --follow
|
||||||
|
|
||||||
|
# Last 100 lines from all services
|
||||||
|
laconic-so deployment --dir my-deployment logs --tail 100
|
||||||
|
|
||||||
|
# Specific service only
|
||||||
|
laconic-so deployment --dir my-deployment logs webapp
|
||||||
|
|
||||||
|
# Combine options
|
||||||
|
laconic-so deployment --dir my-deployment logs --tail 50 --follow webapp
|
||||||
|
```
|
||||||
|
|
||||||
|
### Executing Commands in Containers
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Execute a command in a running service
|
||||||
|
laconic-so deployment --dir my-deployment exec webapp ls -la
|
||||||
|
|
||||||
|
# Interactive shell
|
||||||
|
laconic-so deployment --dir my-deployment exec webapp /bin/bash
|
||||||
|
|
||||||
|
# Run command with specific environment variables
|
||||||
|
laconic-so deployment --dir my-deployment exec webapp env VAR=value command
|
||||||
|
```
|
||||||
|
|
||||||
|
### Checking Service Status
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# List all running services
|
||||||
|
laconic-so deployment --dir my-deployment ps
|
||||||
|
|
||||||
|
# Check using Docker directly
|
||||||
|
docker ps
|
||||||
|
```
|
||||||
|
|
||||||
|
### Updating a Running Deployment
|
||||||
|
|
||||||
|
If you need to change configuration after deployment:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 1. Edit the spec file
|
||||||
|
vim my-deployment/spec.yml
|
||||||
|
|
||||||
|
# 2. Regenerate configuration
|
||||||
|
laconic-so deployment --dir my-deployment update
|
||||||
|
|
||||||
|
# 3. Restart services to apply changes
|
||||||
|
laconic-so deployment --dir my-deployment stop
|
||||||
|
laconic-so deployment --dir my-deployment start
|
||||||
|
```
|
||||||
|
|
||||||
|
## Multi-Service Deployments
|
||||||
|
|
||||||
|
Many stacks deploy multiple services that work together:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Deploy a stack with multiple services
|
||||||
|
laconic-so --stack laconicd-with-console deploy init --output spec.yml
|
||||||
|
laconic-so --stack laconicd-with-console deploy create \
|
||||||
|
--spec-file spec.yml \
|
||||||
|
--deployment-dir laconicd-deployment
|
||||||
|
|
||||||
|
laconic-so deployment --dir laconicd-deployment start
|
||||||
|
|
||||||
|
# View all services
|
||||||
|
laconic-so deployment --dir laconicd-deployment ps
|
||||||
|
|
||||||
|
# View logs from specific services
|
||||||
|
laconic-so deployment --dir laconicd-deployment logs laconicd
|
||||||
|
laconic-so deployment --dir laconicd-deployment logs console
|
||||||
|
```
|
||||||
|
|
||||||
|
## ConfigMaps
|
||||||
|
|
||||||
|
ConfigMaps allow you to mount configuration files into containers:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 1. Create the config directory in your deployment
|
||||||
|
mkdir -p my-deployment/data/my-config
|
||||||
|
echo "database_url=postgres://localhost" > my-deployment/data/my-config/app.conf
|
||||||
|
|
||||||
|
# 2. Reference in spec file
|
||||||
|
vim my-deployment/spec.yml
|
||||||
|
```
|
||||||
|
|
||||||
|
Add to spec.yml:
|
||||||
|
```yaml
|
||||||
|
configmaps:
|
||||||
|
my-config: ./data/my-config
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 3. Restart to apply
|
||||||
|
laconic-so deployment --dir my-deployment stop
|
||||||
|
laconic-so deployment --dir my-deployment start
|
||||||
|
```
|
||||||
|
|
||||||
|
The files will be mounted in the container at `/config/` (or as specified by the stack).
|
||||||
|
|
||||||
|
## Deployment Directory Structure
|
||||||
|
|
||||||
|
A typical deployment directory contains:
|
||||||
|
|
||||||
|
```
|
||||||
|
my-deployment/
|
||||||
|
├── compose/
|
||||||
|
│ └── docker-compose-*.yml # Generated compose files
|
||||||
|
├── config.env # Environment variables
|
||||||
|
├── deployment.yml # Deployment metadata
|
||||||
|
├── spec.yml # Deployment specification
|
||||||
|
└── data/ # Volume mounts and configs
|
||||||
|
├── service-data/ # Persistent service data
|
||||||
|
└── config-maps/ # ConfigMap files
|
||||||
|
```
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
### Common Issues
|
||||||
|
|
||||||
|
**Problem: "Cannot connect to Docker daemon"**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Ensure Docker is running
|
||||||
|
docker ps
|
||||||
|
|
||||||
|
# Start Docker if needed (macOS)
|
||||||
|
open -a Docker
|
||||||
|
|
||||||
|
# Start Docker (Linux)
|
||||||
|
sudo systemctl start docker
|
||||||
|
```
|
||||||
|
|
||||||
|
**Problem: "Port already in use"**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Either stop the conflicting service or use different ports
|
||||||
|
# Edit spec.yml before creating deployment:
|
||||||
|
|
||||||
|
network:
|
||||||
|
ports:
|
||||||
|
webapp:
|
||||||
|
- '8081:80' # Use 8081 instead of 8080
|
||||||
|
```
|
||||||
|
|
||||||
|
**Problem: "Image not found"**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Build containers first
|
||||||
|
laconic-so --stack your-stack build-containers
|
||||||
|
```
|
||||||
|
|
||||||
|
**Problem: Volumes not persisting**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Check if you used --delete-volumes when stopping
|
||||||
|
# Volume data is in: <deployment-dir>/data/
|
||||||
|
|
||||||
|
# Don't use --delete-volumes if you want to keep data:
|
||||||
|
laconic-so deployment --dir my-deployment stop
|
||||||
|
|
||||||
|
# Only use --delete-volumes when you want to reset completely:
|
||||||
|
laconic-so deployment --dir my-deployment stop --delete-volumes
|
||||||
|
```
|
||||||
|
|
||||||
|
**Problem: Services not starting**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Check logs for errors
|
||||||
|
laconic-so deployment --dir my-deployment logs
|
||||||
|
|
||||||
|
# Check Docker container status
|
||||||
|
docker ps -a
|
||||||
|
|
||||||
|
# Try stopping and starting again
|
||||||
|
laconic-so deployment --dir my-deployment stop
|
||||||
|
laconic-so deployment --dir my-deployment start
|
||||||
|
```
|
||||||
|
|
||||||
|
### Inspecting Deployment State
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Check deployment directory structure
|
||||||
|
ls -la my-deployment/
|
||||||
|
|
||||||
|
# Check running containers
|
||||||
|
docker ps
|
||||||
|
|
||||||
|
# Check container details
|
||||||
|
docker inspect <container-name>
|
||||||
|
|
||||||
|
# Check networks
|
||||||
|
docker network ls
|
||||||
|
|
||||||
|
# Check volumes
|
||||||
|
docker volume ls
|
||||||
|
```
|
||||||
|
|
||||||
|
## CLI Commands Reference
|
||||||
|
|
||||||
|
### Stack Operations
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Clone required repositories
|
||||||
|
laconic-so --stack <name> setup-repositories
|
||||||
|
|
||||||
|
# Build container images
|
||||||
|
laconic-so --stack <name> build-containers
|
||||||
|
```
|
||||||
|
|
||||||
|
### Deployment Initialization
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Initialize deployment spec with defaults
|
||||||
|
laconic-so --stack <name> deploy init --output <spec-file>
|
||||||
|
|
||||||
|
# Initialize with configuration
|
||||||
|
laconic-so --stack <name> deploy init --output <spec-file> \
|
||||||
|
--config PARAM1=value1,PARAM2=value2
|
||||||
|
```
|
||||||
|
|
||||||
|
### Deployment Creation
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Create deployment directory from spec
|
||||||
|
laconic-so --stack <name> deploy create \
|
||||||
|
--spec-file <spec-file> \
|
||||||
|
--deployment-dir <dir>
|
||||||
|
```
|
||||||
|
|
||||||
|
### Deployment Management
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Start all services
|
||||||
|
laconic-so deployment --dir <dir> start
|
||||||
|
|
||||||
|
# Stop services (preserves volumes)
|
||||||
|
laconic-so deployment --dir <dir> stop
|
||||||
|
|
||||||
|
# Stop and remove volumes
|
||||||
|
laconic-so deployment --dir <dir> stop --delete-volumes
|
||||||
|
|
||||||
|
# List running services
|
||||||
|
laconic-so deployment --dir <dir> ps
|
||||||
|
|
||||||
|
# View logs
|
||||||
|
laconic-so deployment --dir <dir> logs [--tail N] [--follow] [service]
|
||||||
|
|
||||||
|
# Show mapped port
|
||||||
|
laconic-so deployment --dir <dir> port <service> <private-port>
|
||||||
|
|
||||||
|
# Execute command in service
|
||||||
|
laconic-so deployment --dir <dir> exec <service> <command>
|
||||||
|
|
||||||
|
# Update configuration
|
||||||
|
laconic-so deployment --dir <dir> update
|
||||||
|
```
|
||||||
|
|
||||||
|
### Quick Deploy Commands
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Start stack directly
|
||||||
|
laconic-so --stack <name> deploy up
|
||||||
|
|
||||||
|
# Stop stack
|
||||||
|
laconic-so --stack <name> deploy down [--delete-volumes]
|
||||||
|
|
||||||
|
# View logs
|
||||||
|
laconic-so --stack <name> deploy logs
|
||||||
|
|
||||||
|
# Show port mapping
|
||||||
|
laconic-so --stack <name> deploy port <service> <port>
|
||||||
|
```
|
||||||
|
|
||||||
|
## Related Documentation
|
||||||
|
|
||||||
|
- [CLI Reference](./cli.md) - Complete CLI command documentation
|
||||||
|
- [Adding a New Stack](./adding-a-new-stack.md) - Creating custom stacks
|
||||||
|
- [Specification](./spec.md) - Internal structure and design
|
||||||
|
- [Kubernetes Enhancements](./k8s-deployment-enhancements.md) - Advanced K8s deployment options
|
||||||
|
- [Web App Deployment](./webapp.md) - Deploying web applications
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
For more examples, see the test scripts:
|
||||||
|
- `scripts/quick-deploy-test.sh` - Quick deployment example
|
||||||
|
- `tests/deploy/run-deploy-test.sh` - Comprehensive test showing all features
|
||||||
|
|
||||||
|
## Summary
|
||||||
|
|
||||||
|
- Docker Compose is the default and recommended deployment mode
|
||||||
|
- Two workflows: deployment directory (recommended) or quick deploy
|
||||||
|
- The standard workflow is: setup → build → init → create → start
|
||||||
|
- Configuration is flexible with multiple override layers
|
||||||
|
- Volume persistence is automatic unless explicitly deleted
|
||||||
|
- All deployment state is contained in the deployment directory
|
||||||
|
- For Kubernetes deployments, see separate K8s documentation
|
||||||
|
|
||||||
|
You're now ready to deploy stacks using stack-orchestrator with Docker Compose!
|
||||||
@@ -56,7 +56,7 @@ laconic-so --stack fixturenet-laconicd build-npms
|
|||||||
Navigate to the Gitea console and switch to the `cerc-io` user then find the `Packages` tab to confirm that these two npm packages have been published:
|
Navigate to the Gitea console and switch to the `cerc-io` user then find the `Packages` tab to confirm that these two npm packages have been published:
|
||||||
|
|
||||||
- `@cerc-io/laconic-registry-cli`
|
- `@cerc-io/laconic-registry-cli`
|
||||||
- `@cerc-io/laconic-sdk`
|
- `@cerc-io/registry-sdk`
|
||||||
|
|
||||||
### Build and deploy fixturenet containers
|
### Build and deploy fixturenet containers
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,113 @@
|
|||||||
|
# Helm Chart Generation
|
||||||
|
|
||||||
|
Generate Kubernetes Helm charts from stack compose files using Kompose.
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
|
||||||
|
Install Kompose:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Linux
|
||||||
|
curl -L https://github.com/kubernetes/kompose/releases/download/v1.34.0/kompose-linux-amd64 -o kompose
|
||||||
|
chmod +x kompose
|
||||||
|
sudo mv kompose /usr/local/bin/
|
||||||
|
|
||||||
|
# macOS
|
||||||
|
brew install kompose
|
||||||
|
|
||||||
|
# Verify
|
||||||
|
kompose version
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
### 1. Create spec file
|
||||||
|
|
||||||
|
```bash
|
||||||
|
laconic-so --stack <stack-name> deploy --deploy-to k8s init \
|
||||||
|
--kube-config ~/.kube/config \
|
||||||
|
--output spec.yml
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. Generate Helm chart
|
||||||
|
|
||||||
|
```bash
|
||||||
|
laconic-so --stack <stack-name> deploy create \
|
||||||
|
--spec-file spec.yml \
|
||||||
|
--deployment-dir my-deployment \
|
||||||
|
--helm-chart
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. Deploy to Kubernetes
|
||||||
|
|
||||||
|
```bash
|
||||||
|
helm install my-release my-deployment/chart
|
||||||
|
kubectl get pods -n zenith
|
||||||
|
```
|
||||||
|
|
||||||
|
## Output Structure
|
||||||
|
|
||||||
|
```bash
|
||||||
|
my-deployment/
|
||||||
|
├── spec.yml # Reference
|
||||||
|
├── stack.yml # Reference
|
||||||
|
└── chart/ # Helm chart
|
||||||
|
├── Chart.yaml
|
||||||
|
├── README.md
|
||||||
|
└── templates/
|
||||||
|
└── *.yaml
|
||||||
|
```
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Generate chart for stage1-zenithd
|
||||||
|
laconic-so --stack stage1-zenithd deploy --deploy-to k8s init \
|
||||||
|
--kube-config ~/.kube/config \
|
||||||
|
--output stage1-spec.yml
|
||||||
|
|
||||||
|
laconic-so --stack stage1-zenithd deploy create \
|
||||||
|
--spec-file stage1-spec.yml \
|
||||||
|
--deployment-dir stage1-deployment \
|
||||||
|
--helm-chart
|
||||||
|
|
||||||
|
# Deploy
|
||||||
|
helm install stage1-zenithd stage1-deployment/chart
|
||||||
|
```
|
||||||
|
|
||||||
|
## Production Deployment (TODO)
|
||||||
|
|
||||||
|
### Local Development
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Access services using port-forward
|
||||||
|
kubectl port-forward service/zenithd 26657:26657
|
||||||
|
kubectl port-forward service/nginx-api-proxy 1317:80
|
||||||
|
kubectl port-forward service/cosmos-explorer 4173:4173
|
||||||
|
```
|
||||||
|
|
||||||
|
### Production Access Options
|
||||||
|
|
||||||
|
- Option 1: Ingress + cert-manager (Recommended)
|
||||||
|
- Install ingress-nginx + cert-manager
|
||||||
|
- Point DNS to cluster LoadBalancer IP
|
||||||
|
- Auto-provisions Let's Encrypt TLS certs
|
||||||
|
- Access: `https://api.zenith.example.com`
|
||||||
|
- Option 2: Cloud LoadBalancer
|
||||||
|
- Use cloud provider's LoadBalancer service type
|
||||||
|
- Point DNS to assigned external IP
|
||||||
|
- Manual TLS cert management
|
||||||
|
- Option 3: Bare Metal (MetalLB + Ingress)
|
||||||
|
- MetalLB provides LoadBalancer IPs from local network
|
||||||
|
- Same Ingress setup as cloud
|
||||||
|
- Option 4: NodePort + External Proxy
|
||||||
|
- Expose services on 30000-32767 range
|
||||||
|
- External nginx/Caddy proxies 80/443 → NodePort
|
||||||
|
- Manual cert management
|
||||||
|
|
||||||
|
### Changes Needed
|
||||||
|
|
||||||
|
- Add Ingress template to charts
|
||||||
|
- Add TLS configuration to values.yaml
|
||||||
|
- Document cert-manager setup
|
||||||
|
- Add production deployment guide
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
# K8S Deployment Enhancements
|
||||||
|
## Controlling pod placement
|
||||||
|
The placement of pods created as part of a stack deployment can be controlled to either avoid certain nodes, or require certain nodes.
|
||||||
|
### Pod/Node Affinity
|
||||||
|
Node affinity rules applied to pods target node labels. The effect is that a pod can only be placed on a node having the specified label value. Note that other pods that do not have any node affinity rules can also be placed on those same nodes. Thus node affinity for a pod controls where that pod can be placed, but does not control where other pods are placed.
|
||||||
|
|
||||||
|
Node affinity for stack pods is specified in the deployment's `spec.yml` file as follows:
|
||||||
|
```
|
||||||
|
node-affinities:
|
||||||
|
- label: nodetype
|
||||||
|
value: typeb
|
||||||
|
```
|
||||||
|
This example denotes that the stack's pods should only be placed on nodes that have the label `nodetype` with value `typeb`.
|
||||||
|
### Node Taint Toleration
|
||||||
|
K8s nodes can be given one or more "taints". These are special fields (distinct from labels) with a name (key) and optional value.
|
||||||
|
When placing pods, the k8s scheduler will only assign a pod to a tainted node if the pod posesses a corresponding "toleration".
|
||||||
|
This is metadata associated with the pod that specifies that the pod "tolerates" a given taint.
|
||||||
|
Therefore taint toleration provides a mechanism by which only certain pods can be placed on specific nodes, and provides a complementary mechanism to node affinity.
|
||||||
|
|
||||||
|
Taint toleration for stack pods is specified in the deployment's `spec.yml` file as follows:
|
||||||
|
```
|
||||||
|
node-tolerations:
|
||||||
|
- key: nodetype
|
||||||
|
value: typeb
|
||||||
|
```
|
||||||
|
This example denotes that the stack's pods will tolerate a taint: `nodetype=typeb`
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
# Running a laconicd fixturenet with console
|
# Running a laconicd fixturenet with console
|
||||||
|
|
||||||
The following tutorial explains the steps to run a laconicd fixturenet with CLI and web console that displays records in the registry. It is designed as an introduction to Stack Orchestrator and to showcase one component of the Laconic Stack. Prior to Stack Orchestrator, the following 4 repositories had to be cloned and setup manually:
|
The following tutorial explains the steps to run a laconicd fixturenet with CLI and web console that displays records in the registry. It is designed as an introduction to Stack Orchestrator and to showcase one component of the Laconic Stack. Prior to Stack Orchestrator, the following repositories had to be cloned and setup manually:
|
||||||
|
|
||||||
- https://git.vdb.to/cerc-io/laconicd
|
- https://git.vdb.to/cerc-io/laconicd
|
||||||
- https://git.vdb.to/cerc-io/laconic-sdk
|
|
||||||
- https://git.vdb.to/cerc-io/laconic-registry-cli
|
- https://git.vdb.to/cerc-io/laconic-registry-cli
|
||||||
- https://git.vdb.to/cerc-io/laconic-console
|
- https://git.vdb.to/cerc-io/laconic-console
|
||||||
|
|
||||||
@@ -51,7 +50,7 @@ To avoid hiccups on Mac M1/M2 and any local machine nuances that may affect the
|
|||||||
1. Get the repositories
|
1. Get the repositories
|
||||||
|
|
||||||
```
|
```
|
||||||
laconic-so --stack fixturenet-laconic-loaded setup-repositories --include git.vdb.to/cerc-io/laconicd,git.vdb.to/cerc-io/laconic-sdk,git.vdb.to/cerc-io/laconic-registry-cli,git.vdb.to/cerc-io/laconic-console
|
laconic-so --stack fixturenet-laconic-loaded setup-repositories --include git.vdb.to/cerc-io/laconicd
|
||||||
```
|
```
|
||||||
|
|
||||||
1. Build the containers:
|
1. Build the containers:
|
||||||
@@ -76,6 +75,8 @@ To avoid hiccups on Mac M1/M2 and any local machine nuances that may affect the
|
|||||||
1. Create a deployment directory for the stack:
|
1. Create a deployment directory for the stack:
|
||||||
```
|
```
|
||||||
laconic-so --stack fixturenet-laconic-loaded deploy init --output laconic-loaded.spec --map-ports-to-host any-same --config LACONIC_HOSTED_ENDPOINT=$BACKEND_ENDPOINT
|
laconic-so --stack fixturenet-laconic-loaded deploy init --output laconic-loaded.spec --map-ports-to-host any-same --config LACONIC_HOSTED_ENDPOINT=$BACKEND_ENDPOINT
|
||||||
|
|
||||||
|
# Update port mapping in the laconic-loaded.spec file to resolve port conflicts on host if any
|
||||||
```
|
```
|
||||||
```
|
```
|
||||||
laconic-so --stack fixturenet-laconic-loaded deploy create --deployment-dir laconic-loaded-deployment --spec-file laconic-loaded.spec
|
laconic-so --stack fixturenet-laconic-loaded deploy create --deployment-dir laconic-loaded-deployment --spec-file laconic-loaded.spec
|
||||||
@@ -95,16 +96,15 @@ To avoid hiccups on Mac M1/M2 and any local machine nuances that may affect the
|
|||||||
You'll see output from `laconicd` and the block height should be >1 to confirm it is running:
|
You'll see output from `laconicd` and the block height should be >1 to confirm it is running:
|
||||||
|
|
||||||
```
|
```
|
||||||
laconic-5cd0a80c1442c3044c8b295d26426bae-laconicd-1 | 9:29PM INF indexed block exents height=12 module=txindex server=node
|
laconicd-1 | 6:12AM INF indexed block events height=16 module=txindex
|
||||||
laconic-5cd0a80c1442c3044c8b295d26426bae-laconicd-1 | 9:30PM INF Timed out dur=4976.960115 height=13 module=consensus round=0 server=node step=1
|
laconicd-1 | 6:12AM INF Timed out dur=2993.893332 height=17 module=consensus round=0 step=RoundStepNewHeight
|
||||||
laconic-5cd0a80c1442c3044c8b295d26426bae-laconicd-1 | 9:30PM INF received proposal module=consensus proposal={"Type":32,"block_id":{"hash":"D26C088A711F912ADB97888C269F628DA33153795621967BE44DCB43C3D03CA4","parts":{"hash":"22411A20B7F14CDA33244420FBDDAF24450C0628C7A06034FF22DAC3699DDCC8","total":1}},"height":13,"pol_round":-1,"round":0,"signature":"DEuqnaQmvyYbUwckttJmgKdpRu6eVm9i+9rQ1pIrV2PidkMNdWRZBLdmNghkIrUzGbW8Xd7UVJxtLRmwRASgBg==","timestamp":"2023-04-18T21:30:01.49450663Z"} server=node
|
laconicd-1 | 6:12AM INF received proposal module=consensus proposal="Proposal{17/0 (E15D03C180CE607AE8340A1325A0C134DFB4E1ADD992E173C701EBD362523267:1:DF138772FEF0, -1) 6A6F3B0A42B3 @ 2024-07-25T06:12:31.952967053Z}" proposer=86970D950BC9C16F3991A52D9C6DC55BA478A7C6
|
||||||
laconic-5cd0a80c1442c3044c8b295d26426bae-laconicd-1 | 9:30PM INF received complete proposal block hash=D26C088A711F912ADB97888C269F628DA33153795621967BE44DCB43C3D03CA4 height=13 module=consensus server=node
|
laconicd-1 | 6:12AM INF received complete proposal block hash=E15D03C180CE607AE8340A1325A0C134DFB4E1ADD992E173C701EBD362523267 height=17 module=consensus
|
||||||
laconic-5cd0a80c1442c3044c8b295d26426bae-laconicd-1 | 9:30PM INF finalizing commit of block hash={} height=13 module=consensus num_txs=0 root=1A8CA1AF139CCC80EC007C6321D8A63A46A793386EE2EDF9A5CA0AB2C90728B7 server=node
|
laconicd-1 | 6:12AM INF finalizing commit of block hash=E15D03C180CE607AE8340A1325A0C134DFB4E1ADD992E173C701EBD362523267 height=17 module=consensus num_txs=0 root=AF4941107DC718ED1425E77A3DC7F1154FB780B7A7DE20288DC43442203527E3
|
||||||
laconic-5cd0a80c1442c3044c8b295d26426bae-laconicd-1 | 9:30PM INF minted coins from module account amount=2059730459416582643aphoton from=mint module=x/bank
|
laconicd-1 | 6:12AM INF finalized block block_app_hash=26A665360BB1EE64E54F97F2A5AB7F621B33A86D9896574000C05DE63F43F788 height=17 module=state num_txs_res=0 num_val_updates=0
|
||||||
laconic-5cd0a80c1442c3044c8b295d26426bae-laconicd-1 | 9:30PM INF executed block height=13 module=state num_invalid_txs=0 num_valid_txs=0 server=node
|
laconicd-1 | 6:12AM INF executed block app_hash=26A665360BB1EE64E54F97F2A5AB7F621B33A86D9896574000C05DE63F43F788 height=17 module=state
|
||||||
laconic-5cd0a80c1442c3044c8b295d26426bae-laconicd-1 | 9:30PM INF commit synced commit=436F6D6D697449447B5B363520313037203630203232372039352038352032303820313334203231392032303520313433203130372031343920313431203139203139322038362031323720362031383520323533203137362031333820313735203135392031383620323334203135382031323120313431203230342037335D3A447D
|
laconicd-1 | 6:12AM INF committed state block_app_hash=AF4941107DC718ED1425E77A3DC7F1154FB780B7A7DE20288DC43442203527E3 height=17 module=state
|
||||||
laconic-5cd0a80c1442c3044c8b295d26426bae-laconicd-1 | 9:30PM INF committed state app_hash=416B3CE35F55D086DBCD8F6B958D13C0567F06B9FDB08AAF9FBAEA9E798DCC49 height=13 module=state num_txs=0 server=node
|
laconicd-1 | 6:12AM INF indexed block events height=17 module=txindex
|
||||||
laconic-5cd0a80c1442c3044c8b295d26426bae-laconicd-1 | 9:30PM INF indexed block exents height=13 module=txindex server=node
|
|
||||||
```
|
```
|
||||||
|
|
||||||
4. Confirm operation of the registry CLI:
|
4. Confirm operation of the registry CLI:
|
||||||
@@ -117,30 +117,30 @@ To avoid hiccups on Mac M1/M2 and any local machine nuances that may affect the
|
|||||||
{
|
{
|
||||||
"version": "0.3.0",
|
"version": "0.3.0",
|
||||||
"node": {
|
"node": {
|
||||||
"id": "4216af2ac9f68bda33a38803fc1b5c9559312c1d",
|
"id": "6e072894aa1f5d9535a1127a0d7a7f8e65100a2c",
|
||||||
"network": "laconic_9000-1",
|
"network": "laconic_9000-1",
|
||||||
"moniker": "localtestnet"
|
"moniker": "localtestnet"
|
||||||
},
|
},
|
||||||
"sync": {
|
"sync": {
|
||||||
"latest_block_hash": "1BDF4CB9AE2390DA65BCF997C83133C18014FCDDCAE03708488F0B56FCEEA429",
|
"latestBlockHash": "260102C283D0411CFBA0270F7DC182650FFCA737A2F6F652A985F6065696F590",
|
||||||
"latest_block_height": "5",
|
"latestBlockHeight": "49",
|
||||||
"latest_block_time": "2023-08-09 16:00:30.386903172 +0000 UTC",
|
"latestBlockTime": "2024-07-25 06:14:05.626744215 +0000 UTC",
|
||||||
"catching_up": false
|
"catchingUp": false
|
||||||
},
|
},
|
||||||
"validator": {
|
"validator": {
|
||||||
"address": "651FBC700B747C76E90ACFC18CC9508C3D0905B9",
|
"address": "86970D950BC9C16F3991A52D9C6DC55BA478A7C6",
|
||||||
"voting_power": "1000000000000000"
|
"votingPower": "1000000000000000"
|
||||||
},
|
},
|
||||||
"validators": [
|
"validators": [
|
||||||
{
|
{
|
||||||
"address": "651FBC700B747C76E90ACFC18CC9508C3D0905B9",
|
"address": "86970D950BC9C16F3991A52D9C6DC55BA478A7C6",
|
||||||
"voting_power": "1000000000000000",
|
"votingPower": "1000000000000000",
|
||||||
"proposer_priority": "0"
|
"proposerPriority": "0"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"num_peers": "0",
|
"numPeers": "0",
|
||||||
"peers": [],
|
"peers": [],
|
||||||
"disk_usage": "292.0K"
|
"diskUsage": "688K"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -186,13 +186,13 @@ wns
|
|||||||
1. The following command will create a bond and publish a record:
|
1. The following command will create a bond and publish a record:
|
||||||
|
|
||||||
```
|
```
|
||||||
laconic-so --stack fixturenet-laconic-loaded deploy exec cli ./scripts/create-demo-records.sh
|
laconic-so deployment --dir laconic-loaded-deployment exec cli ./scripts/create-demo-records.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
You'll get an output like:
|
You'll get an output like:
|
||||||
|
|
||||||
```
|
```
|
||||||
Balance is: 99998999999999998999600000
|
Balance is: 9.9999e+25
|
||||||
Created bond with id: dd88e8d6f9567b32b28e70552aea4419c5dd3307ebae85a284d1fe38904e301a
|
Created bond with id: dd88e8d6f9567b32b28e70552aea4419c5dd3307ebae85a284d1fe38904e301a
|
||||||
Published demo-record-1.yml with id: bafyreierh3xnfivexlscdwubvczmddsnf46uytyfvrbdhkjzztvsz6ruly
|
Published demo-record-1.yml with id: bafyreierh3xnfivexlscdwubvczmddsnf46uytyfvrbdhkjzztvsz6ruly
|
||||||
```
|
```
|
||||||
@@ -223,5 +223,5 @@ record:
|
|||||||
- e.g,:
|
- e.g,:
|
||||||
|
|
||||||
```
|
```
|
||||||
laconic-so --stack fixturenet-laconic-loaded deploy exec cli "laconic registry record list"
|
laconic-so deployment --dir laconic-loaded-deployment exec cli "laconic registry record list"
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -26,4 +26,3 @@ $ ./scripts/tag_new_release.sh 1 0 17
|
|||||||
$ ./scripts/build_shiv_package.sh
|
$ ./scripts/build_shiv_package.sh
|
||||||
$ ./scripts/publish_shiv_package_github.sh 1 0 17
|
$ ./scripts/publish_shiv_package_github.sh 1 0 17
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,128 @@
|
|||||||
|
# Deploying to the Laconic Network
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
|
||||||
|
The Laconic network uses a **registry-based deployment model** where everything is published as blockchain records.
|
||||||
|
|
||||||
|
## Key Documentation in stack-orchestrator
|
||||||
|
|
||||||
|
- `docs/laconicd-with-console.md` - Setting up a laconicd network
|
||||||
|
- `docs/webapp.md` - Webapp building/running
|
||||||
|
- `stack_orchestrator/deploy/webapp/` - Implementation (14 modules)
|
||||||
|
|
||||||
|
## Core Concepts
|
||||||
|
|
||||||
|
### LRN (Laconic Resource Name)
|
||||||
|
Format: `lrn://laconic/[namespace]/[name]`
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
- `lrn://laconic/deployers/my-deployer-name`
|
||||||
|
- `lrn://laconic/dns/example.com`
|
||||||
|
- `lrn://laconic/deployments/example.com`
|
||||||
|
|
||||||
|
### Registry Record Types
|
||||||
|
|
||||||
|
| Record Type | Purpose |
|
||||||
|
|-------------|---------|
|
||||||
|
| `ApplicationRecord` | Published app metadata |
|
||||||
|
| `WebappDeployer` | Deployment service offering |
|
||||||
|
| `ApplicationDeploymentRequest` | User's request to deploy |
|
||||||
|
| `ApplicationDeploymentAuction` | Optional bidding for deployers |
|
||||||
|
| `ApplicationDeploymentRecord` | Completed deployment result |
|
||||||
|
|
||||||
|
## Deployment Workflows
|
||||||
|
|
||||||
|
### 1. Direct Deployment
|
||||||
|
|
||||||
|
```
|
||||||
|
User publishes ApplicationDeploymentRequest
|
||||||
|
→ targets specific WebappDeployer (by LRN)
|
||||||
|
→ includes payment TX hash
|
||||||
|
→ Deployer picks up request, builds, deploys, publishes result
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. Auction-Based Deployment
|
||||||
|
|
||||||
|
```
|
||||||
|
User publishes ApplicationDeploymentAuction
|
||||||
|
→ Deployers bid (commit/reveal phases)
|
||||||
|
→ Winner selected
|
||||||
|
→ User publishes request targeting winner
|
||||||
|
```
|
||||||
|
|
||||||
|
## Key CLI Commands
|
||||||
|
|
||||||
|
### Publish a Deployer Service
|
||||||
|
```bash
|
||||||
|
laconic-so publish-webapp-deployer --laconic-config config.yml \
|
||||||
|
--api-url https://deployer-api.example.com \
|
||||||
|
--name my-deployer \
|
||||||
|
--payment-address laconic1... \
|
||||||
|
--minimum-payment 1000alnt
|
||||||
|
```
|
||||||
|
|
||||||
|
### Request Deployment (User Side)
|
||||||
|
```bash
|
||||||
|
laconic-so request-webapp-deployment --laconic-config config.yml \
|
||||||
|
--app lrn://laconic/apps/my-app \
|
||||||
|
--deployer lrn://laconic/deployers/xyz \
|
||||||
|
--make-payment auto
|
||||||
|
```
|
||||||
|
|
||||||
|
### Run Deployer Service (Deployer Side)
|
||||||
|
```bash
|
||||||
|
laconic-so deploy-webapp-from-registry --laconic-config config.yml --discover
|
||||||
|
```
|
||||||
|
|
||||||
|
## Laconic Config File
|
||||||
|
|
||||||
|
All tools require a laconic config file (`laconic.toml`):
|
||||||
|
|
||||||
|
```toml
|
||||||
|
[cosmos]
|
||||||
|
address_prefix = "laconic"
|
||||||
|
chain_id = "laconic_9000-1"
|
||||||
|
endpoint = "http://localhost:26657"
|
||||||
|
key = "<account-name>"
|
||||||
|
password = "<account-password>"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Setting Up a Local Laconicd Network
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Clone and build
|
||||||
|
laconic-so --stack fixturenet-laconic-loaded setup-repositories
|
||||||
|
laconic-so --stack fixturenet-laconic-loaded build-containers
|
||||||
|
laconic-so --stack fixturenet-laconic-loaded deploy create
|
||||||
|
laconic-so deployment --dir laconic-loaded-deployment start
|
||||||
|
|
||||||
|
# Check status
|
||||||
|
laconic-so deployment --dir laconic-loaded-deployment exec cli "laconic registry status"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Key Implementation Files
|
||||||
|
|
||||||
|
| File | Purpose |
|
||||||
|
|------|---------|
|
||||||
|
| `publish_webapp_deployer.py` | Register deployment service on network |
|
||||||
|
| `publish_deployment_auction.py` | Create auction for deployers to bid on |
|
||||||
|
| `handle_deployment_auction.py` | Monitor and bid on auctions (deployer-side) |
|
||||||
|
| `request_webapp_deployment.py` | Create deployment request (user-side) |
|
||||||
|
| `deploy_webapp_from_registry.py` | Process requests and deploy (deployer-side) |
|
||||||
|
| `request_webapp_undeployment.py` | Request app removal |
|
||||||
|
| `undeploy_webapp_from_registry.py` | Process removal requests |
|
||||||
|
| `util.py` | LaconicRegistryClient - all registry interactions |
|
||||||
|
|
||||||
|
## Payment System
|
||||||
|
|
||||||
|
- **Token Denom**: `alnt` (Laconic network tokens)
|
||||||
|
- **Payment Options**:
|
||||||
|
- `--make-payment`: Create new payment with amount (or "auto" for deployer's minimum)
|
||||||
|
- `--use-payment`: Reference existing payment TX
|
||||||
|
|
||||||
|
## What's NOT Well-Documented
|
||||||
|
|
||||||
|
1. No end-to-end tutorial for full deployment workflow
|
||||||
|
2. Stack publishing (vs webapp) process unclear
|
||||||
|
3. LRN naming conventions not formally specified
|
||||||
|
4. Payment economics and token mechanics
|
||||||
+110
@@ -0,0 +1,110 @@
|
|||||||
|
[build-system]
|
||||||
|
requires = ["setuptools>=61.0", "wheel"]
|
||||||
|
build-backend = "setuptools.build_meta"
|
||||||
|
|
||||||
|
[project]
|
||||||
|
name = "laconic-stack-orchestrator"
|
||||||
|
version = "1.1.0"
|
||||||
|
description = "Orchestrates deployment of the Laconic stack"
|
||||||
|
readme = "README.md"
|
||||||
|
license = {text = "GNU Affero General Public License"}
|
||||||
|
authors = [
|
||||||
|
{name = "Cerc", email = "info@cerc.io"}
|
||||||
|
]
|
||||||
|
requires-python = ">=3.8"
|
||||||
|
classifiers = [
|
||||||
|
"Programming Language :: Python :: 3.8",
|
||||||
|
"Operating System :: OS Independent",
|
||||||
|
]
|
||||||
|
dependencies = [
|
||||||
|
"python-decouple>=3.8",
|
||||||
|
"python-dotenv==1.0.0",
|
||||||
|
"GitPython>=3.1.32",
|
||||||
|
"tqdm>=4.65.0",
|
||||||
|
"python-on-whales>=0.64.0",
|
||||||
|
"click>=8.1.6",
|
||||||
|
"PyYAML>=6.0.1",
|
||||||
|
"ruamel.yaml>=0.17.32",
|
||||||
|
"pydantic==1.10.9",
|
||||||
|
"tomli==2.0.1",
|
||||||
|
"validators==0.22.0",
|
||||||
|
"kubernetes>=28.1.0",
|
||||||
|
"humanfriendly>=10.0",
|
||||||
|
"python-gnupg>=0.5.2",
|
||||||
|
"requests>=2.3.2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[project.optional-dependencies]
|
||||||
|
dev = [
|
||||||
|
"pytest>=7.0.0",
|
||||||
|
"pytest-cov>=4.0.0",
|
||||||
|
"black>=22.0.0",
|
||||||
|
"flake8>=5.0.0",
|
||||||
|
"pyright>=1.1.0",
|
||||||
|
"yamllint>=1.28.0",
|
||||||
|
"pre-commit>=3.0.0",
|
||||||
|
]
|
||||||
|
|
||||||
|
[project.scripts]
|
||||||
|
laconic-so = "stack_orchestrator.main:cli"
|
||||||
|
|
||||||
|
[project.urls]
|
||||||
|
Homepage = "https://git.vdb.to/cerc-io/stack-orchestrator"
|
||||||
|
|
||||||
|
[tool.setuptools.packages.find]
|
||||||
|
where = ["."]
|
||||||
|
|
||||||
|
[tool.setuptools.package-data]
|
||||||
|
"*" = ["data/**"]
|
||||||
|
|
||||||
|
[tool.black]
|
||||||
|
line-length = 88
|
||||||
|
target-version = ['py38']
|
||||||
|
|
||||||
|
[tool.flake8]
|
||||||
|
max-line-length = 88
|
||||||
|
extend-ignore = ["E203", "W503", "E402"]
|
||||||
|
|
||||||
|
[tool.pyright]
|
||||||
|
pythonVersion = "3.9"
|
||||||
|
typeCheckingMode = "basic"
|
||||||
|
reportMissingImports = "none"
|
||||||
|
reportMissingModuleSource = "none"
|
||||||
|
reportUnusedImport = "error"
|
||||||
|
include = ["stack_orchestrator/**/*.py", "tests/**/*.py"]
|
||||||
|
exclude = ["**/build/**", "**/__pycache__/**"]
|
||||||
|
|
||||||
|
[tool.mypy]
|
||||||
|
python_version = "3.8"
|
||||||
|
warn_return_any = true
|
||||||
|
warn_unused_configs = true
|
||||||
|
disallow_untyped_defs = true
|
||||||
|
|
||||||
|
[tool.pytest.ini_options]
|
||||||
|
testpaths = ["tests"]
|
||||||
|
python_files = ["test_*.py"]
|
||||||
|
python_classes = ["Test*"]
|
||||||
|
python_functions = ["test_*"]
|
||||||
|
markers = [
|
||||||
|
"slow: marks tests as slow (deselect with '-m \"not slow\"')",
|
||||||
|
"e2e: marks tests as end-to-end (requires real infrastructure)",
|
||||||
|
]
|
||||||
|
addopts = [
|
||||||
|
"--cov",
|
||||||
|
"--cov-report=term-missing",
|
||||||
|
"--cov-report=html",
|
||||||
|
"--strict-markers",
|
||||||
|
]
|
||||||
|
asyncio_default_fixture_loop_scope = "function"
|
||||||
|
|
||||||
|
[tool.coverage.run]
|
||||||
|
source = ["stack_orchestrator"]
|
||||||
|
disable_warnings = ["couldnt-parse"]
|
||||||
|
|
||||||
|
[tool.coverage.report]
|
||||||
|
exclude_lines = [
|
||||||
|
"pragma: no cover",
|
||||||
|
"def __repr__",
|
||||||
|
"raise AssertionError",
|
||||||
|
"raise NotImplementedError",
|
||||||
|
]
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"pythonVersion": "3.9",
|
||||||
|
"typeCheckingMode": "basic",
|
||||||
|
"reportMissingImports": "none",
|
||||||
|
"reportMissingModuleSource": "none",
|
||||||
|
"reportUnusedImport": "error",
|
||||||
|
"include": ["stack_orchestrator/**/*.py", "tests/**/*.py"],
|
||||||
|
"exclude": ["**/build/**", "**/__pycache__/**"]
|
||||||
|
}
|
||||||
@@ -11,3 +11,5 @@ tomli==2.0.1
|
|||||||
validators==0.22.0
|
validators==0.22.0
|
||||||
kubernetes>=28.1.0
|
kubernetes>=28.1.0
|
||||||
humanfriendly>=10.0
|
humanfriendly>=10.0
|
||||||
|
python-gnupg>=0.5.2
|
||||||
|
requests>=2.3.2
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
# See https://medium.com/nerd-for-tech/how-to-build-and-distribute-a-cli-tool-with-python-537ae41d9d78
|
# See
|
||||||
|
# https://medium.com/nerd-for-tech/how-to-build-and-distribute-a-cli-tool-with-python-537ae41d9d78
|
||||||
from setuptools import setup, find_packages
|
from setuptools import setup, find_packages
|
||||||
|
|
||||||
with open("README.md", "r", encoding="utf-8") as fh:
|
with open("README.md", "r", encoding="utf-8") as fh:
|
||||||
long_description = fh.read()
|
long_description = fh.read()
|
||||||
with open("requirements.txt", "r", encoding="utf-8") as fh:
|
with open("requirements.txt", "r", encoding="utf-8") as fh:
|
||||||
@@ -7,26 +9,26 @@ with open("requirements.txt", "r", encoding="utf-8") as fh:
|
|||||||
with open("stack_orchestrator/data/version.txt", "r", encoding="utf-8") as fh:
|
with open("stack_orchestrator/data/version.txt", "r", encoding="utf-8") as fh:
|
||||||
version = fh.readlines()[-1].strip(" \n")
|
version = fh.readlines()[-1].strip(" \n")
|
||||||
setup(
|
setup(
|
||||||
name='laconic-stack-orchestrator',
|
name="laconic-stack-orchestrator",
|
||||||
version=version,
|
version=version,
|
||||||
author='Cerc',
|
author="Cerc",
|
||||||
author_email='info@cerc.io',
|
author_email="info@cerc.io",
|
||||||
license='GNU Affero General Public License',
|
license="GNU Affero General Public License",
|
||||||
description='Orchestrates deployment of the Laconic stack',
|
description="Orchestrates deployment of the Laconic stack",
|
||||||
long_description=long_description,
|
long_description=long_description,
|
||||||
long_description_content_type="text/markdown",
|
long_description_content_type="text/markdown",
|
||||||
url='https://git.vdb.to/cerc-io/stack-orchestrator',
|
url="https://git.vdb.to/cerc-io/stack-orchestrator",
|
||||||
py_modules=['stack_orchestrator'],
|
py_modules=["stack_orchestrator"],
|
||||||
packages=find_packages(),
|
packages=find_packages(),
|
||||||
install_requires=[requirements],
|
install_requires=[requirements],
|
||||||
python_requires='>=3.7',
|
python_requires=">=3.7",
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
package_data={'': ['data/**']},
|
package_data={"": ["data/**"]},
|
||||||
classifiers=[
|
classifiers=[
|
||||||
"Programming Language :: Python :: 3.8",
|
"Programming Language :: Python :: 3.8",
|
||||||
"Operating System :: OS Independent",
|
"Operating System :: OS Independent",
|
||||||
],
|
],
|
||||||
entry_points={
|
entry_points={
|
||||||
'console_scripts': ['laconic-so=stack_orchestrator.main:cli'],
|
"console_scripts": ["laconic-so=stack_orchestrator.main:cli"],
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
+30
-11
@@ -23,11 +23,10 @@ def get_stack(config, stack):
|
|||||||
if stack == "package-registry":
|
if stack == "package-registry":
|
||||||
return package_registry_stack(config, stack)
|
return package_registry_stack(config, stack)
|
||||||
else:
|
else:
|
||||||
return base_stack(config, stack)
|
return default_stack(config, stack)
|
||||||
|
|
||||||
|
|
||||||
class base_stack(ABC):
|
class base_stack(ABC):
|
||||||
|
|
||||||
def __init__(self, config, stack):
|
def __init__(self, config, stack):
|
||||||
self.config = config
|
self.config = config
|
||||||
self.stack = stack
|
self.stack = stack
|
||||||
@@ -41,15 +40,27 @@ class base_stack(ABC):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class package_registry_stack(base_stack):
|
class default_stack(base_stack):
|
||||||
|
"""Default stack implementation for stacks without specific handling."""
|
||||||
|
|
||||||
|
def ensure_available(self):
|
||||||
|
return True
|
||||||
|
|
||||||
|
def get_url(self):
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
class package_registry_stack(base_stack):
|
||||||
def ensure_available(self):
|
def ensure_available(self):
|
||||||
self.url = "<no registry url set>"
|
self.url = "<no registry url set>"
|
||||||
# Check if we were given an external registry URL
|
# Check if we were given an external registry URL
|
||||||
url_from_environment = os.environ.get("CERC_NPM_REGISTRY_URL")
|
url_from_environment = os.environ.get("CERC_NPM_REGISTRY_URL")
|
||||||
if url_from_environment:
|
if url_from_environment:
|
||||||
if self.config.verbose:
|
if self.config.verbose:
|
||||||
print(f"Using package registry url from CERC_NPM_REGISTRY_URL: {url_from_environment}")
|
print(
|
||||||
|
f"Using package registry url from CERC_NPM_REGISTRY_URL: "
|
||||||
|
f"{url_from_environment}"
|
||||||
|
)
|
||||||
self.url = url_from_environment
|
self.url = url_from_environment
|
||||||
else:
|
else:
|
||||||
# Otherwise we expect to use the local package-registry stack
|
# Otherwise we expect to use the local package-registry stack
|
||||||
@@ -62,10 +73,16 @@ class package_registry_stack(base_stack):
|
|||||||
# TODO: get url from deploy-stack
|
# TODO: get url from deploy-stack
|
||||||
self.url = "http://gitea.local:3000/api/packages/cerc-io/npm/"
|
self.url = "http://gitea.local:3000/api/packages/cerc-io/npm/"
|
||||||
else:
|
else:
|
||||||
# If not, print a message about how to start it and return fail to the caller
|
# If not, print a message about how to start it and return fail to the
|
||||||
print("ERROR: The package-registry stack is not running, and no external registry "
|
# caller
|
||||||
"specified with CERC_NPM_REGISTRY_URL")
|
print(
|
||||||
print("ERROR: Start the local package registry with: laconic-so --stack package-registry deploy-system up")
|
"ERROR: The package-registry stack is not running, "
|
||||||
|
"and no external registry specified with CERC_NPM_REGISTRY_URL"
|
||||||
|
)
|
||||||
|
print(
|
||||||
|
"ERROR: Start the local package registry with: "
|
||||||
|
"laconic-so --stack package-registry deploy-system up"
|
||||||
|
)
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -76,7 +93,9 @@ class package_registry_stack(base_stack):
|
|||||||
def get_npm_registry_url():
|
def get_npm_registry_url():
|
||||||
# If an auth token is not defined, we assume the default should be the cerc registry
|
# If an auth token is not defined, we assume the default should be the cerc registry
|
||||||
# If an auth token is defined, we assume the local gitea should be used.
|
# If an auth token is defined, we assume the local gitea should be used.
|
||||||
default_npm_registry_url = "http://gitea.local:3000/api/packages/cerc-io/npm/" if config(
|
default_npm_registry_url = (
|
||||||
"CERC_NPM_AUTH_TOKEN", default=None
|
"http://gitea.local:3000/api/packages/cerc-io/npm/"
|
||||||
) else "https://git.vdb.to/api/packages/cerc-io/npm/"
|
if config("CERC_NPM_AUTH_TOKEN", default=None)
|
||||||
|
else "https://git.vdb.to/api/packages/cerc-io/npm/"
|
||||||
|
)
|
||||||
return config("CERC_NPM_REGISTRY_URL", default=default_npm_registry_url)
|
return config("CERC_NPM_REGISTRY_URL", default=default_npm_registry_url)
|
||||||
|
|||||||
@@ -18,7 +18,8 @@
|
|||||||
# env vars:
|
# env vars:
|
||||||
# CERC_REPO_BASE_DIR defaults to ~/cerc
|
# CERC_REPO_BASE_DIR defaults to ~/cerc
|
||||||
|
|
||||||
# TODO: display the available list of containers; allow re-build of either all or specific containers
|
# TODO: display the available list of containers;
|
||||||
|
# allow re-build of either all or specific containers
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
@@ -34,14 +35,17 @@ from stack_orchestrator.build.publish import publish_image
|
|||||||
from stack_orchestrator.build.build_util import get_containers_in_scope
|
from stack_orchestrator.build.build_util import get_containers_in_scope
|
||||||
|
|
||||||
# TODO: find a place for this
|
# TODO: find a place for this
|
||||||
# epilog="Config provided either in .env or settings.ini or env vars: CERC_REPO_BASE_DIR (defaults to ~/cerc)"
|
# epilog="Config provided either in .env or settings.ini or env vars:
|
||||||
|
# CERC_REPO_BASE_DIR (defaults to ~/cerc)"
|
||||||
|
|
||||||
|
|
||||||
def make_container_build_env(dev_root_path: str,
|
def make_container_build_env(
|
||||||
container_build_dir: str,
|
dev_root_path: str,
|
||||||
debug: bool,
|
container_build_dir: str,
|
||||||
force_rebuild: bool,
|
debug: bool,
|
||||||
extra_build_args: str):
|
force_rebuild: bool,
|
||||||
|
extra_build_args: str,
|
||||||
|
):
|
||||||
container_build_env = {
|
container_build_env = {
|
||||||
"CERC_NPM_REGISTRY_URL": get_npm_registry_url(),
|
"CERC_NPM_REGISTRY_URL": get_npm_registry_url(),
|
||||||
"CERC_GO_AUTH_TOKEN": config("CERC_GO_AUTH_TOKEN", default=""),
|
"CERC_GO_AUTH_TOKEN": config("CERC_GO_AUTH_TOKEN", default=""),
|
||||||
@@ -50,11 +54,15 @@ def make_container_build_env(dev_root_path: str,
|
|||||||
"CERC_CONTAINER_BASE_DIR": container_build_dir,
|
"CERC_CONTAINER_BASE_DIR": container_build_dir,
|
||||||
"CERC_HOST_UID": f"{os.getuid()}",
|
"CERC_HOST_UID": f"{os.getuid()}",
|
||||||
"CERC_HOST_GID": f"{os.getgid()}",
|
"CERC_HOST_GID": f"{os.getgid()}",
|
||||||
"DOCKER_BUILDKIT": config("DOCKER_BUILDKIT", default="0")
|
"DOCKER_BUILDKIT": config("DOCKER_BUILDKIT", default="0"),
|
||||||
}
|
}
|
||||||
container_build_env.update({"CERC_SCRIPT_DEBUG": "true"} if debug else {})
|
container_build_env.update({"CERC_SCRIPT_DEBUG": "true"} if debug else {})
|
||||||
container_build_env.update({"CERC_FORCE_REBUILD": "true"} if force_rebuild else {})
|
container_build_env.update({"CERC_FORCE_REBUILD": "true"} if force_rebuild else {})
|
||||||
container_build_env.update({"CERC_CONTAINER_EXTRA_BUILD_ARGS": extra_build_args} if extra_build_args else {})
|
container_build_env.update(
|
||||||
|
{"CERC_CONTAINER_EXTRA_BUILD_ARGS": extra_build_args}
|
||||||
|
if extra_build_args
|
||||||
|
else {}
|
||||||
|
)
|
||||||
docker_host_env = os.getenv("DOCKER_HOST")
|
docker_host_env = os.getenv("DOCKER_HOST")
|
||||||
if docker_host_env:
|
if docker_host_env:
|
||||||
container_build_env.update({"DOCKER_HOST": docker_host_env})
|
container_build_env.update({"DOCKER_HOST": docker_host_env})
|
||||||
@@ -67,12 +75,18 @@ def process_container(build_context: BuildContext) -> bool:
|
|||||||
print(f"Building: {build_context.container}")
|
print(f"Building: {build_context.container}")
|
||||||
|
|
||||||
default_container_tag = f"{build_context.container}:local"
|
default_container_tag = f"{build_context.container}:local"
|
||||||
build_context.container_build_env.update({"CERC_DEFAULT_CONTAINER_IMAGE_TAG": default_container_tag})
|
build_context.container_build_env.update(
|
||||||
|
{"CERC_DEFAULT_CONTAINER_IMAGE_TAG": default_container_tag}
|
||||||
|
)
|
||||||
|
|
||||||
# Check if this is in an external stack
|
# Check if this is in an external stack
|
||||||
if stack_is_external(build_context.stack):
|
if stack_is_external(build_context.stack):
|
||||||
container_parent_dir = Path(build_context.stack).parent.parent.joinpath("container-build")
|
container_parent_dir = Path(build_context.stack).parent.parent.joinpath(
|
||||||
temp_build_dir = container_parent_dir.joinpath(build_context.container.replace("/", "-"))
|
"container-build"
|
||||||
|
)
|
||||||
|
temp_build_dir = container_parent_dir.joinpath(
|
||||||
|
build_context.container.replace("/", "-")
|
||||||
|
)
|
||||||
temp_build_script_filename = temp_build_dir.joinpath("build.sh")
|
temp_build_script_filename = temp_build_dir.joinpath("build.sh")
|
||||||
# Now check if the container exists in the external stack.
|
# Now check if the container exists in the external stack.
|
||||||
if not temp_build_script_filename.exists():
|
if not temp_build_script_filename.exists():
|
||||||
@@ -90,21 +104,34 @@ def process_container(build_context: BuildContext) -> bool:
|
|||||||
build_command = build_script_filename.as_posix()
|
build_command = build_script_filename.as_posix()
|
||||||
else:
|
else:
|
||||||
if opts.o.verbose:
|
if opts.o.verbose:
|
||||||
print(f"No script file found: {build_script_filename}, using default build script")
|
print(
|
||||||
repo_dir = build_context.container.split('/')[1]
|
f"No script file found: {build_script_filename}, "
|
||||||
# TODO: make this less of a hack -- should be specified in some metadata somewhere
|
"using default build script"
|
||||||
# Check if we have a repo for this container. If not, set the context dir to the container-build subdir
|
)
|
||||||
|
repo_dir = build_context.container.split("/")[1]
|
||||||
|
# TODO: make this less of a hack -- should be specified in
|
||||||
|
# some metadata somewhere. Check if we have a repo for this
|
||||||
|
# container. If not, set the context dir to container-build subdir
|
||||||
repo_full_path = os.path.join(build_context.dev_root_path, repo_dir)
|
repo_full_path = os.path.join(build_context.dev_root_path, repo_dir)
|
||||||
repo_dir_or_build_dir = repo_full_path if os.path.exists(repo_full_path) else build_dir
|
repo_dir_or_build_dir = (
|
||||||
build_command = os.path.join(build_context.container_build_dir,
|
repo_full_path if os.path.exists(repo_full_path) else build_dir
|
||||||
"default-build.sh") + f" {default_container_tag} {repo_dir_or_build_dir}"
|
)
|
||||||
|
build_command = (
|
||||||
|
os.path.join(build_context.container_build_dir, "default-build.sh")
|
||||||
|
+ f" {default_container_tag} {repo_dir_or_build_dir}"
|
||||||
|
)
|
||||||
if not opts.o.dry_run:
|
if not opts.o.dry_run:
|
||||||
# No PATH at all causes failures with podman.
|
# No PATH at all causes failures with podman.
|
||||||
if "PATH" not in build_context.container_build_env:
|
if "PATH" not in build_context.container_build_env:
|
||||||
build_context.container_build_env["PATH"] = os.environ["PATH"]
|
build_context.container_build_env["PATH"] = os.environ["PATH"]
|
||||||
if opts.o.verbose:
|
if opts.o.verbose:
|
||||||
print(f"Executing: {build_command} with environment: {build_context.container_build_env}")
|
print(
|
||||||
build_result = subprocess.run(build_command, shell=True, env=build_context.container_build_env)
|
f"Executing: {build_command} with environment: "
|
||||||
|
f"{build_context.container_build_env}"
|
||||||
|
)
|
||||||
|
build_result = subprocess.run(
|
||||||
|
build_command, shell=True, env=build_context.container_build_env
|
||||||
|
)
|
||||||
if opts.o.verbose:
|
if opts.o.verbose:
|
||||||
print(f"Return code is: {build_result.returncode}")
|
print(f"Return code is: {build_result.returncode}")
|
||||||
if build_result.returncode != 0:
|
if build_result.returncode != 0:
|
||||||
@@ -117,33 +144,61 @@ def process_container(build_context: BuildContext) -> bool:
|
|||||||
|
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
@click.option('--include', help="only build these containers")
|
@click.option("--include", help="only build these containers")
|
||||||
@click.option('--exclude', help="don\'t build these containers")
|
@click.option("--exclude", help="don't build these containers")
|
||||||
@click.option("--force-rebuild", is_flag=True, default=False, help="Override dependency checking -- always rebuild")
|
@click.option(
|
||||||
|
"--force-rebuild",
|
||||||
|
is_flag=True,
|
||||||
|
default=False,
|
||||||
|
help="Override dependency checking -- always rebuild",
|
||||||
|
)
|
||||||
@click.option("--extra-build-args", help="Supply extra arguments to build")
|
@click.option("--extra-build-args", help="Supply extra arguments to build")
|
||||||
@click.option("--publish-images", is_flag=True, default=False, help="Publish the built images in the specified image registry")
|
@click.option(
|
||||||
@click.option("--image-registry", help="Specify the image registry for --publish-images")
|
"--publish-images",
|
||||||
|
is_flag=True,
|
||||||
|
default=False,
|
||||||
|
help="Publish the built images in the specified image registry",
|
||||||
|
)
|
||||||
|
@click.option(
|
||||||
|
"--image-registry", help="Specify the image registry for --publish-images"
|
||||||
|
)
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def command(ctx, include, exclude, force_rebuild, extra_build_args, publish_images, image_registry):
|
def command(
|
||||||
'''build the set of containers required for a complete stack'''
|
ctx,
|
||||||
|
include,
|
||||||
|
exclude,
|
||||||
|
force_rebuild,
|
||||||
|
extra_build_args,
|
||||||
|
publish_images,
|
||||||
|
image_registry,
|
||||||
|
):
|
||||||
|
"""build the set of containers required for a complete stack"""
|
||||||
|
|
||||||
local_stack = ctx.obj.local_stack
|
local_stack = ctx.obj.local_stack
|
||||||
stack = ctx.obj.stack
|
stack = ctx.obj.stack
|
||||||
|
|
||||||
# See: https://stackoverflow.com/questions/25389095/python-get-path-of-root-project-structure
|
# See: https://stackoverflow.com/questions/25389095/
|
||||||
container_build_dir = Path(__file__).absolute().parent.parent.joinpath("data", "container-build")
|
# python-get-path-of-root-project-structure
|
||||||
|
container_build_dir = (
|
||||||
|
Path(__file__).absolute().parent.parent.joinpath("data", "container-build")
|
||||||
|
)
|
||||||
|
|
||||||
if local_stack:
|
if local_stack:
|
||||||
dev_root_path = os.getcwd()[0:os.getcwd().rindex("stack-orchestrator")]
|
dev_root_path = os.getcwd()[0 : os.getcwd().rindex("stack-orchestrator")]
|
||||||
print(f'Local stack dev_root_path (CERC_REPO_BASE_DIR) overridden to: {dev_root_path}')
|
print(
|
||||||
|
f"Local stack dev_root_path (CERC_REPO_BASE_DIR) overridden to: "
|
||||||
|
f"{dev_root_path}"
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
dev_root_path = os.path.expanduser(config("CERC_REPO_BASE_DIR", default="~/cerc"))
|
dev_root_path = os.path.expanduser(
|
||||||
|
config("CERC_REPO_BASE_DIR", default="~/cerc")
|
||||||
|
)
|
||||||
|
|
||||||
if not opts.o.quiet:
|
if not opts.o.quiet:
|
||||||
print(f'Dev Root is: {dev_root_path}')
|
print(f"Dev Root is: {dev_root_path}")
|
||||||
|
|
||||||
if not os.path.isdir(dev_root_path):
|
if not os.path.isdir(dev_root_path):
|
||||||
print('Dev root directory doesn\'t exist, creating')
|
print("Dev root directory doesn't exist, creating")
|
||||||
|
|
||||||
if publish_images:
|
if publish_images:
|
||||||
if not image_registry:
|
if not image_registry:
|
||||||
@@ -151,21 +206,22 @@ def command(ctx, include, exclude, force_rebuild, extra_build_args, publish_imag
|
|||||||
|
|
||||||
containers_in_scope = get_containers_in_scope(stack)
|
containers_in_scope = get_containers_in_scope(stack)
|
||||||
|
|
||||||
container_build_env = make_container_build_env(dev_root_path,
|
container_build_env = make_container_build_env(
|
||||||
container_build_dir,
|
dev_root_path,
|
||||||
opts.o.debug,
|
container_build_dir,
|
||||||
force_rebuild,
|
opts.o.debug,
|
||||||
extra_build_args)
|
force_rebuild,
|
||||||
|
extra_build_args,
|
||||||
|
)
|
||||||
|
|
||||||
for container in containers_in_scope:
|
for container in containers_in_scope:
|
||||||
if include_exclude_check(container, include, exclude):
|
if include_exclude_check(container, include, exclude):
|
||||||
|
|
||||||
build_context = BuildContext(
|
build_context = BuildContext(
|
||||||
stack,
|
stack,
|
||||||
container,
|
container,
|
||||||
container_build_dir,
|
container_build_dir,
|
||||||
container_build_env,
|
container_build_env,
|
||||||
dev_root_path
|
dev_root_path,
|
||||||
)
|
)
|
||||||
result = process_container(build_context)
|
result = process_container(build_context)
|
||||||
if result:
|
if result:
|
||||||
@@ -174,10 +230,16 @@ def command(ctx, include, exclude, force_rebuild, extra_build_args, publish_imag
|
|||||||
else:
|
else:
|
||||||
print(f"Error running build for {build_context.container}")
|
print(f"Error running build for {build_context.container}")
|
||||||
if not opts.o.continue_on_error:
|
if not opts.o.continue_on_error:
|
||||||
error_exit("container build failed and --continue-on-error not set, exiting")
|
error_exit(
|
||||||
|
"container build failed and --continue-on-error "
|
||||||
|
"not set, exiting"
|
||||||
|
)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
print("****** Container Build Error, continuing because --continue-on-error is set")
|
print(
|
||||||
|
"****** Container Build Error, continuing because "
|
||||||
|
"--continue-on-error is set"
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
if opts.o.verbose:
|
if opts.o.verbose:
|
||||||
print(f"Excluding: {container}")
|
print(f"Excluding: {container}")
|
||||||
|
|||||||
@@ -32,14 +32,18 @@ builder_js_image_name = "cerc/builder-js:local"
|
|||||||
|
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
@click.option('--include', help="only build these packages")
|
@click.option("--include", help="only build these packages")
|
||||||
@click.option('--exclude', help="don\'t build these packages")
|
@click.option("--exclude", help="don't build these packages")
|
||||||
@click.option("--force-rebuild", is_flag=True, default=False,
|
@click.option(
|
||||||
help="Override existing target package version check -- force rebuild")
|
"--force-rebuild",
|
||||||
|
is_flag=True,
|
||||||
|
default=False,
|
||||||
|
help="Override existing target package version check -- force rebuild",
|
||||||
|
)
|
||||||
@click.option("--extra-build-args", help="Supply extra arguments to build")
|
@click.option("--extra-build-args", help="Supply extra arguments to build")
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def command(ctx, include, exclude, force_rebuild, extra_build_args):
|
def command(ctx, include, exclude, force_rebuild, extra_build_args):
|
||||||
'''build the set of npm packages required for a complete stack'''
|
"""build the set of npm packages required for a complete stack"""
|
||||||
|
|
||||||
quiet = ctx.obj.quiet
|
quiet = ctx.obj.quiet
|
||||||
verbose = ctx.obj.verbose
|
verbose = ctx.obj.verbose
|
||||||
@@ -65,45 +69,54 @@ def command(ctx, include, exclude, force_rebuild, extra_build_args):
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if local_stack:
|
if local_stack:
|
||||||
dev_root_path = os.getcwd()[0:os.getcwd().rindex("stack-orchestrator")]
|
dev_root_path = os.getcwd()[0 : os.getcwd().rindex("stack-orchestrator")]
|
||||||
print(f'Local stack dev_root_path (CERC_REPO_BASE_DIR) overridden to: {dev_root_path}')
|
print(
|
||||||
|
f"Local stack dev_root_path (CERC_REPO_BASE_DIR) overridden to: "
|
||||||
|
f"{dev_root_path}"
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
dev_root_path = os.path.expanduser(config("CERC_REPO_BASE_DIR", default="~/cerc"))
|
dev_root_path = os.path.expanduser(
|
||||||
|
config("CERC_REPO_BASE_DIR", default="~/cerc")
|
||||||
|
)
|
||||||
|
|
||||||
build_root_path = os.path.join(dev_root_path, "build-trees")
|
build_root_path = os.path.join(dev_root_path, "build-trees")
|
||||||
|
|
||||||
if verbose:
|
if verbose:
|
||||||
print(f'Dev Root is: {dev_root_path}')
|
print(f"Dev Root is: {dev_root_path}")
|
||||||
|
|
||||||
if not os.path.isdir(dev_root_path):
|
if not os.path.isdir(dev_root_path):
|
||||||
print('Dev root directory doesn\'t exist, creating')
|
print("Dev root directory doesn't exist, creating")
|
||||||
os.makedirs(dev_root_path)
|
os.makedirs(dev_root_path)
|
||||||
if not os.path.isdir(dev_root_path):
|
if not os.path.isdir(dev_root_path):
|
||||||
print('Build root directory doesn\'t exist, creating')
|
print("Build root directory doesn't exist, creating")
|
||||||
os.makedirs(build_root_path)
|
os.makedirs(build_root_path)
|
||||||
|
|
||||||
# See: https://stackoverflow.com/a/20885799/1701505
|
# See: https://stackoverflow.com/a/20885799/1701505
|
||||||
from stack_orchestrator import data
|
from stack_orchestrator import data
|
||||||
with importlib.resources.open_text(data, "npm-package-list.txt") as package_list_file:
|
|
||||||
|
with importlib.resources.open_text(
|
||||||
|
data, "npm-package-list.txt"
|
||||||
|
) as package_list_file:
|
||||||
all_packages = package_list_file.read().splitlines()
|
all_packages = package_list_file.read().splitlines()
|
||||||
|
|
||||||
packages_in_scope = []
|
packages_in_scope = []
|
||||||
if stack:
|
if stack:
|
||||||
stack_config = get_parsed_stack_config(stack)
|
stack_config = get_parsed_stack_config(stack)
|
||||||
# TODO: syntax check the input here
|
# TODO: syntax check the input here
|
||||||
packages_in_scope = stack_config['npms']
|
packages_in_scope = stack_config["npms"]
|
||||||
else:
|
else:
|
||||||
packages_in_scope = all_packages
|
packages_in_scope = all_packages
|
||||||
|
|
||||||
if verbose:
|
if verbose:
|
||||||
print(f'Packages: {packages_in_scope}')
|
print(f"Packages: {packages_in_scope}")
|
||||||
|
|
||||||
def build_package(package):
|
def build_package(package):
|
||||||
if not quiet:
|
if not quiet:
|
||||||
print(f"Building npm package: {package}")
|
print(f"Building npm package: {package}")
|
||||||
repo_dir = package
|
repo_dir = package
|
||||||
repo_full_path = os.path.join(dev_root_path, repo_dir)
|
repo_full_path = os.path.join(dev_root_path, repo_dir)
|
||||||
# Copy the repo and build that to avoid propagating JS tooling file changes back into the cloned repo
|
# Copy the repo and build that to avoid propagating
|
||||||
|
# JS tooling file changes back into the cloned repo
|
||||||
repo_copy_path = os.path.join(build_root_path, repo_dir)
|
repo_copy_path = os.path.join(build_root_path, repo_dir)
|
||||||
# First delete any old build tree
|
# First delete any old build tree
|
||||||
if os.path.isdir(repo_copy_path):
|
if os.path.isdir(repo_copy_path):
|
||||||
@@ -116,41 +129,63 @@ def command(ctx, include, exclude, force_rebuild, extra_build_args):
|
|||||||
print(f"Copying build tree from: {repo_full_path} to: {repo_copy_path}")
|
print(f"Copying build tree from: {repo_full_path} to: {repo_copy_path}")
|
||||||
if not dry_run:
|
if not dry_run:
|
||||||
copytree(repo_full_path, repo_copy_path)
|
copytree(repo_full_path, repo_copy_path)
|
||||||
build_command = ["sh", "-c", f"cd /workspace && build-npm-package-local-dependencies.sh {npm_registry_url}"]
|
build_command = [
|
||||||
|
"sh",
|
||||||
|
"-c",
|
||||||
|
"cd /workspace && "
|
||||||
|
f"build-npm-package-local-dependencies.sh {npm_registry_url}",
|
||||||
|
]
|
||||||
if not dry_run:
|
if not dry_run:
|
||||||
if verbose:
|
if verbose:
|
||||||
print(f"Executing: {build_command}")
|
print(f"Executing: {build_command}")
|
||||||
# Originally we used the PEP 584 merge operator:
|
# Originally we used the PEP 584 merge operator:
|
||||||
# envs = {"CERC_NPM_AUTH_TOKEN": npm_registry_url_token} | ({"CERC_SCRIPT_DEBUG": "true"} if debug else {})
|
# envs = {"CERC_NPM_AUTH_TOKEN": npm_registry_url_token} |
|
||||||
# but that isn't available in Python 3.8 (default in Ubuntu 20) so for now we use dict.update:
|
# ({"CERC_SCRIPT_DEBUG": "true"} if debug else {})
|
||||||
envs = {"CERC_NPM_AUTH_TOKEN": npm_registry_url_token,
|
# but that isn't available in Python 3.8 (default in Ubuntu 20)
|
||||||
"LACONIC_HOSTED_CONFIG_FILE": "config-hosted.yml" # Convention used by our web app packages
|
# so for now we use dict.update:
|
||||||
}
|
envs = {
|
||||||
|
"CERC_NPM_AUTH_TOKEN": npm_registry_url_token,
|
||||||
|
# Convention used by our web app packages
|
||||||
|
"LACONIC_HOSTED_CONFIG_FILE": "config-hosted.yml",
|
||||||
|
}
|
||||||
envs.update({"CERC_SCRIPT_DEBUG": "true"} if debug else {})
|
envs.update({"CERC_SCRIPT_DEBUG": "true"} if debug else {})
|
||||||
envs.update({"CERC_FORCE_REBUILD": "true"} if force_rebuild else {})
|
envs.update({"CERC_FORCE_REBUILD": "true"} if force_rebuild else {})
|
||||||
envs.update({"CERC_CONTAINER_EXTRA_BUILD_ARGS": extra_build_args} if extra_build_args else {})
|
envs.update(
|
||||||
|
{"CERC_CONTAINER_EXTRA_BUILD_ARGS": extra_build_args}
|
||||||
|
if extra_build_args
|
||||||
|
else {}
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
docker.run(builder_js_image_name,
|
docker.run(
|
||||||
remove=True,
|
builder_js_image_name,
|
||||||
interactive=True,
|
remove=True,
|
||||||
tty=True,
|
interactive=True,
|
||||||
user=f"{os.getuid()}:{os.getgid()}",
|
tty=True,
|
||||||
envs=envs,
|
user=f"{os.getuid()}:{os.getgid()}",
|
||||||
# TODO: detect this host name in npm_registry_url rather than hard-wiring it
|
envs=envs,
|
||||||
add_hosts=[("gitea.local", "host-gateway")],
|
# TODO: detect this host name in npm_registry_url
|
||||||
volumes=[(repo_copy_path, "/workspace")],
|
# rather than hard-wiring it
|
||||||
command=build_command
|
add_hosts=[("gitea.local", "host-gateway")],
|
||||||
)
|
volumes=[(repo_copy_path, "/workspace")],
|
||||||
# Note that although the docs say that build_result should contain
|
command=build_command,
|
||||||
# the command output as a string, in reality it is always the empty string.
|
)
|
||||||
# Since we detect errors via catching exceptions below, we can safely ignore it here.
|
# Note that although the docs say that build_result should
|
||||||
|
# contain the command output as a string, in reality it is
|
||||||
|
# always the empty string. Since we detect errors via catching
|
||||||
|
# exceptions below, we can safely ignore it here.
|
||||||
except DockerException as e:
|
except DockerException as e:
|
||||||
print(f"Error executing build for {package} in container:\n {e}")
|
print(f"Error executing build for {package} in container:\n {e}")
|
||||||
if not continue_on_error:
|
if not continue_on_error:
|
||||||
print("FATAL Error: build failed and --continue-on-error not set, exiting")
|
print(
|
||||||
|
"FATAL Error: build failed and --continue-on-error "
|
||||||
|
"not set, exiting"
|
||||||
|
)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
print("****** Build Error, continuing because --continue-on-error is set")
|
print(
|
||||||
|
"****** Build Error, continuing because "
|
||||||
|
"--continue-on-error is set"
|
||||||
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print("Skipped")
|
print("Skipped")
|
||||||
@@ -168,6 +203,12 @@ def _ensure_prerequisites():
|
|||||||
# Tell the user how to build it if not
|
# Tell the user how to build it if not
|
||||||
images = docker.image.list(builder_js_image_name)
|
images = docker.image.list(builder_js_image_name)
|
||||||
if len(images) == 0:
|
if len(images) == 0:
|
||||||
print(f"FATAL: builder image: {builder_js_image_name} is required but was not found")
|
print(
|
||||||
print("Please run this command to create it: laconic-so --stack build-support build-containers")
|
f"FATAL: builder image: {builder_js_image_name} is required "
|
||||||
|
"but was not found"
|
||||||
|
)
|
||||||
|
print(
|
||||||
|
"Please run this command to create it: "
|
||||||
|
"laconic-so --stack build-support build-containers"
|
||||||
|
)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|||||||
@@ -24,6 +24,5 @@ class BuildContext:
|
|||||||
stack: str
|
stack: str
|
||||||
container: str
|
container: str
|
||||||
container_build_dir: Path
|
container_build_dir: Path
|
||||||
container_build_env: Mapping[str,str]
|
container_build_env: Mapping[str, str]
|
||||||
dev_root_path: str
|
dev_root_path: str
|
||||||
|
|
||||||
|
|||||||
@@ -20,21 +20,23 @@ from stack_orchestrator.util import get_parsed_stack_config, warn_exit
|
|||||||
|
|
||||||
|
|
||||||
def get_containers_in_scope(stack: str):
|
def get_containers_in_scope(stack: str):
|
||||||
|
|
||||||
containers_in_scope = []
|
containers_in_scope = []
|
||||||
if stack:
|
if stack:
|
||||||
stack_config = get_parsed_stack_config(stack)
|
stack_config = get_parsed_stack_config(stack)
|
||||||
if "containers" not in stack_config or stack_config["containers"] is None:
|
if "containers" not in stack_config or stack_config["containers"] is None:
|
||||||
warn_exit(f"stack {stack} does not define any containers")
|
warn_exit(f"stack {stack} does not define any containers")
|
||||||
containers_in_scope = stack_config['containers']
|
containers_in_scope = stack_config["containers"]
|
||||||
else:
|
else:
|
||||||
# See: https://stackoverflow.com/a/20885799/1701505
|
# See: https://stackoverflow.com/a/20885799/1701505
|
||||||
from stack_orchestrator import data
|
from stack_orchestrator import data
|
||||||
with importlib.resources.open_text(data, "container-image-list.txt") as container_list_file:
|
|
||||||
|
with importlib.resources.open_text(
|
||||||
|
data, "container-image-list.txt"
|
||||||
|
) as container_list_file:
|
||||||
containers_in_scope = container_list_file.read().splitlines()
|
containers_in_scope = container_list_file.read().splitlines()
|
||||||
|
|
||||||
if opts.o.verbose:
|
if opts.o.verbose:
|
||||||
print(f'Containers: {containers_in_scope}')
|
print(f"Containers: {containers_in_scope}")
|
||||||
if stack:
|
if stack:
|
||||||
print(f"Stack: {stack}")
|
print(f"Stack: {stack}")
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,8 @@
|
|||||||
# env vars:
|
# env vars:
|
||||||
# CERC_REPO_BASE_DIR defaults to ~/cerc
|
# CERC_REPO_BASE_DIR defaults to ~/cerc
|
||||||
|
|
||||||
# TODO: display the available list of containers; allow re-build of either all or specific containers
|
# TODO: display the available list of containers;
|
||||||
|
# allow re-build of either all or specific containers
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
@@ -32,40 +33,55 @@ from stack_orchestrator.build.build_types import BuildContext
|
|||||||
|
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
@click.option('--base-container')
|
@click.option("--base-container")
|
||||||
@click.option('--source-repo', help="directory containing the webapp to build", required=True)
|
@click.option(
|
||||||
@click.option("--force-rebuild", is_flag=True, default=False, help="Override dependency checking -- always rebuild")
|
"--source-repo", help="directory containing the webapp to build", required=True
|
||||||
|
)
|
||||||
|
@click.option(
|
||||||
|
"--force-rebuild",
|
||||||
|
is_flag=True,
|
||||||
|
default=False,
|
||||||
|
help="Override dependency checking -- always rebuild",
|
||||||
|
)
|
||||||
@click.option("--extra-build-args", help="Supply extra arguments to build")
|
@click.option("--extra-build-args", help="Supply extra arguments to build")
|
||||||
@click.option("--tag", help="Container tag (default: cerc/<app_name>:local)")
|
@click.option("--tag", help="Container tag (default: cerc/<app_name>:local)")
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def command(ctx, base_container, source_repo, force_rebuild, extra_build_args, tag):
|
def command(ctx, base_container, source_repo, force_rebuild, extra_build_args, tag):
|
||||||
'''build the specified webapp container'''
|
"""build the specified webapp container"""
|
||||||
logger = TimedLogger()
|
logger = TimedLogger()
|
||||||
|
|
||||||
quiet = ctx.obj.quiet
|
|
||||||
debug = ctx.obj.debug
|
debug = ctx.obj.debug
|
||||||
verbose = ctx.obj.verbose
|
verbose = ctx.obj.verbose
|
||||||
local_stack = ctx.obj.local_stack
|
local_stack = ctx.obj.local_stack
|
||||||
stack = ctx.obj.stack
|
stack = ctx.obj.stack
|
||||||
|
|
||||||
# See: https://stackoverflow.com/questions/25389095/python-get-path-of-root-project-structure
|
# See: https://stackoverflow.com/questions/25389095/
|
||||||
container_build_dir = Path(__file__).absolute().parent.parent.joinpath("data", "container-build")
|
# python-get-path-of-root-project-structure
|
||||||
|
container_build_dir = (
|
||||||
|
Path(__file__).absolute().parent.parent.joinpath("data", "container-build")
|
||||||
|
)
|
||||||
|
|
||||||
if local_stack:
|
if local_stack:
|
||||||
dev_root_path = os.getcwd()[0:os.getcwd().rindex("stack-orchestrator")]
|
dev_root_path = os.getcwd()[0 : os.getcwd().rindex("stack-orchestrator")]
|
||||||
logger.log(f'Local stack dev_root_path (CERC_REPO_BASE_DIR) overridden to: {dev_root_path}')
|
logger.log(
|
||||||
|
f"Local stack dev_root_path (CERC_REPO_BASE_DIR) overridden to: "
|
||||||
|
f"{dev_root_path}"
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
dev_root_path = os.path.expanduser(config("CERC_REPO_BASE_DIR", default="~/cerc"))
|
dev_root_path = os.path.expanduser(
|
||||||
|
config("CERC_REPO_BASE_DIR", default="~/cerc")
|
||||||
|
)
|
||||||
|
|
||||||
if verbose:
|
if verbose:
|
||||||
logger.log(f'Dev Root is: {dev_root_path}')
|
logger.log(f"Dev Root is: {dev_root_path}")
|
||||||
|
|
||||||
if not base_container:
|
if not base_container:
|
||||||
base_container = determine_base_container(source_repo)
|
base_container = determine_base_container(source_repo)
|
||||||
|
|
||||||
# First build the base container.
|
# First build the base container.
|
||||||
container_build_env = build_containers.make_container_build_env(dev_root_path, container_build_dir, debug,
|
container_build_env = build_containers.make_container_build_env(
|
||||||
force_rebuild, extra_build_args)
|
dev_root_path, container_build_dir, debug, force_rebuild, extra_build_args
|
||||||
|
)
|
||||||
|
|
||||||
if verbose:
|
if verbose:
|
||||||
logger.log(f"Building base container: {base_container}")
|
logger.log(f"Building base container: {base_container}")
|
||||||
@@ -85,12 +101,13 @@ def command(ctx, base_container, source_repo, force_rebuild, extra_build_args, t
|
|||||||
if verbose:
|
if verbose:
|
||||||
logger.log(f"Base container {base_container} build finished.")
|
logger.log(f"Base container {base_container} build finished.")
|
||||||
|
|
||||||
# Now build the target webapp. We use the same build script, but with a different Dockerfile and work dir.
|
# Now build the target webapp. We use the same build script,
|
||||||
|
# but with a different Dockerfile and work dir.
|
||||||
container_build_env["CERC_WEBAPP_BUILD_RUNNING"] = "true"
|
container_build_env["CERC_WEBAPP_BUILD_RUNNING"] = "true"
|
||||||
container_build_env["CERC_CONTAINER_BUILD_WORK_DIR"] = os.path.abspath(source_repo)
|
container_build_env["CERC_CONTAINER_BUILD_WORK_DIR"] = os.path.abspath(source_repo)
|
||||||
container_build_env["CERC_CONTAINER_BUILD_DOCKERFILE"] = os.path.join(container_build_dir,
|
container_build_env["CERC_CONTAINER_BUILD_DOCKERFILE"] = os.path.join(
|
||||||
base_container.replace("/", "-"),
|
container_build_dir, base_container.replace("/", "-"), "Dockerfile.webapp"
|
||||||
"Dockerfile.webapp")
|
)
|
||||||
if not tag:
|
if not tag:
|
||||||
webapp_name = os.path.abspath(source_repo).split(os.path.sep)[-1]
|
webapp_name = os.path.abspath(source_repo).split(os.path.sep)[-1]
|
||||||
tag = f"cerc/{webapp_name}:local"
|
tag = f"cerc/{webapp_name}:local"
|
||||||
|
|||||||
@@ -52,7 +52,8 @@ def _local_tag_for(container: str):
|
|||||||
|
|
||||||
# See: https://docker-docs.uclv.cu/registry/spec/api/
|
# See: https://docker-docs.uclv.cu/registry/spec/api/
|
||||||
# Emulate this:
|
# Emulate this:
|
||||||
# $ curl -u "my-username:my-token" -X GET "https://<container-registry-hostname>/v2/cerc-io/cerc/test-container/tags/list"
|
# $ curl -u "my-username:my-token" -X GET \
|
||||||
|
# "https://<container-registry-hostname>/v2/cerc-io/cerc/test-container/tags/list"
|
||||||
# {"name":"cerc-io/cerc/test-container","tags":["202402232130","202402232208"]}
|
# {"name":"cerc-io/cerc/test-container","tags":["202402232130","202402232208"]}
|
||||||
def _get_tags_for_container(container: str, registry_info: RegistryInfo) -> List[str]:
|
def _get_tags_for_container(container: str, registry_info: RegistryInfo) -> List[str]:
|
||||||
# registry looks like: git.vdb.to/cerc-io
|
# registry looks like: git.vdb.to/cerc-io
|
||||||
@@ -60,7 +61,9 @@ def _get_tags_for_container(container: str, registry_info: RegistryInfo) -> List
|
|||||||
url = f"https://{registry_parts[0]}/v2/{registry_parts[1]}/{container}/tags/list"
|
url = f"https://{registry_parts[0]}/v2/{registry_parts[1]}/{container}/tags/list"
|
||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print(f"Fetching tags from: {url}")
|
print(f"Fetching tags from: {url}")
|
||||||
response = requests.get(url, auth=(registry_info.registry_username, registry_info.registry_token))
|
response = requests.get(
|
||||||
|
url, auth=(registry_info.registry_username, registry_info.registry_token)
|
||||||
|
)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
tag_info = response.json()
|
tag_info = response.json()
|
||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
@@ -68,7 +71,10 @@ def _get_tags_for_container(container: str, registry_info: RegistryInfo) -> List
|
|||||||
tags_array = tag_info["tags"]
|
tags_array = tag_info["tags"]
|
||||||
return tags_array
|
return tags_array
|
||||||
else:
|
else:
|
||||||
error_exit(f"failed to fetch tags from image registry, status code: {response.status_code}")
|
error_exit(
|
||||||
|
f"failed to fetch tags from image registry, "
|
||||||
|
f"status code: {response.status_code}"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def _find_latest(candidate_tags: List[str]):
|
def _find_latest(candidate_tags: List[str]):
|
||||||
@@ -79,9 +85,9 @@ def _find_latest(candidate_tags: List[str]):
|
|||||||
return sorted_candidates[-1]
|
return sorted_candidates[-1]
|
||||||
|
|
||||||
|
|
||||||
def _filter_for_platform(container: str,
|
def _filter_for_platform(
|
||||||
registry_info: RegistryInfo,
|
container: str, registry_info: RegistryInfo, tag_list: List[str]
|
||||||
tag_list: List[str]) -> List[str] :
|
) -> List[str]:
|
||||||
filtered_tags = []
|
filtered_tags = []
|
||||||
this_machine = platform.machine()
|
this_machine = platform.machine()
|
||||||
# Translate between Python and docker platform names
|
# Translate between Python and docker platform names
|
||||||
@@ -98,7 +104,7 @@ def _filter_for_platform(container: str,
|
|||||||
manifest = manifest_cmd.inspect_verbose(remote_tag)
|
manifest = manifest_cmd.inspect_verbose(remote_tag)
|
||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print(f"manifest: {manifest}")
|
print(f"manifest: {manifest}")
|
||||||
image_architecture = manifest["Descriptor"]["platform"]["architecture"]
|
image_architecture = manifest["Descriptor"]["platform"]["architecture"]
|
||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print(f"image_architecture: {image_architecture}")
|
print(f"image_architecture: {image_architecture}")
|
||||||
if this_machine == image_architecture:
|
if this_machine == image_architecture:
|
||||||
@@ -137,21 +143,44 @@ def _add_local_tag(remote_tag: str, registry: str, local_tag: str):
|
|||||||
|
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
@click.option('--include', help="only fetch these containers")
|
@click.option("--include", help="only fetch these containers")
|
||||||
@click.option('--exclude', help="don\'t fetch these containers")
|
@click.option("--exclude", help="don't fetch these containers")
|
||||||
@click.option("--force-local-overwrite", is_flag=True, default=False, help="Overwrite a locally built image, if present")
|
@click.option(
|
||||||
@click.option("--image-registry", required=True, help="Specify the image registry to fetch from")
|
"--force-local-overwrite",
|
||||||
@click.option("--registry-username", required=True, help="Specify the image registry username")
|
is_flag=True,
|
||||||
@click.option("--registry-token", required=True, help="Specify the image registry access token")
|
default=False,
|
||||||
|
help="Overwrite a locally built image, if present",
|
||||||
|
)
|
||||||
|
@click.option(
|
||||||
|
"--image-registry", required=True, help="Specify the image registry to fetch from"
|
||||||
|
)
|
||||||
|
@click.option(
|
||||||
|
"--registry-username", required=True, help="Specify the image registry username"
|
||||||
|
)
|
||||||
|
@click.option(
|
||||||
|
"--registry-token", required=True, help="Specify the image registry access token"
|
||||||
|
)
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def command(ctx, include, exclude, force_local_overwrite, image_registry, registry_username, registry_token):
|
def command(
|
||||||
'''EXPERIMENTAL: fetch the images for a stack from remote registry'''
|
ctx,
|
||||||
|
include,
|
||||||
|
exclude,
|
||||||
|
force_local_overwrite,
|
||||||
|
image_registry,
|
||||||
|
registry_username,
|
||||||
|
registry_token,
|
||||||
|
):
|
||||||
|
"""EXPERIMENTAL: fetch the images for a stack from remote registry"""
|
||||||
|
|
||||||
registry_info = RegistryInfo(image_registry, registry_username, registry_token)
|
registry_info = RegistryInfo(image_registry, registry_username, registry_token)
|
||||||
docker = DockerClient()
|
docker = DockerClient()
|
||||||
if not opts.o.quiet:
|
if not opts.o.quiet:
|
||||||
print("Logging into container registry:")
|
print("Logging into container registry:")
|
||||||
docker.login(registry_info.registry, registry_info.registry_username, registry_info.registry_token)
|
docker.login(
|
||||||
|
registry_info.registry,
|
||||||
|
registry_info.registry_username,
|
||||||
|
registry_info.registry_token,
|
||||||
|
)
|
||||||
# Generate list of target containers
|
# Generate list of target containers
|
||||||
stack = ctx.obj.stack
|
stack = ctx.obj.stack
|
||||||
containers_in_scope = get_containers_in_scope(stack)
|
containers_in_scope = get_containers_in_scope(stack)
|
||||||
@@ -172,19 +201,24 @@ def command(ctx, include, exclude, force_local_overwrite, image_registry, regist
|
|||||||
print(f"Fetching: {image_to_fetch}")
|
print(f"Fetching: {image_to_fetch}")
|
||||||
_fetch_image(image_to_fetch, registry_info)
|
_fetch_image(image_to_fetch, registry_info)
|
||||||
# Now check if the target container already exists exists locally already
|
# Now check if the target container already exists exists locally already
|
||||||
if (_exists_locally(container)):
|
if _exists_locally(container):
|
||||||
if not opts.o.quiet:
|
if not opts.o.quiet:
|
||||||
print(f"Container image {container} already exists locally")
|
print(f"Container image {container} already exists locally")
|
||||||
# if so, fail unless the user specified force-local-overwrite
|
# if so, fail unless the user specified force-local-overwrite
|
||||||
if (force_local_overwrite):
|
if force_local_overwrite:
|
||||||
# In that case remove the existing :local tag
|
# In that case remove the existing :local tag
|
||||||
if not opts.o.quiet:
|
if not opts.o.quiet:
|
||||||
print(f"Warning: overwriting local tag from this image: {container} because "
|
print(
|
||||||
"--force-local-overwrite was specified")
|
f"Warning: overwriting local tag from this image: "
|
||||||
|
f"{container} because --force-local-overwrite was specified"
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
if not opts.o.quiet:
|
if not opts.o.quiet:
|
||||||
print(f"Skipping local tagging for this image: {container} because that would "
|
print(
|
||||||
"overwrite an existing :local tagged image, use --force-local-overwrite to do so.")
|
f"Skipping local tagging for this image: {container} "
|
||||||
|
"because that would overwrite an existing :local tagged "
|
||||||
|
"image, use --force-local-overwrite to do so."
|
||||||
|
)
|
||||||
continue
|
continue
|
||||||
# Tag the fetched image with the :local tag
|
# Tag the fetched image with the :local tag
|
||||||
_add_local_tag(image_to_fetch, image_registry, local_tag)
|
_add_local_tag(image_to_fetch, image_registry, local_tag)
|
||||||
@@ -192,4 +226,7 @@ def command(ctx, include, exclude, force_local_overwrite, image_registry, regist
|
|||||||
if opts.o.verbose:
|
if opts.o.verbose:
|
||||||
print(f"Excluding: {container}")
|
print(f"Excluding: {container}")
|
||||||
if not all_containers_found:
|
if not all_containers_found:
|
||||||
print("Warning: couldn't find usable images for one or more containers, this stack will not deploy")
|
print(
|
||||||
|
"Warning: couldn't find usable images for one or more containers, "
|
||||||
|
"this stack will not deploy"
|
||||||
|
)
|
||||||
|
|||||||
@@ -34,5 +34,13 @@ volumes_key = "volumes"
|
|||||||
security_key = "security"
|
security_key = "security"
|
||||||
annotations_key = "annotations"
|
annotations_key = "annotations"
|
||||||
labels_key = "labels"
|
labels_key = "labels"
|
||||||
|
replicas_key = "replicas"
|
||||||
|
node_affinities_key = "node-affinities"
|
||||||
|
node_tolerations_key = "node-tolerations"
|
||||||
kind_config_filename = "kind-config.yml"
|
kind_config_filename = "kind-config.yml"
|
||||||
kube_config_filename = "kubeconfig.yml"
|
kube_config_filename = "kubeconfig.yml"
|
||||||
|
cri_base_filename = "cri-base.json"
|
||||||
|
unlimited_memlock_key = "unlimited-memlock"
|
||||||
|
runtime_class_key = "runtime-class"
|
||||||
|
high_memlock_runtime = "high-memlock"
|
||||||
|
high_memlock_spec_filename = "high-memlock-spec.json"
|
||||||
|
|||||||
@@ -2,10 +2,11 @@ services:
|
|||||||
laconicd:
|
laconicd:
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
image: cerc/laconicd:local
|
image: cerc/laconicd:local
|
||||||
command: ["sh", "/docker-entrypoint-scripts.d/create-fixturenet.sh"]
|
command: ["bash", "/docker-entrypoint-scripts.d/create-fixturenet.sh"]
|
||||||
environment:
|
environment:
|
||||||
TEST_AUCTION_ENABLED: ${TEST_AUCTION_ENABLED}
|
TEST_AUCTION_ENABLED: ${TEST_AUCTION_ENABLED:-false}
|
||||||
TEST_REGISTRY_EXPIRY: ${TEST_REGISTRY_EXPIRY}
|
TEST_REGISTRY_EXPIRY: ${TEST_REGISTRY_EXPIRY:-false}
|
||||||
|
ONBOARDING_ENABLED: ${ONBOARDING_ENABLED:-false}
|
||||||
volumes:
|
volumes:
|
||||||
# The cosmos-sdk node's database directory:
|
# The cosmos-sdk node's database directory:
|
||||||
- laconicd-data:/root/.laconicd
|
- laconicd-data:/root/.laconicd
|
||||||
@@ -19,11 +20,9 @@ services:
|
|||||||
- "26657"
|
- "26657"
|
||||||
- "26656"
|
- "26656"
|
||||||
- "9473"
|
- "9473"
|
||||||
- "8545"
|
|
||||||
- "8546"
|
|
||||||
- "9090"
|
- "9090"
|
||||||
- "9091"
|
|
||||||
- "1317"
|
- "1317"
|
||||||
|
|
||||||
cli:
|
cli:
|
||||||
image: cerc/laconic-registry-cli:local
|
image: cerc/laconic-registry-cli:local
|
||||||
volumes:
|
volumes:
|
||||||
|
|||||||
@@ -14,4 +14,3 @@ services:
|
|||||||
- "9090"
|
- "9090"
|
||||||
- "9091"
|
- "9091"
|
||||||
- "1317"
|
- "1317"
|
||||||
|
|
||||||
|
|||||||
@@ -17,4 +17,3 @@ services:
|
|||||||
- URL_NEUTRON_TEST_REST=https://rest-palvus.pion-1.ntrn.tech
|
- URL_NEUTRON_TEST_REST=https://rest-palvus.pion-1.ntrn.tech
|
||||||
- URL_NEUTRON_TEST_RPC=https://rpc-palvus.pion-1.ntrn.tech
|
- URL_NEUTRON_TEST_RPC=https://rpc-palvus.pion-1.ntrn.tech
|
||||||
- WALLET_CONNECT_ID=0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x
|
- WALLET_CONNECT_ID=0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x
|
||||||
|
|
||||||
|
|||||||
@@ -8,68 +8,68 @@ KEY="mykey"
|
|||||||
CHAINID="laconic_9000-1"
|
CHAINID="laconic_9000-1"
|
||||||
MONIKER="localtestnet"
|
MONIKER="localtestnet"
|
||||||
KEYRING="test"
|
KEYRING="test"
|
||||||
KEYALGO="eth_secp256k1"
|
KEYALGO="secp256k1"
|
||||||
LOGLEVEL="info"
|
LOGLEVEL="${LOGLEVEL:-info}"
|
||||||
# trace evm
|
DENOM="alnt"
|
||||||
TRACE="--trace"
|
|
||||||
# TRACE=""
|
|
||||||
|
|
||||||
if [ "$1" == "clean" ] || [ ! -d "$HOME/.laconicd/data/blockstore.db" ]; then
|
if [ "$1" == "clean" ] || [ ! -d "$HOME/.laconicd/data/blockstore.db" ]; then
|
||||||
# validate dependencies are installed
|
# validate dependencies are installed
|
||||||
command -v jq > /dev/null 2>&1 || { echo >&2 "jq not installed. More info: https://stedolan.github.io/jq/download/"; exit 1; }
|
command -v jq > /dev/null 2>&1 || {
|
||||||
|
echo >&2 "jq not installed. More info: https://stedolan.github.io/jq/download/"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
# remove existing daemon and client
|
# remove existing daemon and client
|
||||||
rm -rf $HOME/.laconicd/*
|
rm -rf $HOME/.laconicd/*
|
||||||
rm -rf $HOME/.laconic/*
|
|
||||||
|
|
||||||
if [ -n "`which make`" ]; then
|
if [ -n "`which make`" ]; then
|
||||||
make install
|
make install
|
||||||
fi
|
fi
|
||||||
|
|
||||||
laconicd config keyring-backend $KEYRING
|
laconicd config set client chain-id $CHAINID
|
||||||
laconicd config chain-id $CHAINID
|
laconicd config set client keyring-backend $KEYRING
|
||||||
|
|
||||||
# if $KEY exists it should be deleted
|
# if $KEY exists it should be deleted
|
||||||
laconicd keys add $KEY --keyring-backend $KEYRING --algo $KEYALGO
|
laconicd keys add $KEY --keyring-backend $KEYRING --algo $KEYALGO
|
||||||
|
|
||||||
# Set moniker and chain-id for Ethermint (Moniker can be anything, chain-id must be an integer)
|
# Set moniker and chain-id for Ethermint (Moniker can be anything, chain-id must be an integer)
|
||||||
laconicd init $MONIKER --chain-id $CHAINID
|
laconicd init $MONIKER --chain-id $CHAINID --default-denom $DENOM
|
||||||
|
|
||||||
# Change parameter token denominations to aphoton
|
update_genesis() {
|
||||||
cat $HOME/.laconicd/config/genesis.json | jq '.app_state["staking"]["params"]["bond_denom"]="aphoton"' > $HOME/.laconicd/config/tmp_genesis.json && mv $HOME/.laconicd/config/tmp_genesis.json $HOME/.laconicd/config/genesis.json
|
jq "$1" $HOME/.laconicd/config/genesis.json > $HOME/.laconicd/config/tmp_genesis.json &&
|
||||||
cat $HOME/.laconicd/config/genesis.json | jq '.app_state["crisis"]["constant_fee"]["denom"]="aphoton"' > $HOME/.laconicd/config/tmp_genesis.json && mv $HOME/.laconicd/config/tmp_genesis.json $HOME/.laconicd/config/genesis.json
|
mv $HOME/.laconicd/config/tmp_genesis.json $HOME/.laconicd/config/genesis.json
|
||||||
cat $HOME/.laconicd/config/genesis.json | jq '.app_state["gov"]["deposit_params"]["min_deposit"][0]["denom"]="aphoton"' > $HOME/.laconicd/config/tmp_genesis.json && mv $HOME/.laconicd/config/tmp_genesis.json $HOME/.laconicd/config/genesis.json
|
}
|
||||||
cat $HOME/.laconicd/config/genesis.json | jq '.app_state["mint"]["params"]["mint_denom"]="aphoton"' > $HOME/.laconicd/config/tmp_genesis.json && mv $HOME/.laconicd/config/tmp_genesis.json $HOME/.laconicd/config/genesis.json
|
|
||||||
# Custom modules
|
|
||||||
cat $HOME/.laconicd/config/genesis.json | jq '.app_state["registry"]["params"]["record_rent"]["denom"]="aphoton"' > $HOME/.laconicd/config/tmp_genesis.json && mv $HOME/.laconicd/config/tmp_genesis.json $HOME/.laconicd/config/genesis.json
|
|
||||||
cat $HOME/.laconicd/config/genesis.json | jq '.app_state["registry"]["params"]["authority_rent"]["denom"]="aphoton"' > $HOME/.laconicd/config/tmp_genesis.json && mv $HOME/.laconicd/config/tmp_genesis.json $HOME/.laconicd/config/genesis.json
|
|
||||||
cat $HOME/.laconicd/config/genesis.json | jq '.app_state["registry"]["params"]["authority_auction_commit_fee"]["denom"]="aphoton"' > $HOME/.laconicd/config/tmp_genesis.json && mv $HOME/.laconicd/config/tmp_genesis.json $HOME/.laconicd/config/genesis.json
|
|
||||||
cat $HOME/.laconicd/config/genesis.json | jq '.app_state["registry"]["params"]["authority_auction_reveal_fee"]["denom"]="aphoton"' > $HOME/.laconicd/config/tmp_genesis.json && mv $HOME/.laconicd/config/tmp_genesis.json $HOME/.laconicd/config/genesis.json
|
|
||||||
cat $HOME/.laconicd/config/genesis.json | jq '.app_state["registry"]["params"]["authority_auction_minimum_bid"]["denom"]="aphoton"' > $HOME/.laconicd/config/tmp_genesis.json && mv $HOME/.laconicd/config/tmp_genesis.json $HOME/.laconicd/config/genesis.json
|
|
||||||
|
|
||||||
if [[ "$TEST_REGISTRY_EXPIRY" == "true" ]]; then
|
if [[ "$TEST_REGISTRY_EXPIRY" == "true" ]]; then
|
||||||
echo "Setting timers for expiry tests."
|
echo "Setting timers for expiry tests."
|
||||||
|
|
||||||
cat $HOME/.laconicd/config/genesis.json | jq '.app_state["registry"]["params"]["record_rent_duration"]="60s"' > $HOME/.laconicd/config/tmp_genesis.json && mv $HOME/.laconicd/config/tmp_genesis.json $HOME/.laconicd/config/genesis.json
|
update_genesis '.app_state["registry"]["params"]["record_rent_duration"]="60s"'
|
||||||
cat $HOME/.laconicd/config/genesis.json | jq '.app_state["registry"]["params"]["authority_grace_period"]="60s"' > $HOME/.laconicd/config/tmp_genesis.json && mv $HOME/.laconicd/config/tmp_genesis.json $HOME/.laconicd/config/genesis.json
|
update_genesis '.app_state["registry"]["params"]["authority_grace_period"]="60s"'
|
||||||
cat $HOME/.laconicd/config/genesis.json | jq '.app_state["registry"]["params"]["authority_rent_duration"]="60s"' > $HOME/.laconicd/config/tmp_genesis.json && mv $HOME/.laconicd/config/tmp_genesis.json $HOME/.laconicd/config/genesis.json
|
update_genesis '.app_state["registry"]["params"]["authority_rent_duration"]="60s"'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$TEST_AUCTION_ENABLED" == "true" ]]; then
|
if [[ "$TEST_AUCTION_ENABLED" == "true" ]]; then
|
||||||
echo "Enabling auction and setting timers."
|
echo "Enabling auction and setting timers."
|
||||||
|
|
||||||
cat $HOME/.laconicd/config/genesis.json | jq '.app_state["registry"]["params"]["authority_auction_enabled"]=true' > $HOME/.laconicd/config/tmp_genesis.json && mv $HOME/.laconicd/config/tmp_genesis.json $HOME/.laconicd/config/genesis.json
|
update_genesis '.app_state["registry"]["params"]["authority_auction_enabled"]=true'
|
||||||
cat $HOME/.laconicd/config/genesis.json | jq '.app_state["registry"]["params"]["authority_rent_duration"]="60s"' > $HOME/.laconicd/config/tmp_genesis.json && mv $HOME/.laconicd/config/tmp_genesis.json $HOME/.laconicd/config/genesis.json
|
update_genesis '.app_state["registry"]["params"]["authority_rent_duration"]="60s"'
|
||||||
cat $HOME/.laconicd/config/genesis.json | jq '.app_state["registry"]["params"]["authority_grace_period"]="300s"' > $HOME/.laconicd/config/tmp_genesis.json && mv $HOME/.laconicd/config/tmp_genesis.json $HOME/.laconicd/config/genesis.json
|
update_genesis '.app_state["registry"]["params"]["authority_grace_period"]="300s"'
|
||||||
cat $HOME/.laconicd/config/genesis.json | jq '.app_state["registry"]["params"]["authority_auction_commits_duration"]="60s"' > $HOME/.laconicd/config/tmp_genesis.json && mv $HOME/.laconicd/config/tmp_genesis.json $HOME/.laconicd/config/genesis.json
|
update_genesis '.app_state["registry"]["params"]["authority_auction_commits_duration"]="60s"'
|
||||||
cat $HOME/.laconicd/config/genesis.json | jq '.app_state["registry"]["params"]["authority_auction_reveals_duration"]="60s"' > $HOME/.laconicd/config/tmp_genesis.json && mv $HOME/.laconicd/config/tmp_genesis.json $HOME/.laconicd/config/genesis.json
|
update_genesis '.app_state["registry"]["params"]["authority_auction_reveals_duration"]="60s"'
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$ONBOARDING_ENABLED" == "true" ]]; then
|
||||||
|
echo "Enabling validator onboarding."
|
||||||
|
|
||||||
|
update_genesis '.app_state["onboarding"]["params"]["onboarding_enabled"]=true'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# increase block time (?)
|
# increase block time (?)
|
||||||
cat $HOME/.laconicd/config/genesis.json | jq '.consensus_params["block"]["time_iota_ms"]="1000"' > $HOME/.laconicd/config/tmp_genesis.json && mv $HOME/.laconicd/config/tmp_genesis.json $HOME/.laconicd/config/genesis.json
|
update_genesis '.consensus["params"]["block"]["time_iota_ms"]="1000"'
|
||||||
|
|
||||||
# Set gas limit in genesis
|
# Set gas limit in genesis
|
||||||
cat $HOME/.laconicd/config/genesis.json | jq '.consensus_params["block"]["max_gas"]="10000000"' > $HOME/.laconicd/config/tmp_genesis.json && mv $HOME/.laconicd/config/tmp_genesis.json $HOME/.laconicd/config/genesis.json
|
update_genesis '.consensus["params"]["block"]["max_gas"]="10000000"'
|
||||||
|
|
||||||
# disable produce empty block
|
# disable produce empty block
|
||||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||||
@@ -78,30 +78,6 @@ if [ "$1" == "clean" ] || [ ! -d "$HOME/.laconicd/data/blockstore.db" ]; then
|
|||||||
sed -i 's/create_empty_blocks = true/create_empty_blocks = false/g' $HOME/.laconicd/config/config.toml
|
sed -i 's/create_empty_blocks = true/create_empty_blocks = false/g' $HOME/.laconicd/config/config.toml
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $1 == "pending" ]]; then
|
|
||||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
|
||||||
sed -i '' 's/create_empty_blocks_interval = "0s"/create_empty_blocks_interval = "30s"/g' $HOME/.laconicd/config/config.toml
|
|
||||||
sed -i '' 's/timeout_propose = "3s"/timeout_propose = "30s"/g' $HOME/.laconicd/config/config.toml
|
|
||||||
sed -i '' 's/timeout_propose_delta = "500ms"/timeout_propose_delta = "5s"/g' $HOME/.laconicd/config/config.toml
|
|
||||||
sed -i '' 's/timeout_prevote = "1s"/timeout_prevote = "10s"/g' $HOME/.laconicd/config/config.toml
|
|
||||||
sed -i '' 's/timeout_prevote_delta = "500ms"/timeout_prevote_delta = "5s"/g' $HOME/.laconicd/config/config.toml
|
|
||||||
sed -i '' 's/timeout_precommit = "1s"/timeout_precommit = "10s"/g' $HOME/.laconicd/config/config.toml
|
|
||||||
sed -i '' 's/timeout_precommit_delta = "500ms"/timeout_precommit_delta = "5s"/g' $HOME/.laconicd/config/config.toml
|
|
||||||
sed -i '' 's/timeout_commit = "5s"/timeout_commit = "150s"/g' $HOME/.laconicd/config/config.toml
|
|
||||||
sed -i '' 's/timeout_broadcast_tx_commit = "10s"/timeout_broadcast_tx_commit = "150s"/g' $HOME/.laconicd/config/config.toml
|
|
||||||
else
|
|
||||||
sed -i 's/create_empty_blocks_interval = "0s"/create_empty_blocks_interval = "30s"/g' $HOME/.laconicd/config/config.toml
|
|
||||||
sed -i 's/timeout_propose = "3s"/timeout_propose = "30s"/g' $HOME/.laconicd/config/config.toml
|
|
||||||
sed -i 's/timeout_propose_delta = "500ms"/timeout_propose_delta = "5s"/g' $HOME/.laconicd/config/config.toml
|
|
||||||
sed -i 's/timeout_prevote = "1s"/timeout_prevote = "10s"/g' $HOME/.laconicd/config/config.toml
|
|
||||||
sed -i 's/timeout_prevote_delta = "500ms"/timeout_prevote_delta = "5s"/g' $HOME/.laconicd/config/config.toml
|
|
||||||
sed -i 's/timeout_precommit = "1s"/timeout_precommit = "10s"/g' $HOME/.laconicd/config/config.toml
|
|
||||||
sed -i 's/timeout_precommit_delta = "500ms"/timeout_precommit_delta = "5s"/g' $HOME/.laconicd/config/config.toml
|
|
||||||
sed -i 's/timeout_commit = "5s"/timeout_commit = "150s"/g' $HOME/.laconicd/config/config.toml
|
|
||||||
sed -i 's/timeout_broadcast_tx_commit = "10s"/timeout_broadcast_tx_commit = "150s"/g' $HOME/.laconicd/config/config.toml
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Enable telemetry (prometheus metrics: http://localhost:1317/metrics?format=prometheus)
|
# Enable telemetry (prometheus metrics: http://localhost:1317/metrics?format=prometheus)
|
||||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||||
sed -i '' 's/enabled = false/enabled = true/g' $HOME/.laconicd/config/app.toml
|
sed -i '' 's/enabled = false/enabled = true/g' $HOME/.laconicd/config/app.toml
|
||||||
@@ -114,23 +90,27 @@ if [ "$1" == "clean" ] || [ ! -d "$HOME/.laconicd/data/blockstore.db" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Allocate genesis accounts (cosmos formatted addresses)
|
# Allocate genesis accounts (cosmos formatted addresses)
|
||||||
laconicd add-genesis-account $KEY 100000000000000000000000000aphoton --keyring-backend $KEYRING
|
# 10^30 alnt | 10^12 lnt
|
||||||
|
laconicd genesis add-genesis-account $KEY 1000000000000000000000000000000$DENOM --keyring-backend $KEYRING
|
||||||
|
|
||||||
# Sign genesis transaction
|
# Sign genesis transaction
|
||||||
laconicd gentx $KEY 1000000000000000000000aphoton --keyring-backend $KEYRING --chain-id $CHAINID
|
# 10^24 alnt | 10^6 lnt
|
||||||
|
laconicd genesis gentx $KEY 1000000000000000000000000$DENOM --keyring-backend $KEYRING --chain-id $CHAINID
|
||||||
|
|
||||||
# Collect genesis tx
|
# Collect genesis tx
|
||||||
laconicd collect-gentxs
|
laconicd genesis collect-gentxs
|
||||||
|
|
||||||
# Run this to ensure everything worked and that the genesis file is setup correctly
|
# Run this to ensure everything worked and that the genesis file is setup correctly
|
||||||
laconicd validate-genesis
|
laconicd genesis validate
|
||||||
|
|
||||||
if [[ $1 == "pending" ]]; then
|
|
||||||
echo "pending mode is on, please wait for the first block committed."
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
echo "Using existing database at $HOME/.laconicd. To replace, run '`basename $0` clean'"
|
echo "Using existing database at $HOME/.laconicd. To replace, run '`basename $0` clean'"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Start the node (remove the --pruning=nothing flag if historical queries are not needed)
|
# Start the node (remove the --pruning=nothing flag if historical queries are not needed)
|
||||||
laconicd start --pruning=nothing --evm.tracer=json $TRACE --log_level $LOGLEVEL --minimum-gas-prices=0.0001aphoton --json-rpc.api eth,txpool,personal,net,debug,web3,miner --api.enable --gql-server --gql-playground
|
laconicd start \
|
||||||
|
--pruning=nothing \
|
||||||
|
--log_level $LOGLEVEL \
|
||||||
|
--minimum-gas-prices=1$DENOM \
|
||||||
|
--api.enable \
|
||||||
|
--rpc.laddr="tcp://0.0.0.0:26657" \
|
||||||
|
--gql-server --gql-playground
|
||||||
|
|||||||
@@ -6,4 +6,4 @@ services:
|
|||||||
bondId:
|
bondId:
|
||||||
chainId: laconic_9000-1
|
chainId: laconic_9000-1
|
||||||
gas: 350000
|
gas: 350000
|
||||||
fees: 200000photon
|
fees: 2000000alnt
|
||||||
|
|||||||
@@ -29,4 +29,3 @@
|
|||||||
"l1_system_config_address": "0x5531dcff39ec1ec727c4c5d2fc49835368f805a9",
|
"l1_system_config_address": "0x5531dcff39ec1ec727c4c5d2fc49835368f805a9",
|
||||||
"protocol_versions_address": "0x0000000000000000000000000000000000000000"
|
"protocol_versions_address": "0x0000000000000000000000000000000000000000"
|
||||||
}
|
}
|
||||||
|
|
||||||
+4
-1
@@ -12,7 +12,10 @@ from fabric import Connection
|
|||||||
|
|
||||||
|
|
||||||
def dump_src_db_to_file(db_host, db_port, db_user, db_password, db_name, file_name):
|
def dump_src_db_to_file(db_host, db_port, db_user, db_password, db_name, file_name):
|
||||||
command = f"pg_dump -h {db_host} -p {db_port} -U {db_user} -d {db_name} -c --inserts -f {file_name}"
|
command = (
|
||||||
|
f"pg_dump -h {db_host} -p {db_port} -U {db_user} "
|
||||||
|
f"-d {db_name} -c --inserts -f {file_name}"
|
||||||
|
)
|
||||||
my_env = os.environ.copy()
|
my_env = os.environ.copy()
|
||||||
my_env["PGPASSWORD"] = db_password
|
my_env["PGPASSWORD"] = db_password
|
||||||
print(f"Exporting from {db_host}:{db_port}/{db_name} to {file_name}... ", end="")
|
print(f"Exporting from {db_host}:{db_port}/{db_name} to {file_name}... ", end="")
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
|
|
||||||
|
|||||||
@@ -6,4 +6,4 @@ services:
|
|||||||
bondId:
|
bondId:
|
||||||
chainId: laconic_9000-1
|
chainId: laconic_9000-1
|
||||||
gas: 250000
|
gas: 250000
|
||||||
fees: 200000photon
|
fees: 2000000alnt
|
||||||
|
|||||||
@@ -1,18 +1,15 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
if [[ -n "$CERC_SCRIPT_DEBUG" ]]; then
|
if [ -n "$CERC_SCRIPT_DEBUG" ]; then
|
||||||
set -x
|
set -x
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#TODO: pass these in from the caller
|
#TODO: pass these in from the caller
|
||||||
TRACE="--trace"
|
|
||||||
LOGLEVEL="info"
|
LOGLEVEL="info"
|
||||||
|
|
||||||
laconicd start \
|
laconicd start \
|
||||||
--pruning=nothing \
|
--pruning=nothing \
|
||||||
--evm.tracer=json $TRACE \
|
|
||||||
--log_level $LOGLEVEL \
|
--log_level $LOGLEVEL \
|
||||||
--minimum-gas-prices=0.0001aphoton \
|
--minimum-gas-prices=1alnt \
|
||||||
--json-rpc.api eth,txpool,personal,net,debug,web3,miner \
|
|
||||||
--api.enable \
|
--api.enable \
|
||||||
--gql-server \
|
--gql-server \
|
||||||
--gql-playground
|
--gql-playground
|
||||||
|
|||||||
@@ -940,4 +940,3 @@ ALTER TABLE ONLY public.state
|
|||||||
--
|
--
|
||||||
-- PostgreSQL database dump complete
|
-- PostgreSQL database dump complete
|
||||||
--
|
--
|
||||||
|
|
||||||
|
|||||||
@@ -18,4 +18,3 @@ root@7c4124bb09e3:/src#
|
|||||||
```
|
```
|
||||||
|
|
||||||
Now gerbil commands can be run.
|
Now gerbil commands can be run.
|
||||||
|
|
||||||
|
|||||||
@@ -68,5 +68,5 @@ ENV PATH="${PATH}:/scripts"
|
|||||||
COPY entrypoint.sh .
|
COPY entrypoint.sh .
|
||||||
ENTRYPOINT ["./entrypoint.sh"]
|
ENTRYPOINT ["./entrypoint.sh"]
|
||||||
# Placeholder CMD : generally this will be overridden at run time like :
|
# Placeholder CMD : generally this will be overridden at run time like :
|
||||||
# docker run -it -v /home/builder/cerc/laconic-sdk:/workspace cerc/builder-js sh -c 'cd /workspace && yarn && yarn build'
|
# docker run -it -v /home/builder/cerc/registry-sdk:/workspace cerc/builder-js sh -c 'cd /workspace && yarn && yarn build'
|
||||||
CMD node --version
|
CMD node --version
|
||||||
|
|||||||
+4
-2
@@ -11,6 +11,8 @@ if len(sys.argv) > 1:
|
|||||||
with open(testnet_config_path) as stream:
|
with open(testnet_config_path) as stream:
|
||||||
data = yaml.safe_load(stream)
|
data = yaml.safe_load(stream)
|
||||||
|
|
||||||
for key, value in data['el_premine'].items():
|
for key, value in data["el_premine"].items():
|
||||||
acct = w3.eth.account.from_mnemonic(data['mnemonic'], account_path=key, passphrase='')
|
acct = w3.eth.account.from_mnemonic(
|
||||||
|
data["mnemonic"], account_path=key, passphrase=""
|
||||||
|
)
|
||||||
print("%s,%s,%s" % (key, acct.address, acct.key.hex()))
|
print("%s,%s,%s" % (key, acct.address, acct.key.hex()))
|
||||||
|
|||||||
+2
-2
@@ -10,11 +10,11 @@ demo_records_dir="scripts/demo-records"
|
|||||||
|
|
||||||
# Check we have funds
|
# Check we have funds
|
||||||
funds_response=$(${registry_command} account get --address $(cat my-address.txt))
|
funds_response=$(${registry_command} account get --address $(cat my-address.txt))
|
||||||
funds_balance=$(echo ${funds_response} | jq -r .[0].balance[0].quantity)
|
funds_balance=$(echo ${funds_response} | jq -r ".[0].balance[0].quantity")
|
||||||
echo "Balance is: ${funds_balance}"
|
echo "Balance is: ${funds_balance}"
|
||||||
|
|
||||||
# Create a bond
|
# Create a bond
|
||||||
bond_create_result=$(${registry_command} bond create --type aphoton --quantity 1000000000)
|
bond_create_result=$(${registry_command} bond create --type alnt --quantity 1000000000)
|
||||||
bond_id=$(echo ${bond_create_result} | jq -r .bondId)
|
bond_id=$(echo ${bond_create_result} | jq -r .bondId)
|
||||||
echo "Created bond with id: ${bond_id}"
|
echo "Created bond with id: ${bond_id}"
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,11 @@ if [ -n "$CERC_SCRIPT_DEBUG" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
CERC_MIN_NEXTVER=13.4.2
|
CERC_MIN_NEXTVER=13.4.2
|
||||||
|
CERC_DEFAULT_WEBPACK_VER="5.93.0"
|
||||||
|
|
||||||
CERC_NEXT_VERSION="${CERC_NEXT_VERSION:-keep}"
|
CERC_NEXT_VERSION="${CERC_NEXT_VERSION:-keep}"
|
||||||
|
CERC_WEBPACK_VERSION="${CERC_WEBPACK_VERSION:-keep}"
|
||||||
|
|
||||||
CERC_BUILD_TOOL="${CERC_BUILD_TOOL}"
|
CERC_BUILD_TOOL="${CERC_BUILD_TOOL}"
|
||||||
if [ -z "$CERC_BUILD_TOOL" ]; then
|
if [ -z "$CERC_BUILD_TOOL" ]; then
|
||||||
if [ -f "pnpm-lock.yaml" ]; then
|
if [ -f "pnpm-lock.yaml" ]; then
|
||||||
@@ -23,15 +26,29 @@ fi
|
|||||||
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
||||||
WORK_DIR="${1:-/app}"
|
WORK_DIR="${1:-/app}"
|
||||||
|
|
||||||
|
if [ -f "${WORK_DIR}/build-webapp.sh" ]; then
|
||||||
|
echo "Building webapp with ${WORK_DIR}/build-webapp.sh ..."
|
||||||
cd "${WORK_DIR}" || exit 1
|
cd "${WORK_DIR}" || exit 1
|
||||||
|
|
||||||
|
./build-webapp.sh || exit 1
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f "next.config.mjs" ]; then
|
||||||
|
NEXT_CONFIG_JS="next.config.mjs"
|
||||||
|
IMPORT_OR_REQUIRE="import"
|
||||||
|
else
|
||||||
|
NEXT_CONFIG_JS="next.config.js"
|
||||||
|
IMPORT_OR_REQUIRE="require"
|
||||||
|
fi
|
||||||
|
|
||||||
# If this file doesn't exist at all, we'll get errors below.
|
# If this file doesn't exist at all, we'll get errors below.
|
||||||
if [ ! -f "next.config.js" ]; then
|
if [ ! -f "${NEXT_CONFIG_JS}" ]; then
|
||||||
touch next.config.js
|
touch ${NEXT_CONFIG_JS}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -f "next.config.dist" ]; then
|
if [ ! -f "next.config.dist" ]; then
|
||||||
cp next.config.js next.config.dist
|
cp $NEXT_CONFIG_JS next.config.dist
|
||||||
fi
|
fi
|
||||||
|
|
||||||
which js-beautify >/dev/null
|
which js-beautify >/dev/null
|
||||||
@@ -39,17 +56,34 @@ if [ $? -ne 0 ]; then
|
|||||||
npm i -g js-beautify
|
npm i -g js-beautify
|
||||||
fi
|
fi
|
||||||
|
|
||||||
js-beautify next.config.dist > next.config.js
|
# js-beautify formats NEXTJS_CONFIG_FILE (ie next.config.js / next.config.mjs) so we can reliably transformable later
|
||||||
echo "" >> next.config.js
|
js-beautify next.config.dist > ${NEXT_CONFIG_JS}
|
||||||
|
echo "" >> ${NEXT_CONFIG_JS}
|
||||||
|
|
||||||
WEBPACK_REQ_LINE=$(grep -n "require([\'\"]webpack[\'\"])" next.config.js | cut -d':' -f1)
|
if [ "${IMPORT_OR_REQUIRE}" == "require" ]; then
|
||||||
if [ -z "$WEBPACK_REQ_LINE" ]; then
|
WEBPACK_REQ_LINE=$(grep -n "require([\'\"]webpack[\'\"])" ${NEXT_CONFIG_JS} | cut -d':' -f1)
|
||||||
cat > next.config.js.0 <<EOF
|
if [ -z "$WEBPACK_REQ_LINE" ]; then
|
||||||
|
cat > ${NEXT_CONFIG_JS}.0 <<EOF
|
||||||
const webpack = require('webpack');
|
const webpack = require('webpack');
|
||||||
EOF
|
EOF
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
WEBPACK_IMPORT_LINE=$(grep -n "^import .*[\'\"]webpack[\'\"];?$" ${NEXT_CONFIG_JS} | cut -d':' -f1)
|
||||||
|
if [ -z "$WEBPACK_IMPORT_LINE" ]; then
|
||||||
|
cat > ${NEXT_CONFIG_JS}.0 <<EOF
|
||||||
|
import webpack from 'webpack';
|
||||||
|
EOF
|
||||||
|
fi
|
||||||
|
CREATE_REQUIRE_LINE=$(grep -n "require = createRequire" ${NEXT_CONFIG_JS} | cut -d':' -f1)
|
||||||
|
if [ -z "$CREATE_REQUIRE_LINE" ]; then
|
||||||
|
cat >> ${NEXT_CONFIG_JS}.0 <<EOF
|
||||||
|
import { createRequire } from "module";
|
||||||
|
const require = createRequire(import.meta.url);
|
||||||
|
EOF
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cat > next.config.js.1 <<EOF
|
cat > ${NEXT_CONFIG_JS}.1 <<EOF
|
||||||
let envMap;
|
let envMap;
|
||||||
try {
|
try {
|
||||||
// .env-list.json provides us a list of identifiers which should be replaced at runtime.
|
// .env-list.json provides us a list of identifiers which should be replaced at runtime.
|
||||||
@@ -57,7 +91,8 @@ try {
|
|||||||
a[v] = \`"CERC_RUNTIME_ENV_\${v.split(/\./).pop()}"\`;
|
a[v] = \`"CERC_RUNTIME_ENV_\${v.split(/\./).pop()}"\`;
|
||||||
return a;
|
return a;
|
||||||
}, {});
|
}, {});
|
||||||
} catch {
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
// If .env-list.json cannot be loaded, we are probably running in dev mode, so use process.env instead.
|
// If .env-list.json cannot be loaded, we are probably running in dev mode, so use process.env instead.
|
||||||
envMap = Object.keys(process.env).reduce((a, v) => {
|
envMap = Object.keys(process.env).reduce((a, v) => {
|
||||||
if (v.startsWith('CERC_')) {
|
if (v.startsWith('CERC_')) {
|
||||||
@@ -66,40 +101,80 @@ try {
|
|||||||
return a;
|
return a;
|
||||||
}, {});
|
}, {});
|
||||||
}
|
}
|
||||||
|
console.log(envMap);
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
CONFIG_LINES=$(wc -l next.config.js | awk '{ print $1 }')
|
grep 'withPWA' ${NEXT_CONFIG_JS} >/dev/null && HAS_WITHPWA=true || HAS_WITHPWA=false
|
||||||
ENV_LINE=$(grep -n 'env:' next.config.js | cut -d':' -f1)
|
|
||||||
WEBPACK_CONF_LINE=$(egrep -n 'webpack:\s+\([^,]+,' next.config.js | cut -d':' -f1)
|
|
||||||
NEXT_SECTION_ADJUSTMENT=0
|
|
||||||
|
|
||||||
if [ -n "$WEBPACK_CONF_LINE" ]; then
|
if [ "$HAS_WITHPWA" == "true" ]; then
|
||||||
WEBPACK_CONF_VAR=$(egrep -n 'webpack:\s+\([^,]+,' next.config.js | cut -d',' -f1 | cut -d'(' -f2)
|
if [ "$IMPORT_OR_REQUIRE" == "import" ]; then
|
||||||
head -$(( ${WEBPACK_CONF_LINE} )) next.config.js > next.config.js.2
|
cat > ${NEXT_CONFIG_JS}.2 <<EOF
|
||||||
cat > next.config.js.3 <<EOF
|
const __xPWA__ = (p) => {
|
||||||
$WEBPACK_CONF_VAR.plugins.push(new webpack.DefinePlugin(envMap));
|
const realPWA = withPWA(p);
|
||||||
EOF
|
return (nextConfig) => {
|
||||||
NEXT_SECTION_LINE=$((WEBPACK_CONF_LINE))
|
const modConfig = {...nextConfig};
|
||||||
elif [ -n "$ENV_LINE" ]; then
|
|
||||||
head -$(( ${ENV_LINE} - 1 )) next.config.js > next.config.js.2
|
modConfig.webpack = (config) => {
|
||||||
cat > next.config.js.3 <<EOF
|
|
||||||
webpack: (config) => {
|
|
||||||
config.plugins.push(new webpack.DefinePlugin(envMap));
|
config.plugins.push(new webpack.DefinePlugin(envMap));
|
||||||
return config;
|
return nextConfig.webpack ? nextConfig.webpack(config) : config;
|
||||||
},
|
};
|
||||||
|
|
||||||
|
return realPWA(modConfig);
|
||||||
|
};
|
||||||
|
};
|
||||||
EOF
|
EOF
|
||||||
NEXT_SECTION_ADJUSTMENT=1
|
else
|
||||||
NEXT_SECTION_LINE=$ENV_LINE
|
cat > ${NEXT_CONFIG_JS}.3 <<EOF
|
||||||
|
const __xPWA__ = (nextConfig) => {
|
||||||
|
const modConfig = {...nextConfig};
|
||||||
|
|
||||||
|
modConfig.webpack = (config) => {
|
||||||
|
config.plugins.push(new webpack.DefinePlugin(envMap));
|
||||||
|
return nextConfig.webpack ? nextConfig.webpack(config) : config;
|
||||||
|
};
|
||||||
|
|
||||||
|
return withPWA(modConfig);
|
||||||
|
};
|
||||||
|
EOF
|
||||||
|
fi
|
||||||
|
|
||||||
|
cat ${NEXT_CONFIG_JS} | js-beautify | sed 's/withPWA(/__xPWA__(/g' > ${NEXT_CONFIG_JS}.4
|
||||||
else
|
else
|
||||||
echo "WARNING: Cannot find location to insert environment variable map in next.config.js" 1>&2
|
cat > ${NEXT_CONFIG_JS}.3 <<EOF
|
||||||
rm -f next.config.js.*
|
const __xCfg__ = (nextConfig) => {
|
||||||
NEXT_SECTION_LINE=0
|
const modConfig = {...nextConfig};
|
||||||
|
|
||||||
|
modConfig.webpack = (config) => {
|
||||||
|
config.plugins.push(new webpack.DefinePlugin(envMap));
|
||||||
|
return nextConfig.webpack ? nextConfig.webpack(config) : config;
|
||||||
|
};
|
||||||
|
|
||||||
|
return modConfig;
|
||||||
|
};
|
||||||
|
EOF
|
||||||
|
if [ "$IMPORT_OR_REQUIRE" == "import" ]; then
|
||||||
|
cat ${NEXT_CONFIG_JS} | js-beautify | sed 's/export\s\+default\s\+/const __orig_cfg__ = /g' > ${NEXT_CONFIG_JS}.4
|
||||||
|
echo "export default __xCfg__(__orig_cfg__);" > ${NEXT_CONFIG_JS}.5
|
||||||
|
else
|
||||||
|
cat ${NEXT_CONFIG_JS} | js-beautify | sed 's/module.exports\s\+=\s\+/const __orig_cfg__ = /g' > ${NEXT_CONFIG_JS}.4
|
||||||
|
echo "module.exports = __xCfg__(__orig_cfg__);" > ${NEXT_CONFIG_JS}.5
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
tail -$(( ${CONFIG_LINES} - ${NEXT_SECTION_LINE} + ${NEXT_SECTION_ADJUSTMENT} )) next.config.js > next.config.js.5
|
|
||||||
|
|
||||||
cat next.config.js.* | sed 's/^ *//g' | js-beautify | grep -v 'process\.\env\.' | js-beautify > next.config.js
|
rm -f ${NEXT_CONFIG_JS}
|
||||||
rm next.config.js.*
|
for ((i=0; i <= 10; i++)); do
|
||||||
|
if [ -s "${NEXT_CONFIG_JS}.${i}" ]; then
|
||||||
|
if [ $i -le 2 ] ; then
|
||||||
|
cat ${NEXT_CONFIG_JS}.${i} >> ${NEXT_CONFIG_JS}
|
||||||
|
else
|
||||||
|
cat ${NEXT_CONFIG_JS}.${i} | sed 's/^ *//g' | js-beautify | grep -v 'process\.\env\.' | js-beautify >> ${NEXT_CONFIG_JS}
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
rm ${NEXT_CONFIG_JS}.*
|
||||||
|
cat ${NEXT_CONFIG_JS} | js-beautify > ${NEXT_CONFIG_JS}.pretty
|
||||||
|
mv ${NEXT_CONFIG_JS}.pretty ${NEXT_CONFIG_JS}
|
||||||
|
|
||||||
"${SCRIPT_DIR}/find-env.sh" "$(pwd)" > .env-list.json
|
"${SCRIPT_DIR}/find-env.sh" "$(pwd)" > .env-list.json
|
||||||
|
|
||||||
@@ -107,8 +182,6 @@ if [ ! -f "package.dist" ]; then
|
|||||||
cp package.json package.dist
|
cp package.json package.dist
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cat package.dist | jq '.scripts.cerc_compile = "next experimental-compile"' | jq '.scripts.cerc_generate = "next experimental-generate"' > package.json
|
|
||||||
|
|
||||||
CUR_NEXT_VERSION="`jq -r '.dependencies.next' package.json`"
|
CUR_NEXT_VERSION="`jq -r '.dependencies.next' package.json`"
|
||||||
|
|
||||||
if [ "$CERC_NEXT_VERSION" != "keep" ] && [ "$CUR_NEXT_VERSION" != "$CERC_NEXT_VERSION" ]; then
|
if [ "$CERC_NEXT_VERSION" != "keep" ] && [ "$CUR_NEXT_VERSION" != "$CERC_NEXT_VERSION" ]; then
|
||||||
@@ -117,10 +190,38 @@ if [ "$CERC_NEXT_VERSION" != "keep" ] && [ "$CUR_NEXT_VERSION" != "$CERC_NEXT_VE
|
|||||||
mv package.json.$$ package.json
|
mv package.json.$$ package.json
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
CUR_WEBPACK_VERSION="`jq -r '.dependencies.webpack' package.json`"
|
||||||
|
if [ -z "$CUR_WEBPACK_VERSION" ]; then
|
||||||
|
CUR_WEBPACK_VERSION="`jq -r '.devDependencies.webpack' package.json`"
|
||||||
|
fi
|
||||||
|
if [ "${CERC_WEBPACK_VERSION}" != "keep" ] || [ "${CUR_WEBPACK_VERSION}" == "null" ]; then
|
||||||
|
if [ -z "$CERC_WEBPACK_VERSION" ] || [ "$CERC_WEBPACK_VERSION" == "keep" ]; then
|
||||||
|
CERC_WEBPACK_VERSION="${CERC_DEFAULT_WEBPACK_VER}"
|
||||||
|
fi
|
||||||
|
echo "Webpack is required for env variable substitution. Adding to webpack@$CERC_WEBPACK_VERSION to dependencies..." 1>&2
|
||||||
|
cat package.json | jq ".dependencies.webpack = \"$CERC_WEBPACK_VERSION\"" > package.json.$$
|
||||||
|
mv package.json.$$ package.json
|
||||||
|
fi
|
||||||
|
|
||||||
time $CERC_BUILD_TOOL install || exit 1
|
time $CERC_BUILD_TOOL install || exit 1
|
||||||
|
|
||||||
CUR_NEXT_VERSION=`jq -r '.version' node_modules/next/package.json`
|
CUR_NEXT_VERSION=`jq -r '.version' node_modules/next/package.json`
|
||||||
|
|
||||||
|
# See https://github.com/vercel/next.js/discussions/46544
|
||||||
|
semver -p -r ">=14.2.0" "$CUR_NEXT_VERSION"
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
# For >= 14.2.0
|
||||||
|
CERC_NEXT_COMPILE_COMMAND="next build --experimental-build-mode compile"
|
||||||
|
CERC_NEXT_GENERATE_COMMAND="next build --experimental-build-mode generate"
|
||||||
|
else
|
||||||
|
# For 13.4.2 to 14.1.x
|
||||||
|
CERC_NEXT_COMPILE_COMMAND="next experimental-compile"
|
||||||
|
CERC_NEXT_GENERATE_COMMAND="next experimental-generate"
|
||||||
|
fi
|
||||||
|
|
||||||
|
cat package.json | jq ".scripts.cerc_compile = \"$CERC_NEXT_COMPILE_COMMAND\"" | jq ".scripts.cerc_generate = \"$CERC_NEXT_GENERATE_COMMAND\"" > package.json.$$
|
||||||
|
mv package.json.$$ package.json
|
||||||
|
|
||||||
semver -p -r ">=$CERC_MIN_NEXTVER" $CUR_NEXT_VERSION
|
semver -p -r ">=$CERC_MIN_NEXTVER" $CUR_NEXT_VERSION
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
|
|||||||
@@ -20,9 +20,11 @@ for d in $(find . -maxdepth 1 -type d | grep -v '\./\.' | grep '/' | cut -d'/' -
|
|||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
|
||||||
NEXT_CONF="next.config.js next.config.dist"
|
NEXT_CONF="next.config.mjs next.config.js next.config.dist"
|
||||||
for f in $NEXT_CONF; do
|
for f in $NEXT_CONF; do
|
||||||
cat "$f" | tr -s '[:blank:]' '\n' | tr -s '[{},()]' '\n' | egrep -o 'process.env.[A-Za-z0-9_]+' >> $TMPF
|
if [ -f "$f" ]; then
|
||||||
|
cat "$f" | tr -s '[:blank:]' '\n' | tr -s '[{},()]' '\n' | egrep -o 'process.env.[A-Za-z0-9_]+' >> $TMPF
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
cat $TMPF | sort -u | jq --raw-input . | jq --slurp .
|
cat $TMPF | sort -u | jq --raw-input . | jq --slurp .
|
||||||
|
|||||||
+34
-26
@@ -30,36 +30,44 @@ fi
|
|||||||
CERC_WEBAPP_FILES_DIR="${CERC_WEBAPP_FILES_DIR:-/app}"
|
CERC_WEBAPP_FILES_DIR="${CERC_WEBAPP_FILES_DIR:-/app}"
|
||||||
cd "$CERC_WEBAPP_FILES_DIR"
|
cd "$CERC_WEBAPP_FILES_DIR"
|
||||||
|
|
||||||
"$SCRIPT_DIR/apply-runtime-env.sh" "`pwd`" .next .next-r
|
if [ -f "./run-webapp.sh" ]; then
|
||||||
mv .next .next.old
|
echo "Running webapp with run-webapp.sh ..."
|
||||||
mv .next-r/.next .
|
cd "${WORK_DIR}" || exit 1
|
||||||
|
./run-webapp.sh &
|
||||||
|
tpid=$!
|
||||||
|
wait $tpid
|
||||||
|
else
|
||||||
|
"$SCRIPT_DIR/apply-runtime-env.sh" "`pwd`" .next .next-r
|
||||||
|
mv .next .next.old
|
||||||
|
mv .next-r/.next .
|
||||||
|
|
||||||
if [ "$CERC_NEXTJS_SKIP_GENERATE" != "true" ]; then
|
if [ "$CERC_NEXTJS_SKIP_GENERATE" != "true" ]; then
|
||||||
jq -e '.scripts.cerc_generate' package.json >/dev/null
|
jq -e '.scripts.cerc_generate' package.json >/dev/null
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
npm run cerc_generate > gen.out 2>&1 &
|
npm run cerc_generate > gen.out 2>&1 &
|
||||||
tail -f gen.out &
|
tail -f gen.out &
|
||||||
tpid=$!
|
tpid=$!
|
||||||
|
|
||||||
count=0
|
count=0
|
||||||
generate_done="false"
|
generate_done="false"
|
||||||
while [ $count -lt $CERC_MAX_GENERATE_TIME ] && [ "$generate_done" == "false" ]; do
|
while [ $count -lt $CERC_MAX_GENERATE_TIME ] && [ "$generate_done" == "false" ]; do
|
||||||
sleep 1
|
sleep 1
|
||||||
count=$((count + 1))
|
count=$((count + 1))
|
||||||
grep 'rendered as static' gen.out > /dev/null
|
grep 'rendered as static' gen.out > /dev/null
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
generate_done="true"
|
generate_done="true"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ $generate_done != "true" ]; then
|
||||||
|
echo "ERROR: 'npm run cerc_generate' not successful within CERC_MAX_GENERATE_TIME" 1>&2
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
done
|
|
||||||
|
|
||||||
if [ $generate_done != "true" ]; then
|
kill $tpid $(ps -ef | grep node | grep next | grep generate | awk '{print $2}') 2>/dev/null
|
||||||
echo "ERROR: 'npm run cerc_generate' not successful within CERC_MAX_GENERATE_TIME" 1>&2
|
tpid=""
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
kill $tpid $(ps -ef | grep node | grep next | grep generate | awk '{print $2}') 2>/dev/null
|
|
||||||
tpid=""
|
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
$CERC_BUILD_TOOL start . -- -p ${CERC_LISTEN_PORT:-80}
|
$CERC_BUILD_TOOL start . -- -p ${CERC_LISTEN_PORT:-80}
|
||||||
|
fi
|
||||||
|
|||||||
@@ -5,4 +5,3 @@ WORKDIR /app
|
|||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
RUN yarn
|
RUN yarn
|
||||||
|
|
||||||
|
|||||||
@@ -4,5 +4,9 @@ source ${CERC_CONTAINER_BASE_DIR}/build-base.sh
|
|||||||
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
||||||
|
|
||||||
# Two-stage build is to allow us to pick up both the upstream repo's files, and local files here for config
|
# Two-stage build is to allow us to pick up both the upstream repo's files, and local files here for config
|
||||||
docker build -t cerc/ping-pub-base:local ${build_command_args} -f $SCRIPT_DIR/Dockerfile.base $CERC_REPO_BASE_DIR/explorer
|
docker build -t cerc/ping-pub-base:local ${build_command_args} -f $SCRIPT_DIR/Dockerfile.base $CERC_REPO_BASE_DIR/cosmos-explorer
|
||||||
|
if [[ $? -ne 0 ]]; then
|
||||||
|
echo "FATAL: Base container build failed, exiting"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
docker build -t cerc/ping-pub:local ${build_command_args} -f $SCRIPT_DIR/Dockerfile $SCRIPT_DIR
|
docker build -t cerc/ping-pub:local ${build_command_args} -f $SCRIPT_DIR/Dockerfile $SCRIPT_DIR
|
||||||
|
|||||||
+4
-4
@@ -7,15 +7,15 @@
|
|||||||
"rpc": [
|
"rpc": [
|
||||||
{"provider": "LX-tendermint-rpc", "address": "LACONIC_LACONICD_RPC_URL"}
|
{"provider": "LX-tendermint-rpc", "address": "LACONIC_LACONICD_RPC_URL"}
|
||||||
],
|
],
|
||||||
"sdk_version": "0.45.1",
|
"sdk_version": "0.50.3",
|
||||||
"coin_type": "118",
|
"coin_type": "118",
|
||||||
"min_tx_fee": "800",
|
"min_tx_fee": "800",
|
||||||
"addr_prefix": "ethm",
|
"addr_prefix": "laconic",
|
||||||
"logo": "/logos/cosmos.svg",
|
"logo": "/logos/cosmos.svg",
|
||||||
"assets": [{
|
"assets": [{
|
||||||
"base": "aphoton",
|
"base": "alnt",
|
||||||
"symbol": "LNT",
|
"symbol": "LNT",
|
||||||
"exponent": "6",
|
"exponent": "18",
|
||||||
"coingecko_id": "cosmos",
|
"coingecko_id": "cosmos",
|
||||||
"logo": "/logos/cosmos.svg"
|
"logo": "/logos/cosmos.svg"
|
||||||
}]
|
}]
|
||||||
|
|||||||
@@ -0,0 +1,260 @@
|
|||||||
|
# Caddy Ingress Controller for kind
|
||||||
|
# Based on: https://github.com/caddyserver/ingress
|
||||||
|
# Provides automatic HTTPS with Let's Encrypt
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Namespace
|
||||||
|
metadata:
|
||||||
|
name: caddy-system
|
||||||
|
labels:
|
||||||
|
app.kubernetes.io/name: caddy-ingress-controller
|
||||||
|
app.kubernetes.io/instance: caddy-ingress
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ServiceAccount
|
||||||
|
metadata:
|
||||||
|
name: caddy-ingress-controller
|
||||||
|
namespace: caddy-system
|
||||||
|
labels:
|
||||||
|
app.kubernetes.io/name: caddy-ingress-controller
|
||||||
|
app.kubernetes.io/instance: caddy-ingress
|
||||||
|
---
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
kind: ClusterRole
|
||||||
|
metadata:
|
||||||
|
name: caddy-ingress-controller
|
||||||
|
labels:
|
||||||
|
app.kubernetes.io/name: caddy-ingress-controller
|
||||||
|
app.kubernetes.io/instance: caddy-ingress
|
||||||
|
rules:
|
||||||
|
- apiGroups:
|
||||||
|
- ""
|
||||||
|
resources:
|
||||||
|
- configmaps
|
||||||
|
- endpoints
|
||||||
|
- nodes
|
||||||
|
- pods
|
||||||
|
- namespaces
|
||||||
|
- services
|
||||||
|
verbs:
|
||||||
|
- list
|
||||||
|
- watch
|
||||||
|
- get
|
||||||
|
- apiGroups:
|
||||||
|
- ""
|
||||||
|
resources:
|
||||||
|
- secrets
|
||||||
|
verbs:
|
||||||
|
- list
|
||||||
|
- watch
|
||||||
|
- get
|
||||||
|
- create
|
||||||
|
- update
|
||||||
|
- delete
|
||||||
|
- apiGroups:
|
||||||
|
- ""
|
||||||
|
resources:
|
||||||
|
- nodes
|
||||||
|
verbs:
|
||||||
|
- get
|
||||||
|
- apiGroups:
|
||||||
|
- ""
|
||||||
|
resources:
|
||||||
|
- events
|
||||||
|
verbs:
|
||||||
|
- create
|
||||||
|
- patch
|
||||||
|
- apiGroups:
|
||||||
|
- networking.k8s.io
|
||||||
|
resources:
|
||||||
|
- ingresses
|
||||||
|
verbs:
|
||||||
|
- get
|
||||||
|
- list
|
||||||
|
- watch
|
||||||
|
- apiGroups:
|
||||||
|
- networking.k8s.io
|
||||||
|
resources:
|
||||||
|
- ingresses/status
|
||||||
|
verbs:
|
||||||
|
- update
|
||||||
|
- apiGroups:
|
||||||
|
- networking.k8s.io
|
||||||
|
resources:
|
||||||
|
- ingressclasses
|
||||||
|
verbs:
|
||||||
|
- get
|
||||||
|
- list
|
||||||
|
- watch
|
||||||
|
- apiGroups:
|
||||||
|
- coordination.k8s.io
|
||||||
|
resources:
|
||||||
|
- leases
|
||||||
|
verbs:
|
||||||
|
- get
|
||||||
|
- create
|
||||||
|
- update
|
||||||
|
---
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
kind: ClusterRoleBinding
|
||||||
|
metadata:
|
||||||
|
name: caddy-ingress-controller
|
||||||
|
labels:
|
||||||
|
app.kubernetes.io/name: caddy-ingress-controller
|
||||||
|
app.kubernetes.io/instance: caddy-ingress
|
||||||
|
roleRef:
|
||||||
|
apiGroup: rbac.authorization.k8s.io
|
||||||
|
kind: ClusterRole
|
||||||
|
name: caddy-ingress-controller
|
||||||
|
subjects:
|
||||||
|
- kind: ServiceAccount
|
||||||
|
name: caddy-ingress-controller
|
||||||
|
namespace: caddy-system
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: caddy-ingress-controller-configmap
|
||||||
|
namespace: caddy-system
|
||||||
|
labels:
|
||||||
|
app.kubernetes.io/name: caddy-ingress-controller
|
||||||
|
app.kubernetes.io/instance: caddy-ingress
|
||||||
|
data:
|
||||||
|
# Caddy global options
|
||||||
|
acmeCA: "https://acme-v02.api.letsencrypt.org/directory"
|
||||||
|
email: ""
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: caddy-ingress-controller
|
||||||
|
namespace: caddy-system
|
||||||
|
labels:
|
||||||
|
app.kubernetes.io/name: caddy-ingress-controller
|
||||||
|
app.kubernetes.io/instance: caddy-ingress
|
||||||
|
app.kubernetes.io/component: controller
|
||||||
|
spec:
|
||||||
|
type: NodePort
|
||||||
|
ports:
|
||||||
|
- name: http
|
||||||
|
port: 80
|
||||||
|
targetPort: http
|
||||||
|
protocol: TCP
|
||||||
|
- name: https
|
||||||
|
port: 443
|
||||||
|
targetPort: https
|
||||||
|
protocol: TCP
|
||||||
|
selector:
|
||||||
|
app.kubernetes.io/name: caddy-ingress-controller
|
||||||
|
app.kubernetes.io/instance: caddy-ingress
|
||||||
|
app.kubernetes.io/component: controller
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: caddy-ingress-controller
|
||||||
|
namespace: caddy-system
|
||||||
|
labels:
|
||||||
|
app.kubernetes.io/name: caddy-ingress-controller
|
||||||
|
app.kubernetes.io/instance: caddy-ingress
|
||||||
|
app.kubernetes.io/component: controller
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app.kubernetes.io/name: caddy-ingress-controller
|
||||||
|
app.kubernetes.io/instance: caddy-ingress
|
||||||
|
app.kubernetes.io/component: controller
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app.kubernetes.io/name: caddy-ingress-controller
|
||||||
|
app.kubernetes.io/instance: caddy-ingress
|
||||||
|
app.kubernetes.io/component: controller
|
||||||
|
spec:
|
||||||
|
serviceAccountName: caddy-ingress-controller
|
||||||
|
terminationGracePeriodSeconds: 60
|
||||||
|
nodeSelector:
|
||||||
|
ingress-ready: "true"
|
||||||
|
kubernetes.io/os: linux
|
||||||
|
tolerations:
|
||||||
|
- effect: NoSchedule
|
||||||
|
key: node-role.kubernetes.io/master
|
||||||
|
operator: Equal
|
||||||
|
- effect: NoSchedule
|
||||||
|
key: node-role.kubernetes.io/control-plane
|
||||||
|
operator: Equal
|
||||||
|
containers:
|
||||||
|
- name: caddy-ingress-controller
|
||||||
|
image: caddy/ingress:latest
|
||||||
|
imagePullPolicy: IfNotPresent
|
||||||
|
ports:
|
||||||
|
- name: http
|
||||||
|
containerPort: 80
|
||||||
|
hostPort: 80
|
||||||
|
protocol: TCP
|
||||||
|
- name: https
|
||||||
|
containerPort: 443
|
||||||
|
hostPort: 443
|
||||||
|
protocol: TCP
|
||||||
|
env:
|
||||||
|
- name: POD_NAME
|
||||||
|
valueFrom:
|
||||||
|
fieldRef:
|
||||||
|
fieldPath: metadata.name
|
||||||
|
- name: POD_NAMESPACE
|
||||||
|
valueFrom:
|
||||||
|
fieldRef:
|
||||||
|
fieldPath: metadata.namespace
|
||||||
|
args:
|
||||||
|
- -config-map=caddy-system/caddy-ingress-controller-configmap
|
||||||
|
- -class-name=caddy
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
cpu: 100m
|
||||||
|
memory: 128Mi
|
||||||
|
limits:
|
||||||
|
cpu: 1000m
|
||||||
|
memory: 512Mi
|
||||||
|
readinessProbe:
|
||||||
|
httpGet:
|
||||||
|
path: /healthz
|
||||||
|
port: 9765
|
||||||
|
initialDelaySeconds: 3
|
||||||
|
periodSeconds: 10
|
||||||
|
livenessProbe:
|
||||||
|
httpGet:
|
||||||
|
path: /healthz
|
||||||
|
port: 9765
|
||||||
|
initialDelaySeconds: 3
|
||||||
|
periodSeconds: 10
|
||||||
|
securityContext:
|
||||||
|
allowPrivilegeEscalation: true
|
||||||
|
capabilities:
|
||||||
|
add:
|
||||||
|
- NET_BIND_SERVICE
|
||||||
|
drop:
|
||||||
|
- ALL
|
||||||
|
runAsUser: 0
|
||||||
|
runAsGroup: 0
|
||||||
|
volumeMounts:
|
||||||
|
- name: caddy-data
|
||||||
|
mountPath: /data
|
||||||
|
- name: caddy-config
|
||||||
|
mountPath: /config
|
||||||
|
volumes:
|
||||||
|
- name: caddy-data
|
||||||
|
emptyDir: {}
|
||||||
|
- name: caddy-config
|
||||||
|
emptyDir: {}
|
||||||
|
---
|
||||||
|
apiVersion: networking.k8s.io/v1
|
||||||
|
kind: IngressClass
|
||||||
|
metadata:
|
||||||
|
name: caddy
|
||||||
|
labels:
|
||||||
|
app.kubernetes.io/name: caddy-ingress-controller
|
||||||
|
app.kubernetes.io/instance: caddy-ingress
|
||||||
|
annotations:
|
||||||
|
ingressclass.kubernetes.io/is-default-class: "true"
|
||||||
|
spec:
|
||||||
|
controller: caddy.io/ingress-controller
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
laconic-sdk
|
registry-sdk
|
||||||
laconic-registry-cli
|
laconic-registry-cli
|
||||||
laconic-console
|
laconic-console
|
||||||
debug
|
debug
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ github.com/cerc-io/ipld-eth-db-validator
|
|||||||
github.com/cerc-io/ipld-eth-beacon-indexer
|
github.com/cerc-io/ipld-eth-beacon-indexer
|
||||||
github.com/cerc-io/ipld-eth-beacon-db
|
github.com/cerc-io/ipld-eth-beacon-db
|
||||||
github.com/cerc-io/laconicd
|
github.com/cerc-io/laconicd
|
||||||
github.com/cerc-io/laconic-sdk
|
github.com/cerc-io/registry-sdk
|
||||||
github.com/cerc-io/laconic-registry-cli
|
github.com/cerc-io/laconic-registry-cli
|
||||||
github.com/cerc-io/laconic-console
|
github.com/cerc-io/laconic-console
|
||||||
github.com/cerc-io/mobymask-watcher-ts
|
github.com/cerc-io/mobymask-watcher-ts
|
||||||
|
|||||||
@@ -58,5 +58,5 @@ Now npm packages can be built:
|
|||||||
Ensure that `CERC_NPM_AUTH_TOKEN` is set with the token printed above when the package-registry stack was deployed (the actual token value will be different than shown in this example):
|
Ensure that `CERC_NPM_AUTH_TOKEN` is set with the token printed above when the package-registry stack was deployed (the actual token value will be different than shown in this example):
|
||||||
```
|
```
|
||||||
$ export CERC_NPM_AUTH_TOKEN=84fe66a73698bf11edbdccd0a338236b7d1d5c45
|
$ export CERC_NPM_AUTH_TOKEN=84fe66a73698bf11edbdccd0a338236b7d1d5c45
|
||||||
$ laconic-so build-npms --include laconic-sdk,laconic-registry-cli
|
$ laconic-so build-npms --include registry-sdk,laconic-registry-cli
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -14,4 +14,3 @@ containers:
|
|||||||
pods:
|
pods:
|
||||||
- fixturenet-blast
|
- fixturenet-blast
|
||||||
- foundry
|
- foundry
|
||||||
|
|
||||||
@@ -3,4 +3,3 @@
|
|||||||
A "loaded" version of fixturenet-eth, with all the bells and whistles enabled.
|
A "loaded" version of fixturenet-eth, with all the bells and whistles enabled.
|
||||||
|
|
||||||
TODO: write me
|
TODO: write me
|
||||||
|
|
||||||
|
|||||||
@@ -64,5 +64,6 @@ $ laconic-so --stack fixturenet-laconic-loaded deploy exec cli ./scripts/create-
|
|||||||
Balance is: 99998999999999998999600000
|
Balance is: 99998999999999998999600000
|
||||||
Created bond with id: dd88e8d6f9567b32b28e70552aea4419c5dd3307ebae85a284d1fe38904e301a
|
Created bond with id: dd88e8d6f9567b32b28e70552aea4419c5dd3307ebae85a284d1fe38904e301a
|
||||||
Published demo-record-1.yml with id: bafyreierh3xnfivexlscdwubvczmddsnf46uytyfvrbdhkjzztvsz6ruly
|
Published demo-record-1.yml with id: bafyreierh3xnfivexlscdwubvczmddsnf46uytyfvrbdhkjzztvsz6ruly
|
||||||
|
...
|
||||||
```
|
```
|
||||||
The published record should be visible in the console.
|
The published records should be visible in the console.
|
||||||
|
|||||||
@@ -7,11 +7,11 @@ repos:
|
|||||||
- github.com/lirewine/crypto
|
- github.com/lirewine/crypto
|
||||||
- github.com/lirewine/gem
|
- github.com/lirewine/gem
|
||||||
- github.com/lirewine/sdk
|
- github.com/lirewine/sdk
|
||||||
- git.vdb.to/cerc-io/laconic-sdk
|
- git.vdb.to/cerc-io/registry-sdk
|
||||||
- git.vdb.to/cerc-io/laconic-registry-cli
|
- git.vdb.to/cerc-io/laconic-registry-cli
|
||||||
- git.vdb.to/cerc-io/laconic-console
|
- git.vdb.to/cerc-io/laconic-console
|
||||||
npms:
|
npms:
|
||||||
- laconic-sdk
|
- registry-sdk
|
||||||
- laconic-registry-cli
|
- laconic-registry-cli
|
||||||
- debug
|
- debug
|
||||||
- crypto
|
- crypto
|
||||||
@@ -30,4 +30,3 @@ config:
|
|||||||
cli:
|
cli:
|
||||||
key: laconicd.mykey
|
key: laconicd.mykey
|
||||||
address: laconicd.myaddress
|
address: laconicd.myaddress
|
||||||
|
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ name: fixturenet-laconicd
|
|||||||
description: "A laconicd fixturenet"
|
description: "A laconicd fixturenet"
|
||||||
repos:
|
repos:
|
||||||
- git.vdb.to/cerc-io/laconicd
|
- git.vdb.to/cerc-io/laconicd
|
||||||
- git.vdb.to/cerc-io/laconic-sdk
|
- git.vdb.to/cerc-io/registry-sdk
|
||||||
- git.vdb.to/cerc-io/laconic-registry-cli
|
- git.vdb.to/cerc-io/laconic-registry-cli
|
||||||
npms:
|
npms:
|
||||||
- laconic-sdk
|
- registry-sdk
|
||||||
- laconic-registry-cli
|
- laconic-registry-cli
|
||||||
containers:
|
containers:
|
||||||
- cerc/laconicd
|
- cerc/laconicd
|
||||||
|
|||||||
@@ -14,26 +14,25 @@
|
|||||||
# along with this program. If not, see <http:#www.gnu.org/licenses/>.
|
# along with this program. If not, see <http:#www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from stack_orchestrator.deploy.deployment_context import DeploymentContext
|
from stack_orchestrator.deploy.deployment_context import DeploymentContext
|
||||||
from ruamel.yaml import YAML
|
|
||||||
|
|
||||||
|
|
||||||
def create(context: DeploymentContext, extra_args):
|
def create(context: DeploymentContext, extra_args):
|
||||||
# Slightly modify the base fixturenet-eth compose file to replace the startup script for fixturenet-eth-geth-1
|
# Slightly modify the base fixturenet-eth compose file to replace the
|
||||||
# We need to start geth with the flag to allow non eip-155 compliant transactions in order to publish the
|
# startup script for fixturenet-eth-geth-1
|
||||||
# deterministic-deployment-proxy contract, which itself is a prereq for Optimism contract deployment
|
# We need to start geth with the flag to allow non eip-155 compliant
|
||||||
fixturenet_eth_compose_file = context.deployment_dir.joinpath('compose', 'docker-compose-fixturenet-eth.yml')
|
# transactions in order to publish the
|
||||||
|
# deterministic-deployment-proxy contract, which itself is a prereq for
|
||||||
|
# Optimism contract deployment
|
||||||
|
fixturenet_eth_compose_file = context.deployment_dir.joinpath(
|
||||||
|
"compose", "docker-compose-fixturenet-eth.yml"
|
||||||
|
)
|
||||||
|
|
||||||
with open(fixturenet_eth_compose_file, 'r') as yaml_file:
|
new_script = "../config/fixturenet-optimism/run-geth.sh:/opt/testnet/run.sh"
|
||||||
yaml = YAML()
|
|
||||||
yaml_data = yaml.load(yaml_file)
|
|
||||||
|
|
||||||
new_script = '../config/fixturenet-optimism/run-geth.sh:/opt/testnet/run.sh'
|
def add_geth_volume(yaml_data):
|
||||||
|
if new_script not in yaml_data["services"]["fixturenet-eth-geth-1"]["volumes"]:
|
||||||
|
yaml_data["services"]["fixturenet-eth-geth-1"]["volumes"].append(new_script)
|
||||||
|
|
||||||
if new_script not in yaml_data['services']['fixturenet-eth-geth-1']['volumes']:
|
context.modify_yaml(fixturenet_eth_compose_file, add_geth_volume)
|
||||||
yaml_data['services']['fixturenet-eth-geth-1']['volumes'].append(new_script)
|
|
||||||
|
|
||||||
with open(fixturenet_eth_compose_file, 'w') as yaml_file:
|
|
||||||
yaml = YAML()
|
|
||||||
yaml.dump(yaml_data, yaml_file)
|
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|||||||
@@ -22,18 +22,24 @@ import yaml
|
|||||||
def create(context, extra_args):
|
def create(context, extra_args):
|
||||||
# Our goal here is just to copy the json files for blast
|
# Our goal here is just to copy the json files for blast
|
||||||
yml_path = context.deployment_dir.joinpath("spec.yml")
|
yml_path = context.deployment_dir.joinpath("spec.yml")
|
||||||
with open(yml_path, 'r') as file:
|
with open(yml_path, "r") as file:
|
||||||
data = yaml.safe_load(file)
|
data = yaml.safe_load(file)
|
||||||
|
|
||||||
mount_point = data['volumes']['blast-data']
|
mount_point = data["volumes"]["blast-data"]
|
||||||
if mount_point[0] == "/":
|
if mount_point[0] == "/":
|
||||||
deploy_dir = Path(mount_point)
|
deploy_dir = Path(mount_point)
|
||||||
else:
|
else:
|
||||||
deploy_dir = context.deployment_dir.joinpath(mount_point)
|
deploy_dir = context.deployment_dir.joinpath(mount_point)
|
||||||
|
|
||||||
command_context = extra_args[2]
|
command_context = extra_args[2]
|
||||||
compose_file = [f for f in command_context.cluster_context.compose_files if "mainnet-blast" in f][0]
|
compose_file = [
|
||||||
source_config_file = Path(compose_file).parent.parent.joinpath("config", "mainnet-blast", "genesis.json")
|
f for f in command_context.cluster_context.compose_files if "mainnet-blast" in f
|
||||||
|
][0]
|
||||||
|
source_config_file = Path(compose_file).parent.parent.joinpath(
|
||||||
|
"config", "mainnet-blast", "genesis.json"
|
||||||
|
)
|
||||||
copy(source_config_file, deploy_dir)
|
copy(source_config_file, deploy_dir)
|
||||||
source_config_file = Path(compose_file).parent.parent.joinpath("config", "mainnet-blast", "rollup.json")
|
source_config_file = Path(compose_file).parent.parent.joinpath(
|
||||||
|
"config", "mainnet-blast", "rollup.json"
|
||||||
|
)
|
||||||
copy(source_config_file, deploy_dir)
|
copy(source_config_file, deploy_dir)
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ def setup(ctx):
|
|||||||
def create(ctx, extra_args):
|
def create(ctx, extra_args):
|
||||||
# Generate the JWT secret and save to its config file
|
# Generate the JWT secret and save to its config file
|
||||||
secret = token_hex(32)
|
secret = token_hex(32)
|
||||||
jwt_file_path = ctx.deployment_dir.joinpath("data", "mainnet_eth_plugeth_config_data", "jwtsecret")
|
jwt_file_path = ctx.deployment_dir.joinpath(
|
||||||
with open(jwt_file_path, 'w+') as jwt_file:
|
"data", "mainnet_eth_plugeth_config_data", "jwtsecret"
|
||||||
|
)
|
||||||
|
with open(jwt_file_path, "w+") as jwt_file:
|
||||||
jwt_file.write(secret)
|
jwt_file.write(secret)
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ def setup(ctx):
|
|||||||
def create(ctx, extra_args):
|
def create(ctx, extra_args):
|
||||||
# Generate the JWT secret and save to its config file
|
# Generate the JWT secret and save to its config file
|
||||||
secret = token_hex(32)
|
secret = token_hex(32)
|
||||||
jwt_file_path = ctx.deployment_dir.joinpath("data", "mainnet_eth_config_data", "jwtsecret")
|
jwt_file_path = ctx.deployment_dir.joinpath(
|
||||||
with open(jwt_file_path, 'w+') as jwt_file:
|
"data", "mainnet_eth_config_data", "jwtsecret"
|
||||||
|
)
|
||||||
|
with open(jwt_file_path, "w+") as jwt_file:
|
||||||
jwt_file.write(secret)
|
jwt_file.write(secret)
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
# Laconic Mainnet Deployment (experimental)
|
# Laconic Mainnet Deployment (experimental)
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,10 @@
|
|||||||
# along with this program. If not, see <http:#www.gnu.org/licenses/>.
|
# along with this program. If not, see <http:#www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from stack_orchestrator.util import get_yaml
|
from stack_orchestrator.util import get_yaml
|
||||||
from stack_orchestrator.deploy.deploy_types import DeployCommandContext, LaconicStackSetupCommand
|
from stack_orchestrator.deploy.deploy_types import (
|
||||||
|
DeployCommandContext,
|
||||||
|
LaconicStackSetupCommand,
|
||||||
|
)
|
||||||
from stack_orchestrator.deploy.deployment_context import DeploymentContext
|
from stack_orchestrator.deploy.deployment_context import DeploymentContext
|
||||||
from stack_orchestrator.deploy.stack_state import State
|
from stack_orchestrator.deploy.stack_state import State
|
||||||
from stack_orchestrator.deploy.deploy_util import VolumeMapping, run_container_command
|
from stack_orchestrator.deploy.deploy_util import VolumeMapping, run_container_command
|
||||||
@@ -22,7 +25,6 @@ from stack_orchestrator.opts import opts
|
|||||||
from enum import Enum
|
from enum import Enum
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from shutil import copyfile, copytree
|
from shutil import copyfile, copytree
|
||||||
import json
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import tomli
|
import tomli
|
||||||
@@ -34,8 +36,9 @@ default_spec_file_content = ""
|
|||||||
class SetupPhase(Enum):
|
class SetupPhase(Enum):
|
||||||
INITIALIZE = 1
|
INITIALIZE = 1
|
||||||
JOIN = 2
|
JOIN = 2
|
||||||
CREATE = 3
|
CONNECT = 3
|
||||||
ILLEGAL = 3
|
CREATE = 4
|
||||||
|
ILLEGAL = 5
|
||||||
|
|
||||||
|
|
||||||
def _client_toml_path(network_dir: Path):
|
def _client_toml_path(network_dir: Path):
|
||||||
@@ -62,36 +65,25 @@ def _get_node_moniker_from_config(network_dir: Path):
|
|||||||
return moniker
|
return moniker
|
||||||
|
|
||||||
|
|
||||||
def _get_node_key_from_gentx(gentx_file_name: str):
|
|
||||||
gentx_file_path = Path(gentx_file_name)
|
|
||||||
if gentx_file_path.exists():
|
|
||||||
with open(Path(gentx_file_name), "rb") as f:
|
|
||||||
parsed_json = json.load(f)
|
|
||||||
return parsed_json['body']['messages'][0]['delegator_address']
|
|
||||||
else:
|
|
||||||
print(f"Error: gentx file: {gentx_file_name} does not exist")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
def _comma_delimited_to_list(list_str: str):
|
def _comma_delimited_to_list(list_str: str):
|
||||||
return list_str.split(",") if list_str else []
|
return list_str.split(",") if list_str else []
|
||||||
|
|
||||||
|
|
||||||
def _get_node_keys_from_gentx_files(gentx_file_list: str):
|
def _get_node_keys_from_gentx_files(gentx_address_list: str):
|
||||||
node_keys = []
|
gentx_addresses = _comma_delimited_to_list(gentx_address_list)
|
||||||
gentx_files = _comma_delimited_to_list(gentx_file_list)
|
return gentx_addresses
|
||||||
for gentx_file in gentx_files:
|
|
||||||
node_key = _get_node_key_from_gentx(gentx_file)
|
|
||||||
if node_key:
|
|
||||||
node_keys.append(node_key)
|
|
||||||
return node_keys
|
|
||||||
|
|
||||||
|
|
||||||
def _copy_gentx_files(network_dir: Path, gentx_file_list: str):
|
def _copy_gentx_files(network_dir: Path, gentx_file_list: str):
|
||||||
gentx_files = _comma_delimited_to_list(gentx_file_list)
|
gentx_files = _comma_delimited_to_list(gentx_file_list)
|
||||||
for gentx_file in gentx_files:
|
for gentx_file in gentx_files:
|
||||||
gentx_file_path = Path(gentx_file)
|
gentx_file_path = Path(gentx_file)
|
||||||
copyfile(gentx_file_path, os.path.join(network_dir, "config", "gentx", os.path.basename(gentx_file_path)))
|
copyfile(
|
||||||
|
gentx_file_path,
|
||||||
|
os.path.join(
|
||||||
|
network_dir, "config", "gentx", os.path.basename(gentx_file_path)
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def _remove_persistent_peers(network_dir: Path):
|
def _remove_persistent_peers(network_dir: Path):
|
||||||
@@ -102,8 +94,13 @@ def _remove_persistent_peers(network_dir: Path):
|
|||||||
with open(config_file_path, "r") as input_file:
|
with open(config_file_path, "r") as input_file:
|
||||||
config_file_content = input_file.read()
|
config_file_content = input_file.read()
|
||||||
persistent_peers_pattern = '^persistent_peers = "(.+?)"'
|
persistent_peers_pattern = '^persistent_peers = "(.+?)"'
|
||||||
replace_with = "persistent_peers = \"\""
|
replace_with = 'persistent_peers = ""'
|
||||||
config_file_content = re.sub(persistent_peers_pattern, replace_with, config_file_content, flags=re.MULTILINE)
|
config_file_content = re.sub(
|
||||||
|
persistent_peers_pattern,
|
||||||
|
replace_with,
|
||||||
|
config_file_content,
|
||||||
|
flags=re.MULTILINE,
|
||||||
|
)
|
||||||
with open(config_file_path, "w") as output_file:
|
with open(config_file_path, "w") as output_file:
|
||||||
output_file.write(config_file_content)
|
output_file.write(config_file_content)
|
||||||
|
|
||||||
@@ -116,8 +113,13 @@ def _insert_persistent_peers(config_dir: Path, new_persistent_peers: str):
|
|||||||
with open(config_file_path, "r") as input_file:
|
with open(config_file_path, "r") as input_file:
|
||||||
config_file_content = input_file.read()
|
config_file_content = input_file.read()
|
||||||
persistent_peers_pattern = r'^persistent_peers = ""'
|
persistent_peers_pattern = r'^persistent_peers = ""'
|
||||||
replace_with = f"persistent_peers = \"{new_persistent_peers}\""
|
replace_with = f'persistent_peers = "{new_persistent_peers}"'
|
||||||
config_file_content = re.sub(persistent_peers_pattern, replace_with, config_file_content, flags=re.MULTILINE)
|
config_file_content = re.sub(
|
||||||
|
persistent_peers_pattern,
|
||||||
|
replace_with,
|
||||||
|
config_file_content,
|
||||||
|
flags=re.MULTILINE,
|
||||||
|
)
|
||||||
with open(config_file_path, "w") as output_file:
|
with open(config_file_path, "w") as output_file:
|
||||||
output_file.write(config_file_content)
|
output_file.write(config_file_content)
|
||||||
|
|
||||||
@@ -129,9 +131,11 @@ def _enable_cors(config_dir: Path):
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
with open(config_file_path, "r") as input_file:
|
with open(config_file_path, "r") as input_file:
|
||||||
config_file_content = input_file.read()
|
config_file_content = input_file.read()
|
||||||
cors_pattern = r'^cors_allowed_origins = \[]'
|
cors_pattern = r"^cors_allowed_origins = \[]"
|
||||||
replace_with = 'cors_allowed_origins = ["*"]'
|
replace_with = 'cors_allowed_origins = ["*"]'
|
||||||
config_file_content = re.sub(cors_pattern, replace_with, config_file_content, flags=re.MULTILINE)
|
config_file_content = re.sub(
|
||||||
|
cors_pattern, replace_with, config_file_content, flags=re.MULTILINE
|
||||||
|
)
|
||||||
with open(config_file_path, "w") as output_file:
|
with open(config_file_path, "w") as output_file:
|
||||||
output_file.write(config_file_content)
|
output_file.write(config_file_content)
|
||||||
app_file_path = config_dir.joinpath("app.toml")
|
app_file_path = config_dir.joinpath("app.toml")
|
||||||
@@ -140,9 +144,46 @@ def _enable_cors(config_dir: Path):
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
with open(app_file_path, "r") as input_file:
|
with open(app_file_path, "r") as input_file:
|
||||||
app_file_content = input_file.read()
|
app_file_content = input_file.read()
|
||||||
cors_pattern = r'^enabled-unsafe-cors = false'
|
cors_pattern = r"^enabled-unsafe-cors = false"
|
||||||
replace_with = "enabled-unsafe-cors = true"
|
replace_with = "enabled-unsafe-cors = true"
|
||||||
app_file_content = re.sub(cors_pattern, replace_with, app_file_content, flags=re.MULTILINE)
|
app_file_content = re.sub(
|
||||||
|
cors_pattern, replace_with, app_file_content, flags=re.MULTILINE
|
||||||
|
)
|
||||||
|
with open(app_file_path, "w") as output_file:
|
||||||
|
output_file.write(app_file_content)
|
||||||
|
|
||||||
|
|
||||||
|
def _set_listen_address(config_dir: Path):
|
||||||
|
config_file_path = config_dir.joinpath("config.toml")
|
||||||
|
if not config_file_path.exists():
|
||||||
|
print("Error: config.toml not found")
|
||||||
|
sys.exit(1)
|
||||||
|
with open(config_file_path, "r") as input_file:
|
||||||
|
config_file_content = input_file.read()
|
||||||
|
existing_pattern = r'^laddr = "tcp://127.0.0.1:26657"'
|
||||||
|
replace_with = 'laddr = "tcp://0.0.0.0:26657"'
|
||||||
|
print(f"Replacing in: {config_file_path}")
|
||||||
|
config_file_content = re.sub(
|
||||||
|
existing_pattern, replace_with, config_file_content, flags=re.MULTILINE
|
||||||
|
)
|
||||||
|
with open(config_file_path, "w") as output_file:
|
||||||
|
output_file.write(config_file_content)
|
||||||
|
app_file_path = config_dir.joinpath("app.toml")
|
||||||
|
if not app_file_path.exists():
|
||||||
|
print("Error: app.toml not found")
|
||||||
|
sys.exit(1)
|
||||||
|
with open(app_file_path, "r") as input_file:
|
||||||
|
app_file_content = input_file.read()
|
||||||
|
existing_pattern1 = r'^address = "tcp://localhost:1317"'
|
||||||
|
replace_with1 = 'address = "tcp://0.0.0.0:1317"'
|
||||||
|
app_file_content = re.sub(
|
||||||
|
existing_pattern1, replace_with1, app_file_content, flags=re.MULTILINE
|
||||||
|
)
|
||||||
|
existing_pattern2 = r'^address = "localhost:9090"'
|
||||||
|
replace_with2 = 'address = "0.0.0.0:9090"'
|
||||||
|
app_file_content = re.sub(
|
||||||
|
existing_pattern2, replace_with2, app_file_content, flags=re.MULTILINE
|
||||||
|
)
|
||||||
with open(app_file_path, "w") as output_file:
|
with open(app_file_path, "w") as output_file:
|
||||||
output_file.write(app_file_content)
|
output_file.write(app_file_content)
|
||||||
|
|
||||||
@@ -151,7 +192,10 @@ def _phase_from_params(parameters):
|
|||||||
phase = SetupPhase.ILLEGAL
|
phase = SetupPhase.ILLEGAL
|
||||||
if parameters.initialize_network:
|
if parameters.initialize_network:
|
||||||
if parameters.join_network or parameters.create_network:
|
if parameters.join_network or parameters.create_network:
|
||||||
print("Can't supply --join-network or --create-network with --initialize-network")
|
print(
|
||||||
|
"Can't supply --join-network or --create-network "
|
||||||
|
"with --initialize-network"
|
||||||
|
)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
if not parameters.chain_id:
|
if not parameters.chain_id:
|
||||||
print("--chain-id is required")
|
print("--chain-id is required")
|
||||||
@@ -163,22 +207,39 @@ def _phase_from_params(parameters):
|
|||||||
phase = SetupPhase.INITIALIZE
|
phase = SetupPhase.INITIALIZE
|
||||||
elif parameters.join_network:
|
elif parameters.join_network:
|
||||||
if parameters.initialize_network or parameters.create_network:
|
if parameters.initialize_network or parameters.create_network:
|
||||||
print("Can't supply --initialize-network or --create-network with --join-network")
|
print(
|
||||||
|
"Can't supply --initialize-network or --create-network "
|
||||||
|
"with --join-network"
|
||||||
|
)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
phase = SetupPhase.JOIN
|
phase = SetupPhase.JOIN
|
||||||
elif parameters.create_network:
|
elif parameters.create_network:
|
||||||
if parameters.initialize_network or parameters.join_network:
|
if parameters.initialize_network or parameters.join_network:
|
||||||
print("Can't supply --initialize-network or --join-network with --create-network")
|
print(
|
||||||
|
"Can't supply --initialize-network or --join-network "
|
||||||
|
"with --create-network"
|
||||||
|
)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
phase = SetupPhase.CREATE
|
phase = SetupPhase.CREATE
|
||||||
|
elif parameters.connect_network:
|
||||||
|
if parameters.initialize_network or parameters.join_network:
|
||||||
|
print(
|
||||||
|
"Can't supply --initialize-network or --join-network "
|
||||||
|
"with --connect-network"
|
||||||
|
)
|
||||||
|
sys.exit(1)
|
||||||
|
phase = SetupPhase.CONNECT
|
||||||
return phase
|
return phase
|
||||||
|
|
||||||
|
|
||||||
def setup(command_context: DeployCommandContext, parameters: LaconicStackSetupCommand, extra_args):
|
def setup(
|
||||||
|
command_context: DeployCommandContext,
|
||||||
|
parameters: LaconicStackSetupCommand,
|
||||||
|
extra_args,
|
||||||
|
):
|
||||||
options = opts.o
|
options = opts.o
|
||||||
|
|
||||||
currency = "stake" # Does this need to be a parameter?
|
currency = "alnt" # Does this need to be a parameter?
|
||||||
|
|
||||||
if options.debug:
|
if options.debug:
|
||||||
print(f"parameters: {parameters}")
|
print(f"parameters: {parameters}")
|
||||||
@@ -187,12 +248,9 @@ def setup(command_context: DeployCommandContext, parameters: LaconicStackSetupCo
|
|||||||
|
|
||||||
network_dir = Path(parameters.network_dir).absolute()
|
network_dir = Path(parameters.network_dir).absolute()
|
||||||
laconicd_home_path_in_container = "/laconicd-home"
|
laconicd_home_path_in_container = "/laconicd-home"
|
||||||
mounts = [
|
mounts = [VolumeMapping(str(network_dir), laconicd_home_path_in_container)]
|
||||||
VolumeMapping(network_dir, laconicd_home_path_in_container)
|
|
||||||
]
|
|
||||||
|
|
||||||
if phase == SetupPhase.INITIALIZE:
|
if phase == SetupPhase.INITIALIZE:
|
||||||
|
|
||||||
# We want to create the directory so if it exists that's an error
|
# We want to create the directory so if it exists that's an error
|
||||||
if os.path.exists(network_dir):
|
if os.path.exists(network_dir):
|
||||||
print(f"Error: network directory {network_dir} already exists")
|
print(f"Error: network directory {network_dir} already exists")
|
||||||
@@ -202,12 +260,18 @@ def setup(command_context: DeployCommandContext, parameters: LaconicStackSetupCo
|
|||||||
|
|
||||||
output, status = run_container_command(
|
output, status = run_container_command(
|
||||||
command_context,
|
command_context,
|
||||||
"laconicd", f"laconicd init {parameters.node_moniker} --home {laconicd_home_path_in_container}\
|
"laconicd",
|
||||||
--chain-id {parameters.chain_id}", mounts)
|
f"laconicd init {parameters.node_moniker} "
|
||||||
|
f"--home {laconicd_home_path_in_container} "
|
||||||
|
f"--chain-id {parameters.chain_id} --default-denom {currency}",
|
||||||
|
mounts,
|
||||||
|
)
|
||||||
if options.debug:
|
if options.debug:
|
||||||
print(f"Command output: {output}")
|
print(f"Command output: {output}")
|
||||||
|
|
||||||
elif phase == SetupPhase.JOIN:
|
elif phase == SetupPhase.JOIN:
|
||||||
|
# In the join phase (alternative to connect) we are participating in a
|
||||||
|
# genesis ceremony for the chain
|
||||||
if not os.path.exists(network_dir):
|
if not os.path.exists(network_dir):
|
||||||
print(f"Error: network directory {network_dir} doesn't exist")
|
print(f"Error: network directory {network_dir} doesn't exist")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
@@ -215,76 +279,147 @@ def setup(command_context: DeployCommandContext, parameters: LaconicStackSetupCo
|
|||||||
chain_id = _get_chain_id_from_config(network_dir)
|
chain_id = _get_chain_id_from_config(network_dir)
|
||||||
|
|
||||||
output1, status1 = run_container_command(
|
output1, status1 = run_container_command(
|
||||||
command_context, "laconicd", f"laconicd keys add {parameters.key_name} --home {laconicd_home_path_in_container}\
|
command_context,
|
||||||
--keyring-backend test", mounts)
|
"laconicd",
|
||||||
|
f"laconicd keys add {parameters.key_name} "
|
||||||
|
f"--home {laconicd_home_path_in_container} --keyring-backend test",
|
||||||
|
mounts,
|
||||||
|
)
|
||||||
if options.debug:
|
if options.debug:
|
||||||
print(f"Command output: {output1}")
|
print(f"Command output: {output1}")
|
||||||
output2, status2 = run_container_command(
|
output2, status2 = run_container_command(
|
||||||
command_context,
|
command_context,
|
||||||
"laconicd",
|
"laconicd",
|
||||||
f"laconicd add-genesis-account {parameters.key_name} 12900000000000000000000{currency}\
|
f"laconicd genesis add-genesis-account {parameters.key_name} "
|
||||||
--home {laconicd_home_path_in_container} --keyring-backend test",
|
f"12900000000000000000000{currency} "
|
||||||
mounts)
|
f"--home {laconicd_home_path_in_container} --keyring-backend test",
|
||||||
|
mounts,
|
||||||
|
)
|
||||||
if options.debug:
|
if options.debug:
|
||||||
print(f"Command output: {output2}")
|
print(f"Command output: {output2}")
|
||||||
output3, status3 = run_container_command(
|
output3, status3 = run_container_command(
|
||||||
command_context,
|
command_context,
|
||||||
"laconicd",
|
"laconicd",
|
||||||
f"laconicd gentx {parameters.key_name} 90000000000{currency} --home {laconicd_home_path_in_container}\
|
f"laconicd genesis gentx {parameters.key_name} "
|
||||||
--chain-id {chain_id} --keyring-backend test",
|
f"90000000000{currency} --home {laconicd_home_path_in_container} "
|
||||||
mounts)
|
f"--chain-id {chain_id} --keyring-backend test",
|
||||||
|
mounts,
|
||||||
|
)
|
||||||
if options.debug:
|
if options.debug:
|
||||||
print(f"Command output: {output3}")
|
print(f"Command output: {output3}")
|
||||||
output4, status4 = run_container_command(
|
output4, status4 = run_container_command(
|
||||||
command_context,
|
command_context,
|
||||||
"laconicd",
|
"laconicd",
|
||||||
f"laconicd keys show {parameters.key_name} -a --home {laconicd_home_path_in_container} --keyring-backend test",
|
f"laconicd keys show {parameters.key_name} -a "
|
||||||
mounts)
|
f"--home {laconicd_home_path_in_container} --keyring-backend test",
|
||||||
print(f"Node validator address: {output4}")
|
mounts,
|
||||||
|
)
|
||||||
|
print(f"Node account address: {output4}")
|
||||||
|
|
||||||
|
elif phase == SetupPhase.CONNECT:
|
||||||
|
# In the connect phase (named to not conflict with join) we are
|
||||||
|
# making a node that syncs a chain with existing genesis.json
|
||||||
|
# but not with validator role. We need this kind of node in order to
|
||||||
|
# bootstrap it into a validator after it syncs
|
||||||
|
output1, status1 = run_container_command(
|
||||||
|
command_context,
|
||||||
|
"laconicd",
|
||||||
|
f"laconicd keys add {parameters.key_name} "
|
||||||
|
f"--home {laconicd_home_path_in_container} --keyring-backend test",
|
||||||
|
mounts,
|
||||||
|
)
|
||||||
|
if options.debug:
|
||||||
|
print(f"Command output: {output1}")
|
||||||
|
output2, status2 = run_container_command(
|
||||||
|
command_context,
|
||||||
|
"laconicd",
|
||||||
|
f"laconicd keys show {parameters.key_name} -a "
|
||||||
|
f"--home {laconicd_home_path_in_container} --keyring-backend test",
|
||||||
|
mounts,
|
||||||
|
)
|
||||||
|
print(f"Node account address: {output2}")
|
||||||
|
output3, status3 = run_container_command(
|
||||||
|
command_context,
|
||||||
|
"laconicd",
|
||||||
|
f"laconicd cometbft show-validator "
|
||||||
|
f"--home {laconicd_home_path_in_container}",
|
||||||
|
mounts,
|
||||||
|
)
|
||||||
|
print(f"Node validator address: {output3}")
|
||||||
|
|
||||||
elif phase == SetupPhase.CREATE:
|
elif phase == SetupPhase.CREATE:
|
||||||
if not os.path.exists(network_dir):
|
if not os.path.exists(network_dir):
|
||||||
print(f"Error: network directory {network_dir} doesn't exist")
|
print(f"Error: network directory {network_dir} doesn't exist")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# In the CREATE phase, we are either a "coordinator" node, generating the genesis.json file ourselves
|
# In the CREATE phase, we are either a "coordinator" node,
|
||||||
# OR we are a "not-coordinator" node, consuming a genesis file we got from the coordinator node.
|
# generating the genesis.json file ourselves
|
||||||
|
# OR we are a "not-coordinator" node, consuming a genesis file from
|
||||||
|
# the coordinator node.
|
||||||
if parameters.genesis_file:
|
if parameters.genesis_file:
|
||||||
# We got the genesis file from elsewhere
|
# We got the genesis file from elsewhere
|
||||||
# Copy it into our network dir
|
# Copy it into our network dir
|
||||||
genesis_file_path = Path(parameters.genesis_file)
|
genesis_file_path = Path(parameters.genesis_file)
|
||||||
if not os.path.exists(genesis_file_path):
|
if not os.path.exists(genesis_file_path):
|
||||||
print(f"Error: supplied genesis file: {parameters.genesis_file} does not exist.")
|
print(
|
||||||
|
f"Error: supplied genesis file: {parameters.genesis_file} "
|
||||||
|
"does not exist."
|
||||||
|
)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
copyfile(genesis_file_path, os.path.join(network_dir, "config", os.path.basename(genesis_file_path)))
|
copyfile(
|
||||||
|
genesis_file_path,
|
||||||
|
os.path.join(
|
||||||
|
network_dir, "config", os.path.basename(genesis_file_path)
|
||||||
|
),
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
# We're generating the genesis file
|
# We're generating the genesis file
|
||||||
if not parameters.gentx_file_list:
|
|
||||||
print("Error: --gentx-files must be supplied")
|
|
||||||
sys.exit(1)
|
|
||||||
# First look in the supplied gentx files for the other nodes' keys
|
# First look in the supplied gentx files for the other nodes' keys
|
||||||
other_node_keys = _get_node_keys_from_gentx_files(parameters.gentx_file_list)
|
other_node_keys = _get_node_keys_from_gentx_files(
|
||||||
|
parameters.gentx_address_list
|
||||||
|
)
|
||||||
# Add those keys to our genesis, with balances we determine here (why?)
|
# Add those keys to our genesis, with balances we determine here (why?)
|
||||||
|
outputk = None
|
||||||
for other_node_key in other_node_keys:
|
for other_node_key in other_node_keys:
|
||||||
outputk, statusk = run_container_command(
|
outputk, statusk = run_container_command(
|
||||||
command_context, "laconicd", f"laconicd add-genesis-account {other_node_key} 12900000000000000000000{currency}\
|
command_context,
|
||||||
--home {laconicd_home_path_in_container} --keyring-backend test", mounts)
|
"laconicd",
|
||||||
if options.debug:
|
f"laconicd genesis add-genesis-account {other_node_key} "
|
||||||
|
f"12900000000000000000000{currency} "
|
||||||
|
f"--home {laconicd_home_path_in_container} "
|
||||||
|
"--keyring-backend test",
|
||||||
|
mounts,
|
||||||
|
)
|
||||||
|
if options.debug and outputk is not None:
|
||||||
print(f"Command output: {outputk}")
|
print(f"Command output: {outputk}")
|
||||||
# Copy the gentx json files into our network dir
|
# Copy the gentx json files into our network dir
|
||||||
_copy_gentx_files(network_dir, parameters.gentx_file_list)
|
_copy_gentx_files(network_dir, parameters.gentx_file_list)
|
||||||
# Now we can run collect-gentxs
|
# Now we can run collect-gentxs
|
||||||
output1, status1 = run_container_command(
|
output1, status1 = run_container_command(
|
||||||
command_context, "laconicd", f"laconicd collect-gentxs --home {laconicd_home_path_in_container}", mounts)
|
command_context,
|
||||||
|
"laconicd",
|
||||||
|
f"laconicd genesis collect-gentxs "
|
||||||
|
f"--home {laconicd_home_path_in_container}",
|
||||||
|
mounts,
|
||||||
|
)
|
||||||
if options.debug:
|
if options.debug:
|
||||||
print(f"Command output: {output1}")
|
print(f"Command output: {output1}")
|
||||||
print(f"Generated genesis file, please copy to other nodes as required: \
|
genesis_path = os.path.join(network_dir, "config", "genesis.json")
|
||||||
{os.path.join(network_dir, 'config', 'genesis.json')}")
|
print(
|
||||||
# Last thing, collect-gentxs puts a likely bogus set of persistent_peers in config.toml so we remove that now
|
f"Generated genesis file, please copy to other nodes "
|
||||||
|
f"as required: {genesis_path}"
|
||||||
|
)
|
||||||
|
# Last thing, collect-gentxs puts a likely bogus set of persistent_peers
|
||||||
|
# in config.toml so we remove that now
|
||||||
_remove_persistent_peers(network_dir)
|
_remove_persistent_peers(network_dir)
|
||||||
# In both cases we validate the genesis file now
|
# In both cases we validate the genesis file now
|
||||||
output2, status1 = run_container_command(
|
output2, status1 = run_container_command(
|
||||||
command_context, "laconicd", f"laconicd validate-genesis --home {laconicd_home_path_in_container}", mounts)
|
command_context,
|
||||||
|
"laconicd",
|
||||||
|
f"laconicd genesis validate-genesis "
|
||||||
|
f"--home {laconicd_home_path_in_container}",
|
||||||
|
mounts,
|
||||||
|
)
|
||||||
print(f"validate-genesis result: {output2}")
|
print(f"validate-genesis result: {output2}")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@@ -303,15 +438,23 @@ def create(deployment_context: DeploymentContext, extra_args):
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
config_dir_path = network_dir_path.joinpath("config")
|
config_dir_path = network_dir_path.joinpath("config")
|
||||||
if not (config_dir_path.exists() and config_dir_path.is_dir()):
|
if not (config_dir_path.exists() and config_dir_path.is_dir()):
|
||||||
print(f"Error: supplied network directory does not contain a config directory: {config_dir_path}")
|
print(
|
||||||
|
f"Error: supplied network directory does not contain "
|
||||||
|
f"a config directory: {config_dir_path}"
|
||||||
|
)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
data_dir_path = network_dir_path.joinpath("data")
|
data_dir_path = network_dir_path.joinpath("data")
|
||||||
if not (data_dir_path.exists() and data_dir_path.is_dir()):
|
if not (data_dir_path.exists() and data_dir_path.is_dir()):
|
||||||
print(f"Error: supplied network directory does not contain a data directory: {data_dir_path}")
|
print(
|
||||||
|
f"Error: supplied network directory does not contain "
|
||||||
|
f"a data directory: {data_dir_path}"
|
||||||
|
)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
# Copy the network directory contents into our deployment
|
# Copy the network directory contents into our deployment
|
||||||
# TODO: change this to work with non local paths
|
# TODO: change this to work with non local paths
|
||||||
deployment_config_dir = deployment_context.deployment_dir.joinpath("data", "laconicd-config")
|
deployment_config_dir = deployment_context.deployment_dir.joinpath(
|
||||||
|
"data", "laconicd-config"
|
||||||
|
)
|
||||||
copytree(config_dir_path, deployment_config_dir, dirs_exist_ok=True)
|
copytree(config_dir_path, deployment_config_dir, dirs_exist_ok=True)
|
||||||
# If supplied, add the initial persistent peers to the config file
|
# If supplied, add the initial persistent peers to the config file
|
||||||
if extra_args[1]:
|
if extra_args[1]:
|
||||||
@@ -319,9 +462,12 @@ def create(deployment_context: DeploymentContext, extra_args):
|
|||||||
_insert_persistent_peers(deployment_config_dir, initial_persistent_peers)
|
_insert_persistent_peers(deployment_config_dir, initial_persistent_peers)
|
||||||
# Enable CORS headers so explorers and so on can talk to the node
|
# Enable CORS headers so explorers and so on can talk to the node
|
||||||
_enable_cors(deployment_config_dir)
|
_enable_cors(deployment_config_dir)
|
||||||
|
_set_listen_address(deployment_config_dir)
|
||||||
# Copy the data directory contents into our deployment
|
# Copy the data directory contents into our deployment
|
||||||
# TODO: change this to work with non local paths
|
# TODO: change this to work with non local paths
|
||||||
deployment_data_dir = deployment_context.deployment_dir.joinpath("data", "laconicd-data")
|
deployment_data_dir = deployment_context.deployment_dir.joinpath(
|
||||||
|
"data", "laconicd-data"
|
||||||
|
)
|
||||||
copytree(data_dir_path, deployment_data_dir, dirs_exist_ok=True)
|
copytree(data_dir_path, deployment_data_dir, dirs_exist_ok=True)
|
||||||
|
|
||||||
|
|
||||||
@@ -331,7 +477,6 @@ def init(command_context: DeployCommandContext):
|
|||||||
|
|
||||||
|
|
||||||
def get_state(command_context: DeployCommandContext):
|
def get_state(command_context: DeployCommandContext):
|
||||||
print("Here we get state")
|
|
||||||
return State.CONFIGURED
|
return State.CONFIGURED
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,12 +7,12 @@ repos:
|
|||||||
- github.com/lirewine/crypto
|
- github.com/lirewine/crypto
|
||||||
- github.com/lirewine/gem
|
- github.com/lirewine/gem
|
||||||
- github.com/lirewine/sdk
|
- github.com/lirewine/sdk
|
||||||
- git.vdb.to/cerc-io/laconic-sdk
|
- git.vdb.to/cerc-io/registry-sdk
|
||||||
- git.vdb.to/cerc-io/laconic-registry-cli
|
- git.vdb.to/cerc-io/laconic-registry-cli
|
||||||
- git.vdb.to/cerc-io/laconic-console
|
- git.vdb.to/cerc-io/laconic-console
|
||||||
- github.com/ping-pub/explorer
|
- git.vdb.to/cerc-io/cosmos-explorer
|
||||||
npms:
|
npms:
|
||||||
- laconic-sdk
|
- registry-sdk
|
||||||
- laconic-registry-cli
|
- laconic-registry-cli
|
||||||
- debug
|
- debug
|
||||||
- crypto
|
- crypto
|
||||||
|
|||||||
@@ -8,8 +8,11 @@ echo "Environment variables:"
|
|||||||
env
|
env
|
||||||
# Test laconic stack
|
# Test laconic stack
|
||||||
echo "Running laconic stack test"
|
echo "Running laconic stack test"
|
||||||
# Bit of a hack, test the most recent package
|
if [ "$1" == "from-path" ]; then
|
||||||
TEST_TARGET_SO=$( ls -t1 ./package/laconic-so* | head -1 )
|
TEST_TARGET_SO="laconic-so"
|
||||||
|
else
|
||||||
|
TEST_TARGET_SO=$( ls -t1 ./package/laconic-so* | head -1 )
|
||||||
|
fi
|
||||||
# Set a non-default repo dir
|
# Set a non-default repo dir
|
||||||
export CERC_REPO_BASE_DIR=~/stack-orchestrator-test/repo-base-dir
|
export CERC_REPO_BASE_DIR=~/stack-orchestrator-test/repo-base-dir
|
||||||
echo "Testing this package: $TEST_TARGET_SO"
|
echo "Testing this package: $TEST_TARGET_SO"
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ Setup a test chain:
|
|||||||
```bash
|
```bash
|
||||||
export CERC_NPM_REGISTRY_URL=https://git.vdb.to/api/packages/cerc-io/npm/
|
export CERC_NPM_REGISTRY_URL=https://git.vdb.to/api/packages/cerc-io/npm/
|
||||||
|
|
||||||
laconic-so --stack fixturenet-laconic-loaded setup-repositories --include git.vdb.to/cerc-io/laconicd,git.vdb.to/cerc-io/laconic-sdk,git.vdb.to/cerc-io/laconic-registry-cli,git.vdb.to/cerc-io/laconic-console
|
laconic-so --stack fixturenet-laconic-loaded setup-repositories --include git.vdb.to/cerc-io/laconicd,git.vdb.to/cerc-io/registry-sdk,git.vdb.to/cerc-io/laconic-registry-cli,git.vdb.to/cerc-io/laconic-console
|
||||||
|
|
||||||
laconic-so --stack fixturenet-laconic-loaded build-containers
|
laconic-so --stack fixturenet-laconic-loaded build-containers
|
||||||
|
|
||||||
|
|||||||
@@ -2,4 +2,50 @@
|
|||||||
|
|
||||||
The Package Registry Stack supports a build environment that requires a package registry (initially for NPM packages only).
|
The Package Registry Stack supports a build environment that requires a package registry (initially for NPM packages only).
|
||||||
|
|
||||||
Setup instructions can be found [here](../build-support/README.md).
|
## Setup
|
||||||
|
|
||||||
|
* Setup required repos and build containers:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
laconic-so --stack package-registry setup-repositories
|
||||||
|
laconic-so --stack package-registry build-containers
|
||||||
|
```
|
||||||
|
|
||||||
|
* Create a deployment:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
laconic-so --stack package-registry deploy init --output package-registry-spec.yml
|
||||||
|
# Update port mapping in the laconic-loaded.spec file to resolve port conflicts on host if any
|
||||||
|
|
||||||
|
laconic-so --stack package-registry deploy create --deployment-dir package-registry-deployment --spec-file package-registry-spec.yml
|
||||||
|
```
|
||||||
|
|
||||||
|
* Start the deployment:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
laconic-so deployment --dir package-registry-deployment start
|
||||||
|
```
|
||||||
|
|
||||||
|
* The local gitea registry can now be accessed at <http://localhost:3000> (the username and password can be taken from the deployment logs)
|
||||||
|
|
||||||
|
* Configure the hostname `gitea.local`:
|
||||||
|
|
||||||
|
Update `/etc/hosts`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo nano /etc/hosts
|
||||||
|
|
||||||
|
# Add the following line
|
||||||
|
127.0.0.1 gitea.local
|
||||||
|
```
|
||||||
|
|
||||||
|
Check resolution:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ping gitea.local
|
||||||
|
|
||||||
|
PING gitea.local (127.0.0.1) 56(84) bytes of data.
|
||||||
|
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.147 ms
|
||||||
|
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.033 ms
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
from stack_orchestrator.util import get_yaml
|
from stack_orchestrator.util import get_yaml
|
||||||
from stack_orchestrator.deploy.deploy_types import DeployCommandContext
|
from stack_orchestrator.deploy.deploy_types import DeployCommandContext
|
||||||
|
from stack_orchestrator.deploy.deployment_context import DeploymentContext
|
||||||
from stack_orchestrator.deploy.stack_state import State
|
from stack_orchestrator.deploy.stack_state import State
|
||||||
from stack_orchestrator.deploy.deploy_util import VolumeMapping, run_container_command
|
from stack_orchestrator.deploy.deploy_util import VolumeMapping, run_container_command
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@@ -24,16 +25,20 @@ default_spec_file_content = """config:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
# Output a known string to a know file in the bind mounted directory ./container-output-dir
|
# Output a known string to a know file in the bind mounted directory
|
||||||
|
# ./container-output-dir
|
||||||
# for test purposes -- test checks that the file was written.
|
# for test purposes -- test checks that the file was written.
|
||||||
def setup(command_context: DeployCommandContext, parameters, extra_args):
|
def setup(command_context: DeployCommandContext, parameters, extra_args):
|
||||||
host_directory = "./container-output-dir"
|
host_directory = "./container-output-dir"
|
||||||
host_directory_absolute = Path(extra_args[0]).absolute().joinpath(host_directory)
|
host_directory_absolute = Path(extra_args[0]).absolute().joinpath(host_directory)
|
||||||
host_directory_absolute.mkdir(parents=True, exist_ok=True)
|
host_directory_absolute.mkdir(parents=True, exist_ok=True)
|
||||||
mounts = [
|
mounts = [VolumeMapping(str(host_directory_absolute), "/data")]
|
||||||
VolumeMapping(host_directory_absolute, "/data")
|
output, status = run_container_command(
|
||||||
]
|
command_context,
|
||||||
output, status = run_container_command(command_context, "test", "echo output-data > /data/output-file && echo success", mounts)
|
"test",
|
||||||
|
"echo output-data > /data/output-file && echo success",
|
||||||
|
mounts,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def init(command_context: DeployCommandContext):
|
def init(command_context: DeployCommandContext):
|
||||||
@@ -41,10 +46,10 @@ def init(command_context: DeployCommandContext):
|
|||||||
return yaml.load(default_spec_file_content)
|
return yaml.load(default_spec_file_content)
|
||||||
|
|
||||||
|
|
||||||
def create(command_context: DeployCommandContext, extra_args):
|
def create(deployment_context: DeploymentContext, extra_args):
|
||||||
data = "create-command-output-data"
|
data = "create-command-output-data"
|
||||||
output_file_path = command_context.deployment_dir.joinpath("create-file")
|
output_file_path = deployment_context.deployment_dir.joinpath("create-file")
|
||||||
with open(output_file_path, 'w+') as output_file:
|
with open(output_file_path, "w+") as output_file:
|
||||||
output_file.write(data)
|
output_file.write(data)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ version: "1.0"
|
|||||||
name: test
|
name: test
|
||||||
description: "A test stack"
|
description: "A test stack"
|
||||||
repos:
|
repos:
|
||||||
- git.vdb.to/cerc-io/laconicd
|
|
||||||
- git.vdb.to/cerc-io/test-project@test-branch
|
- git.vdb.to/cerc-io/test-project@test-branch
|
||||||
containers:
|
containers:
|
||||||
- cerc/test-container
|
- cerc/test-container
|
||||||
|
|||||||
@@ -14,8 +14,13 @@
|
|||||||
# along with this program. If not, see <http:#www.gnu.org/licenses/>.
|
# along with this program. If not, see <http:#www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from typing import Optional
|
||||||
from python_on_whales import DockerClient, DockerException
|
from python_on_whales import DockerClient, DockerException
|
||||||
from stack_orchestrator.deploy.deployer import Deployer, DeployerException, DeployerConfigGenerator
|
from stack_orchestrator.deploy.deployer import (
|
||||||
|
Deployer,
|
||||||
|
DeployerException,
|
||||||
|
DeployerConfigGenerator,
|
||||||
|
)
|
||||||
from stack_orchestrator.deploy.deployment_context import DeploymentContext
|
from stack_orchestrator.deploy.deployment_context import DeploymentContext
|
||||||
from stack_orchestrator.opts import opts
|
from stack_orchestrator.opts import opts
|
||||||
|
|
||||||
@@ -24,19 +29,33 @@ class DockerDeployer(Deployer):
|
|||||||
name: str = "compose"
|
name: str = "compose"
|
||||||
type: str
|
type: str
|
||||||
|
|
||||||
def __init__(self, type, deployment_context: DeploymentContext, compose_files, compose_project_name, compose_env_file) -> None:
|
def __init__(
|
||||||
self.docker = DockerClient(compose_files=compose_files, compose_project_name=compose_project_name,
|
self,
|
||||||
compose_env_file=compose_env_file)
|
type: str,
|
||||||
|
deployment_context: Optional[DeploymentContext],
|
||||||
|
compose_files: list,
|
||||||
|
compose_project_name: Optional[str],
|
||||||
|
compose_env_file: Optional[str],
|
||||||
|
) -> None:
|
||||||
|
self.docker = DockerClient(
|
||||||
|
compose_files=compose_files,
|
||||||
|
compose_project_name=compose_project_name,
|
||||||
|
compose_env_file=compose_env_file,
|
||||||
|
)
|
||||||
self.type = type
|
self.type = type
|
||||||
|
# Store these for later use in run_job
|
||||||
|
self.compose_files = compose_files
|
||||||
|
self.compose_project_name = compose_project_name
|
||||||
|
self.compose_env_file = compose_env_file
|
||||||
|
|
||||||
def up(self, detach, services):
|
def up(self, detach, skip_cluster_management, services):
|
||||||
if not opts.o.dry_run:
|
if not opts.o.dry_run:
|
||||||
try:
|
try:
|
||||||
return self.docker.compose.up(detach=detach, services=services)
|
return self.docker.compose.up(detach=detach, services=services)
|
||||||
except DockerException as e:
|
except DockerException as e:
|
||||||
raise DeployerException(e)
|
raise DeployerException(e)
|
||||||
|
|
||||||
def down(self, timeout, volumes):
|
def down(self, timeout, volumes, skip_cluster_management):
|
||||||
if not opts.o.dry_run:
|
if not opts.o.dry_run:
|
||||||
try:
|
try:
|
||||||
return self.docker.compose.down(timeout=timeout, volumes=volumes)
|
return self.docker.compose.down(timeout=timeout, volumes=volumes)
|
||||||
@@ -68,35 +87,98 @@ class DockerDeployer(Deployer):
|
|||||||
def port(self, service, private_port):
|
def port(self, service, private_port):
|
||||||
if not opts.o.dry_run:
|
if not opts.o.dry_run:
|
||||||
try:
|
try:
|
||||||
return self.docker.compose.port(service=service, private_port=private_port)
|
return self.docker.compose.port(
|
||||||
|
service=service, private_port=private_port
|
||||||
|
)
|
||||||
except DockerException as e:
|
except DockerException as e:
|
||||||
raise DeployerException(e)
|
raise DeployerException(e)
|
||||||
|
|
||||||
def execute(self, service, command, tty, envs):
|
def execute(self, service, command, tty, envs):
|
||||||
if not opts.o.dry_run:
|
if not opts.o.dry_run:
|
||||||
try:
|
try:
|
||||||
return self.docker.compose.execute(service=service, command=command, tty=tty, envs=envs)
|
return self.docker.compose.execute(
|
||||||
|
service=service, command=command, tty=tty, envs=envs
|
||||||
|
)
|
||||||
except DockerException as e:
|
except DockerException as e:
|
||||||
raise DeployerException(e)
|
raise DeployerException(e)
|
||||||
|
|
||||||
def logs(self, services, tail, follow, stream):
|
def logs(self, services, tail, follow, stream):
|
||||||
if not opts.o.dry_run:
|
if not opts.o.dry_run:
|
||||||
try:
|
try:
|
||||||
return self.docker.compose.logs(services=services, tail=tail, follow=follow, stream=stream)
|
return self.docker.compose.logs(
|
||||||
|
services=services, tail=tail, follow=follow, stream=stream
|
||||||
|
)
|
||||||
except DockerException as e:
|
except DockerException as e:
|
||||||
raise DeployerException(e)
|
raise DeployerException(e)
|
||||||
|
|
||||||
def run(self, image: str, command=None, user=None, volumes=None, entrypoint=None, env={}, ports=[], detach=False):
|
def run(
|
||||||
|
self,
|
||||||
|
image: str,
|
||||||
|
command=None,
|
||||||
|
user=None,
|
||||||
|
volumes=None,
|
||||||
|
entrypoint=None,
|
||||||
|
env={},
|
||||||
|
ports=[],
|
||||||
|
detach=False,
|
||||||
|
):
|
||||||
if not opts.o.dry_run:
|
if not opts.o.dry_run:
|
||||||
try:
|
try:
|
||||||
return self.docker.run(image=image, command=command, user=user, volumes=volumes,
|
return self.docker.run(
|
||||||
entrypoint=entrypoint, envs=env, detach=detach, publish=ports, publish_all=len(ports) == 0)
|
image=image,
|
||||||
|
command=command if command else [],
|
||||||
|
user=user,
|
||||||
|
volumes=volumes,
|
||||||
|
entrypoint=entrypoint,
|
||||||
|
envs=env,
|
||||||
|
detach=detach,
|
||||||
|
publish=ports,
|
||||||
|
publish_all=len(ports) == 0,
|
||||||
|
)
|
||||||
|
except DockerException as e:
|
||||||
|
raise DeployerException(e)
|
||||||
|
|
||||||
|
def run_job(self, job_name: str, release_name: Optional[str] = None):
|
||||||
|
# release_name is ignored for Docker deployments (only used for K8s/Helm)
|
||||||
|
if not opts.o.dry_run:
|
||||||
|
try:
|
||||||
|
# Find job compose file in compose-jobs directory
|
||||||
|
# The deployment should have compose-jobs/docker-compose-<job_name>.yml
|
||||||
|
if not self.compose_files:
|
||||||
|
raise DeployerException("No compose files configured")
|
||||||
|
|
||||||
|
# Deployment directory is parent of compose directory
|
||||||
|
compose_dir = Path(self.compose_files[0]).parent
|
||||||
|
deployment_dir = compose_dir.parent
|
||||||
|
job_compose_file = (
|
||||||
|
deployment_dir / "compose-jobs" / f"docker-compose-{job_name}.yml"
|
||||||
|
)
|
||||||
|
|
||||||
|
if not job_compose_file.exists():
|
||||||
|
raise DeployerException(
|
||||||
|
f"Job compose file not found: {job_compose_file}"
|
||||||
|
)
|
||||||
|
|
||||||
|
if opts.o.verbose:
|
||||||
|
print(f"Running job from: {job_compose_file}")
|
||||||
|
|
||||||
|
# Create a DockerClient for the job compose file with same
|
||||||
|
# project name and env file
|
||||||
|
# This allows the job to access volumes from the main deployment
|
||||||
|
job_docker = DockerClient(
|
||||||
|
compose_files=[job_compose_file],
|
||||||
|
compose_project_name=self.compose_project_name,
|
||||||
|
compose_env_file=self.compose_env_file,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Run the job with --rm flag to remove container after completion
|
||||||
|
return job_docker.compose.run(service=job_name, remove=True, tty=True)
|
||||||
|
|
||||||
except DockerException as e:
|
except DockerException as e:
|
||||||
raise DeployerException(e)
|
raise DeployerException(e)
|
||||||
|
|
||||||
|
|
||||||
class DockerDeployerConfigGenerator(DeployerConfigGenerator):
|
class DockerDeployerConfigGenerator(DeployerConfigGenerator):
|
||||||
|
|
||||||
def __init__(self, type: str) -> None:
|
def __init__(self, type: str) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from importlib import resources
|
from importlib import resources
|
||||||
|
from typing import Optional
|
||||||
import subprocess
|
import subprocess
|
||||||
import click
|
import click
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@@ -35,27 +36,36 @@ from stack_orchestrator.util import (
|
|||||||
stack_is_in_deployment,
|
stack_is_in_deployment,
|
||||||
resolve_compose_file,
|
resolve_compose_file,
|
||||||
)
|
)
|
||||||
from stack_orchestrator.deploy.deployer import Deployer, DeployerException
|
from stack_orchestrator.deploy.deployer import DeployerException
|
||||||
from stack_orchestrator.deploy.deployer_factory import getDeployer
|
from stack_orchestrator.deploy.deployer_factory import getDeployer
|
||||||
|
from stack_orchestrator.deploy.compose.deploy_docker import DockerDeployer
|
||||||
from stack_orchestrator.deploy.deploy_types import ClusterContext, DeployCommandContext
|
from stack_orchestrator.deploy.deploy_types import ClusterContext, DeployCommandContext
|
||||||
from stack_orchestrator.deploy.deployment_context import DeploymentContext
|
from stack_orchestrator.deploy.deployment_context import DeploymentContext
|
||||||
from stack_orchestrator.deploy.deployment_create import create as deployment_create
|
from stack_orchestrator.deploy.deployment_create import create as deployment_create
|
||||||
from stack_orchestrator.deploy.deployment_create import init as deployment_init
|
from stack_orchestrator.deploy.deployment_create import init as deployment_init
|
||||||
from stack_orchestrator.deploy.deployment_create import setup as deployment_setup
|
from stack_orchestrator.deploy.deployment_create import setup as deployment_setup
|
||||||
|
from stack_orchestrator.deploy.k8s import k8s_command
|
||||||
|
|
||||||
|
|
||||||
@click.group()
|
@click.group()
|
||||||
@click.option("--include", help="only start these components")
|
@click.option("--include", help="only start these components")
|
||||||
@click.option("--exclude", help="don\'t start these components")
|
@click.option("--exclude", help="don't start these components")
|
||||||
@click.option("--env-file", help="env file to be used")
|
@click.option("--env-file", help="env file to be used")
|
||||||
@click.option("--cluster", help="specify a non-default cluster name")
|
@click.option("--cluster", help="specify a non-default cluster name")
|
||||||
@click.option("--deploy-to", help="cluster system to deploy to (compose or k8s or k8s-kind)")
|
@click.option(
|
||||||
|
"--deploy-to", help="cluster system to deploy to (compose or k8s or k8s-kind)"
|
||||||
|
)
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def command(ctx, include, exclude, env_file, cluster, deploy_to):
|
def command(ctx, include, exclude, env_file, cluster, deploy_to):
|
||||||
'''deploy a stack'''
|
"""deploy a stack"""
|
||||||
|
|
||||||
# Although in theory for some subcommands (e.g. deploy create) the stack can be inferred,
|
# k8s subcommand doesn't require a stack
|
||||||
# Click doesn't allow us to know that here, so we make providing the stack mandatory
|
if ctx.invoked_subcommand == "k8s":
|
||||||
|
return
|
||||||
|
|
||||||
|
# Although in theory for some subcommands (e.g. deploy create) the stack
|
||||||
|
# can be inferred, Click doesn't allow us to know that here, so we make
|
||||||
|
# providing the stack mandatory
|
||||||
stack = global_options2(ctx).stack
|
stack = global_options2(ctx).stack
|
||||||
if not stack:
|
if not stack:
|
||||||
print("Error: --stack option is required")
|
print("Error: --stack option is required")
|
||||||
@@ -68,30 +78,65 @@ def command(ctx, include, exclude, env_file, cluster, deploy_to):
|
|||||||
deploy_to = "compose"
|
deploy_to = "compose"
|
||||||
|
|
||||||
stack = get_stack_path(stack)
|
stack = get_stack_path(stack)
|
||||||
ctx.obj = create_deploy_context(global_options2(ctx), None, stack, include, exclude, cluster, env_file, deploy_to)
|
ctx.obj = create_deploy_context(
|
||||||
# Subcommand is executed now, by the magic of click
|
global_options2(ctx),
|
||||||
|
None,
|
||||||
|
|
||||||
def create_deploy_context(
|
|
||||||
global_context,
|
|
||||||
deployment_context: DeploymentContext,
|
|
||||||
stack,
|
stack,
|
||||||
include,
|
include,
|
||||||
exclude,
|
exclude,
|
||||||
cluster,
|
cluster,
|
||||||
env_file,
|
env_file,
|
||||||
deploy_to) -> DeployCommandContext:
|
deploy_to,
|
||||||
|
)
|
||||||
|
# Subcommand is executed now, by the magic of click
|
||||||
|
|
||||||
|
|
||||||
|
def create_deploy_context(
|
||||||
|
global_context,
|
||||||
|
deployment_context: Optional[DeploymentContext],
|
||||||
|
stack,
|
||||||
|
include,
|
||||||
|
exclude,
|
||||||
|
cluster,
|
||||||
|
env_file,
|
||||||
|
deploy_to,
|
||||||
|
) -> DeployCommandContext:
|
||||||
# Extract the cluster name from the deployment, if we have one
|
# Extract the cluster name from the deployment, if we have one
|
||||||
if deployment_context and cluster is None:
|
if deployment_context and cluster is None:
|
||||||
cluster = deployment_context.get_cluster_id()
|
cluster = deployment_context.get_cluster_id()
|
||||||
cluster_context = _make_cluster_context(global_context, stack, include, exclude, cluster, env_file)
|
|
||||||
deployer = getDeployer(deploy_to, deployment_context, compose_files=cluster_context.compose_files,
|
# Check if this is a helm chart deployment (has chart/ but no compose/)
|
||||||
compose_project_name=cluster_context.cluster,
|
# TODO: Add a new deployment type for helm chart deployments
|
||||||
compose_env_file=cluster_context.env_file)
|
# To avoid relying on chart existence in such cases
|
||||||
|
is_helm_chart_deployment = False
|
||||||
|
if deployment_context:
|
||||||
|
chart_dir = deployment_context.deployment_dir / "chart"
|
||||||
|
compose_dir = deployment_context.deployment_dir / "compose"
|
||||||
|
is_helm_chart_deployment = chart_dir.exists() and not compose_dir.exists()
|
||||||
|
|
||||||
|
# For helm chart deployments, skip compose file loading
|
||||||
|
if is_helm_chart_deployment:
|
||||||
|
cluster_context = ClusterContext(
|
||||||
|
global_context, cluster, [], [], [], None, env_file
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
cluster_context = _make_cluster_context(
|
||||||
|
global_context, stack, include, exclude, cluster, env_file
|
||||||
|
)
|
||||||
|
|
||||||
|
deployer = getDeployer(
|
||||||
|
deploy_to,
|
||||||
|
deployment_context,
|
||||||
|
compose_files=cluster_context.compose_files,
|
||||||
|
compose_project_name=cluster_context.cluster,
|
||||||
|
compose_env_file=cluster_context.env_file,
|
||||||
|
)
|
||||||
return DeployCommandContext(stack, cluster_context, deployer)
|
return DeployCommandContext(stack, cluster_context, deployer)
|
||||||
|
|
||||||
|
|
||||||
def up_operation(ctx, services_list, stay_attached=False):
|
def up_operation(
|
||||||
|
ctx, services_list, stay_attached=False, skip_cluster_management=False
|
||||||
|
):
|
||||||
global_context = ctx.parent.parent.obj
|
global_context = ctx.parent.parent.obj
|
||||||
deploy_context = ctx.obj
|
deploy_context = ctx.obj
|
||||||
cluster_context = deploy_context.cluster_context
|
cluster_context = deploy_context.cluster_context
|
||||||
@@ -99,21 +144,38 @@ def up_operation(ctx, services_list, stay_attached=False):
|
|||||||
for attr, value in container_exec_env.items():
|
for attr, value in container_exec_env.items():
|
||||||
os.environ[attr] = value
|
os.environ[attr] = value
|
||||||
if global_context.verbose:
|
if global_context.verbose:
|
||||||
print(f"Running compose up with container_exec_env: {container_exec_env}, extra_args: {services_list}")
|
print(
|
||||||
|
f"Running compose up with container_exec_env: {container_exec_env}, "
|
||||||
|
f"extra_args: {services_list}"
|
||||||
|
)
|
||||||
for pre_start_command in cluster_context.pre_start_commands:
|
for pre_start_command in cluster_context.pre_start_commands:
|
||||||
_run_command(global_context, cluster_context.cluster, pre_start_command)
|
_run_command(global_context, cluster_context.cluster, pre_start_command)
|
||||||
deploy_context.deployer.up(detach=not stay_attached, services=services_list)
|
deploy_context.deployer.up(
|
||||||
|
detach=not stay_attached,
|
||||||
|
skip_cluster_management=skip_cluster_management,
|
||||||
|
services=services_list,
|
||||||
|
)
|
||||||
for post_start_command in cluster_context.post_start_commands:
|
for post_start_command in cluster_context.post_start_commands:
|
||||||
_run_command(global_context, cluster_context.cluster, post_start_command)
|
_run_command(global_context, cluster_context.cluster, post_start_command)
|
||||||
_orchestrate_cluster_config(global_context, cluster_context.config, deploy_context.deployer, container_exec_env)
|
_orchestrate_cluster_config(
|
||||||
|
global_context,
|
||||||
|
cluster_context.config,
|
||||||
|
deploy_context.deployer,
|
||||||
|
container_exec_env,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def down_operation(ctx, delete_volumes, extra_args_list):
|
def down_operation(ctx, delete_volumes, extra_args_list, skip_cluster_management=False):
|
||||||
timeout_arg = None
|
timeout_arg = None
|
||||||
if extra_args_list:
|
if extra_args_list:
|
||||||
timeout_arg = extra_args_list[0]
|
timeout_arg = extra_args_list[0]
|
||||||
# Specify shutdown timeout (default 10s) to give services enough time to shutdown gracefully
|
# Specify shutdown timeout (default 10s) to give services enough time to
|
||||||
ctx.obj.deployer.down(timeout=timeout_arg, volumes=delete_volumes)
|
# shutdown gracefully
|
||||||
|
ctx.obj.deployer.down(
|
||||||
|
timeout=timeout_arg,
|
||||||
|
volumes=delete_volumes,
|
||||||
|
skip_cluster_management=skip_cluster_management,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def status_operation(ctx):
|
def status_operation(ctx):
|
||||||
@@ -140,7 +202,11 @@ def ps_operation(ctx):
|
|||||||
if mapping is None:
|
if mapping is None:
|
||||||
print(f"{port_mapping}", end="")
|
print(f"{port_mapping}", end="")
|
||||||
else:
|
else:
|
||||||
print(f"{mapping[0]['HostIp']}:{mapping[0]['HostPort']}->{port_mapping}", end="")
|
print(
|
||||||
|
f"{mapping[0]['HostIp']}:{mapping[0]['HostPort']}"
|
||||||
|
f"->{port_mapping}",
|
||||||
|
end="",
|
||||||
|
)
|
||||||
comma = ", "
|
comma = ", "
|
||||||
print()
|
print()
|
||||||
else:
|
else:
|
||||||
@@ -175,7 +241,9 @@ def exec_operation(ctx, extra_args):
|
|||||||
if global_context.verbose:
|
if global_context.verbose:
|
||||||
print(f"Running compose exec {service_name} {command_to_exec}")
|
print(f"Running compose exec {service_name} {command_to_exec}")
|
||||||
try:
|
try:
|
||||||
ctx.obj.deployer.execute(service_name, command_to_exec, envs=container_exec_env, tty=True)
|
ctx.obj.deployer.execute(
|
||||||
|
service_name, command_to_exec, envs=container_exec_env, tty=True
|
||||||
|
)
|
||||||
except DeployerException:
|
except DeployerException:
|
||||||
print("container command returned error exit status")
|
print("container command returned error exit status")
|
||||||
|
|
||||||
@@ -183,13 +251,26 @@ def exec_operation(ctx, extra_args):
|
|||||||
def logs_operation(ctx, tail: int, follow: bool, extra_args: str):
|
def logs_operation(ctx, tail: int, follow: bool, extra_args: str):
|
||||||
extra_args_list = list(extra_args) or None
|
extra_args_list = list(extra_args) or None
|
||||||
services_list = extra_args_list if extra_args_list is not None else []
|
services_list = extra_args_list if extra_args_list is not None else []
|
||||||
logs_stream = ctx.obj.deployer.logs(services=services_list, tail=tail, follow=follow, stream=True)
|
logs_stream = ctx.obj.deployer.logs(
|
||||||
|
services=services_list, tail=tail, follow=follow, stream=True
|
||||||
|
)
|
||||||
for stream_type, stream_content in logs_stream:
|
for stream_type, stream_content in logs_stream:
|
||||||
print(stream_content.decode("utf-8"), end="")
|
print(stream_content.decode("utf-8"), end="")
|
||||||
|
|
||||||
|
|
||||||
|
def run_job_operation(ctx, job_name: str, helm_release: Optional[str] = None):
|
||||||
|
global_context = ctx.parent.parent.obj
|
||||||
|
if not global_context.dry_run:
|
||||||
|
print(f"Running job: {job_name}")
|
||||||
|
try:
|
||||||
|
ctx.obj.deployer.run_job(job_name, helm_release)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error running job {job_name}: {e}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
@command.command()
|
@command.command()
|
||||||
@click.argument('extra_args', nargs=-1) # help: command: up <service1> <service2>
|
@click.argument("extra_args", nargs=-1) # help: command: up <service1> <service2>
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def up(ctx, extra_args):
|
def up(ctx, extra_args):
|
||||||
extra_args_list = list(extra_args) or None
|
extra_args_list = list(extra_args) or None
|
||||||
@@ -197,8 +278,10 @@ def up(ctx, extra_args):
|
|||||||
|
|
||||||
|
|
||||||
@command.command()
|
@command.command()
|
||||||
@click.option("--delete-volumes/--preserve-volumes", default=False, help="delete data volumes")
|
@click.option(
|
||||||
@click.argument('extra_args', nargs=-1) # help: command: down<service1> <service2>
|
"--delete-volumes/--preserve-volumes", default=False, help="delete data volumes"
|
||||||
|
)
|
||||||
|
@click.argument("extra_args", nargs=-1) # help: command: down<service1> <service2>
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def down(ctx, delete_volumes, extra_args):
|
def down(ctx, delete_volumes, extra_args):
|
||||||
extra_args_list = list(extra_args) or None
|
extra_args_list = list(extra_args) or None
|
||||||
@@ -212,14 +295,14 @@ def ps(ctx):
|
|||||||
|
|
||||||
|
|
||||||
@command.command()
|
@command.command()
|
||||||
@click.argument('extra_args', nargs=-1) # help: command: port <service1> <service2>
|
@click.argument("extra_args", nargs=-1) # help: command: port <service1> <service2>
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def port(ctx, extra_args):
|
def port(ctx, extra_args):
|
||||||
port_operation(ctx, extra_args)
|
port_operation(ctx, extra_args)
|
||||||
|
|
||||||
|
|
||||||
@command.command()
|
@command.command()
|
||||||
@click.argument('extra_args', nargs=-1) # help: command: exec <service> <command>
|
@click.argument("extra_args", nargs=-1) # help: command: exec <service> <command>
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def exec(ctx, extra_args):
|
def exec(ctx, extra_args):
|
||||||
exec_operation(ctx, extra_args)
|
exec_operation(ctx, extra_args)
|
||||||
@@ -228,44 +311,49 @@ def exec(ctx, extra_args):
|
|||||||
@command.command()
|
@command.command()
|
||||||
@click.option("--tail", "-n", default=None, help="number of lines to display")
|
@click.option("--tail", "-n", default=None, help="number of lines to display")
|
||||||
@click.option("--follow", "-f", is_flag=True, default=False, help="follow log output")
|
@click.option("--follow", "-f", is_flag=True, default=False, help="follow log output")
|
||||||
@click.argument('extra_args', nargs=-1) # help: command: logs <service1> <service2>
|
@click.argument("extra_args", nargs=-1) # help: command: logs <service1> <service2>
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def logs(ctx, tail, follow, extra_args):
|
def logs(ctx, tail, follow, extra_args):
|
||||||
logs_operation(ctx, tail, follow, extra_args)
|
logs_operation(ctx, tail, follow, extra_args)
|
||||||
|
|
||||||
|
|
||||||
def get_stack_status(ctx, stack):
|
def get_stack_status(ctx, stack):
|
||||||
|
|
||||||
ctx_copy = copy.copy(ctx)
|
ctx_copy = copy.copy(ctx)
|
||||||
ctx_copy.stack = stack
|
ctx_copy.stack = stack
|
||||||
|
|
||||||
cluster_context = _make_cluster_context(ctx_copy, stack, None, None, None, None)
|
cluster_context = _make_cluster_context(ctx_copy, stack, None, None, None, None)
|
||||||
deployer = Deployer(compose_files=cluster_context.compose_files, compose_project_name=cluster_context.cluster)
|
deployer = DockerDeployer(
|
||||||
|
type="compose",
|
||||||
|
deployment_context=None,
|
||||||
|
compose_files=cluster_context.compose_files,
|
||||||
|
compose_project_name=cluster_context.cluster,
|
||||||
|
compose_env_file=cluster_context.env_file,
|
||||||
|
)
|
||||||
# TODO: refactor to avoid duplicating this code above
|
# TODO: refactor to avoid duplicating this code above
|
||||||
if ctx.verbose:
|
if ctx.verbose:
|
||||||
print("Running compose ps")
|
print("Running compose ps")
|
||||||
container_list = deployer.ps()
|
container_list = deployer.ps()
|
||||||
if len(container_list) > 0:
|
if container_list is None or len(container_list) == 0:
|
||||||
if ctx.debug:
|
|
||||||
print(f"Container list from compose ps: {container_list}")
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
if ctx.debug:
|
if ctx.debug:
|
||||||
print("No containers found from compose ps")
|
print("No containers found from compose ps")
|
||||||
False
|
return False
|
||||||
|
if ctx.debug:
|
||||||
|
print(f"Container list from compose ps: {container_list}")
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def _make_runtime_env(ctx):
|
def _make_runtime_env(ctx):
|
||||||
container_exec_env = {
|
container_exec_env = {
|
||||||
"CERC_HOST_UID": f"{os.getuid()}",
|
"CERC_HOST_UID": f"{os.getuid()}",
|
||||||
"CERC_HOST_GID": f"{os.getgid()}"
|
"CERC_HOST_GID": f"{os.getgid()}",
|
||||||
}
|
}
|
||||||
container_exec_env.update({"CERC_SCRIPT_DEBUG": "true"} if ctx.debug else {})
|
container_exec_env.update({"CERC_SCRIPT_DEBUG": "true"} if ctx.debug else {})
|
||||||
return container_exec_env
|
return container_exec_env
|
||||||
|
|
||||||
|
|
||||||
def _make_default_cluster_name(deployment, compose_dir, stack, include, exclude):
|
def _make_default_cluster_name(deployment, compose_dir, stack, include, exclude):
|
||||||
# Create default unique, stable cluster name from confile file path and stack name if provided
|
# Create default unique, stable cluster name from confile file path and
|
||||||
|
# stack name if provided
|
||||||
if deployment:
|
if deployment:
|
||||||
path = os.path.realpath(os.path.abspath(compose_dir))
|
path = os.path.realpath(os.path.abspath(compose_dir))
|
||||||
else:
|
else:
|
||||||
@@ -280,7 +368,8 @@ def _make_default_cluster_name(deployment, compose_dir, stack, include, exclude)
|
|||||||
return cluster
|
return cluster
|
||||||
|
|
||||||
|
|
||||||
# stack has to be either PathLike pointing to a stack yml file, or a string with the name of a known stack
|
# stack has to be either PathLike pointing to a stack yml file, or a
|
||||||
|
# string with the name of a known stack
|
||||||
def _make_cluster_context(ctx, stack, include, exclude, cluster, env_file):
|
def _make_cluster_context(ctx, stack, include, exclude, cluster, env_file):
|
||||||
dev_root_path = get_dev_root_path(ctx)
|
dev_root_path = get_dev_root_path(ctx)
|
||||||
|
|
||||||
@@ -289,28 +378,37 @@ def _make_cluster_context(ctx, stack, include, exclude, cluster, env_file):
|
|||||||
if deployment:
|
if deployment:
|
||||||
compose_dir = stack.joinpath("compose")
|
compose_dir = stack.joinpath("compose")
|
||||||
else:
|
else:
|
||||||
# See: https://stackoverflow.com/questions/25389095/python-get-path-of-root-project-structure
|
# See:
|
||||||
compose_dir = Path(__file__).absolute().parent.parent.joinpath("data", "compose")
|
# https://stackoverflow.com/questions/25389095/python-get-path-of-root-project-structure
|
||||||
|
compose_dir = (
|
||||||
|
Path(__file__).absolute().parent.parent.joinpath("data", "compose")
|
||||||
|
)
|
||||||
|
|
||||||
if cluster is None:
|
if cluster is None:
|
||||||
cluster = _make_default_cluster_name(deployment, compose_dir, stack, include, exclude)
|
cluster = _make_default_cluster_name(
|
||||||
|
deployment, compose_dir, stack, include, exclude
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
_make_default_cluster_name(deployment, compose_dir, stack, include, exclude)
|
_make_default_cluster_name(deployment, compose_dir, stack, include, exclude)
|
||||||
|
|
||||||
# See: https://stackoverflow.com/a/20885799/1701505
|
# See: https://stackoverflow.com/a/20885799/1701505
|
||||||
from stack_orchestrator import data
|
from stack_orchestrator import data
|
||||||
|
|
||||||
with resources.open_text(data, "pod-list.txt") as pod_list_file:
|
with resources.open_text(data, "pod-list.txt") as pod_list_file:
|
||||||
all_pods = pod_list_file.read().splitlines()
|
all_pods = pod_list_file.read().splitlines()
|
||||||
|
|
||||||
pods_in_scope = []
|
pods_in_scope = []
|
||||||
|
cluster_config = None
|
||||||
if stack:
|
if stack:
|
||||||
stack_config = get_parsed_stack_config(stack)
|
stack_config = get_parsed_stack_config(stack)
|
||||||
# TODO: syntax check the input here
|
if stack_config is not None:
|
||||||
pods_in_scope = stack_config['pods']
|
# TODO: syntax check the input here
|
||||||
cluster_config = stack_config['config'] if 'config' in stack_config else None
|
pods_in_scope = stack_config["pods"]
|
||||||
|
cluster_config = (
|
||||||
|
stack_config["config"] if "config" in stack_config else None
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
pods_in_scope = all_pods
|
pods_in_scope = all_pods
|
||||||
cluster_config = None
|
|
||||||
|
|
||||||
# Convert all pod definitions to v1.1 format
|
# Convert all pod definitions to v1.1 format
|
||||||
pods_in_scope = _convert_to_new_format(pods_in_scope)
|
pods_in_scope = _convert_to_new_format(pods_in_scope)
|
||||||
@@ -330,29 +428,47 @@ def _make_cluster_context(ctx, stack, include, exclude, cluster, env_file):
|
|||||||
if include_exclude_check(pod_name, include, exclude):
|
if include_exclude_check(pod_name, include, exclude):
|
||||||
if pod_repository is None or pod_repository == "internal":
|
if pod_repository is None or pod_repository == "internal":
|
||||||
if deployment:
|
if deployment:
|
||||||
compose_file_name = os.path.join(compose_dir, f"docker-compose-{pod_path}.yml")
|
compose_file_name = os.path.join(
|
||||||
|
compose_dir, f"docker-compose-{pod_path}.yml"
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
compose_file_name = resolve_compose_file(stack, pod_name)
|
compose_file_name = resolve_compose_file(stack, pod_name)
|
||||||
else:
|
else:
|
||||||
if deployment:
|
if deployment:
|
||||||
compose_file_name = os.path.join(compose_dir, f"docker-compose-{pod_name}.yml")
|
compose_file_name = os.path.join(
|
||||||
|
compose_dir, f"docker-compose-{pod_name}.yml"
|
||||||
|
)
|
||||||
pod_pre_start_command = pod.get("pre_start_command")
|
pod_pre_start_command = pod.get("pre_start_command")
|
||||||
pod_post_start_command = pod.get("post_start_command")
|
pod_post_start_command = pod.get("post_start_command")
|
||||||
script_dir = compose_dir.parent.joinpath("pods", pod_name, "scripts")
|
script_dir = compose_dir.parent.joinpath(
|
||||||
|
"pods", pod_name, "scripts"
|
||||||
|
)
|
||||||
if pod_pre_start_command is not None:
|
if pod_pre_start_command is not None:
|
||||||
pre_start_commands.append(os.path.join(script_dir, pod_pre_start_command))
|
pre_start_commands.append(
|
||||||
|
os.path.join(script_dir, pod_pre_start_command)
|
||||||
|
)
|
||||||
if pod_post_start_command is not None:
|
if pod_post_start_command is not None:
|
||||||
post_start_commands.append(os.path.join(script_dir, pod_post_start_command))
|
post_start_commands.append(
|
||||||
|
os.path.join(script_dir, pod_post_start_command)
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
# TODO: fix this code for external stack with scripts
|
# TODO: fix this code for external stack with scripts
|
||||||
pod_root_dir = os.path.join(dev_root_path, pod_repository.split("/")[-1], pod["path"])
|
pod_root_dir = os.path.join(
|
||||||
compose_file_name = os.path.join(pod_root_dir, f"docker-compose-{pod_name}.yml")
|
dev_root_path, pod_repository.split("/")[-1], pod["path"]
|
||||||
|
)
|
||||||
|
compose_file_name = os.path.join(
|
||||||
|
pod_root_dir, f"docker-compose-{pod_name}.yml"
|
||||||
|
)
|
||||||
pod_pre_start_command = pod.get("pre_start_command")
|
pod_pre_start_command = pod.get("pre_start_command")
|
||||||
pod_post_start_command = pod.get("post_start_command")
|
pod_post_start_command = pod.get("post_start_command")
|
||||||
if pod_pre_start_command is not None:
|
if pod_pre_start_command is not None:
|
||||||
pre_start_commands.append(os.path.join(pod_root_dir, pod_pre_start_command))
|
pre_start_commands.append(
|
||||||
|
os.path.join(pod_root_dir, pod_pre_start_command)
|
||||||
|
)
|
||||||
if pod_post_start_command is not None:
|
if pod_post_start_command is not None:
|
||||||
post_start_commands.append(os.path.join(pod_root_dir, pod_post_start_command))
|
post_start_commands.append(
|
||||||
|
os.path.join(pod_root_dir, pod_post_start_command)
|
||||||
|
)
|
||||||
compose_files.append(compose_file_name)
|
compose_files.append(compose_file_name)
|
||||||
else:
|
else:
|
||||||
if ctx.verbose:
|
if ctx.verbose:
|
||||||
@@ -361,7 +477,15 @@ def _make_cluster_context(ctx, stack, include, exclude, cluster, env_file):
|
|||||||
if ctx.verbose:
|
if ctx.verbose:
|
||||||
print(f"files: {compose_files}")
|
print(f"files: {compose_files}")
|
||||||
|
|
||||||
return ClusterContext(ctx, cluster, compose_files, pre_start_commands, post_start_commands, cluster_config, env_file)
|
return ClusterContext(
|
||||||
|
ctx,
|
||||||
|
cluster,
|
||||||
|
compose_files,
|
||||||
|
pre_start_commands,
|
||||||
|
post_start_commands,
|
||||||
|
cluster_config,
|
||||||
|
env_file,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def _convert_to_new_format(old_pod_array):
|
def _convert_to_new_format(old_pod_array):
|
||||||
@@ -370,11 +494,7 @@ def _convert_to_new_format(old_pod_array):
|
|||||||
if isinstance(old_pod, dict):
|
if isinstance(old_pod, dict):
|
||||||
new_pod_array.append(old_pod)
|
new_pod_array.append(old_pod)
|
||||||
else:
|
else:
|
||||||
new_pod = {
|
new_pod = {"name": old_pod, "repository": "internal", "path": old_pod}
|
||||||
"name": old_pod,
|
|
||||||
"repository": "internal",
|
|
||||||
"path": old_pod
|
|
||||||
}
|
|
||||||
new_pod_array.append(new_pod)
|
new_pod_array.append(new_pod)
|
||||||
return new_pod_array
|
return new_pod_array
|
||||||
|
|
||||||
@@ -388,14 +508,15 @@ def _run_command(ctx, cluster_name, command):
|
|||||||
command_env["CERC_SO_COMPOSE_PROJECT"] = cluster_name
|
command_env["CERC_SO_COMPOSE_PROJECT"] = cluster_name
|
||||||
if ctx.debug:
|
if ctx.debug:
|
||||||
command_env["CERC_SCRIPT_DEBUG"] = "true"
|
command_env["CERC_SCRIPT_DEBUG"] = "true"
|
||||||
command_result = subprocess.run(command_file, shell=True, env=command_env, cwd=command_dir)
|
command_result = subprocess.run(
|
||||||
|
command_file, shell=True, env=command_env, cwd=command_dir
|
||||||
|
)
|
||||||
if command_result.returncode != 0:
|
if command_result.returncode != 0:
|
||||||
print(f"FATAL Error running command: {command}")
|
print(f"FATAL Error running command: {command}")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def _orchestrate_cluster_config(ctx, cluster_config, deployer, container_exec_env):
|
def _orchestrate_cluster_config(ctx, cluster_config, deployer, container_exec_env):
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ConfigDirective:
|
class ConfigDirective:
|
||||||
source_container: str
|
source_container: str
|
||||||
@@ -413,24 +534,32 @@ def _orchestrate_cluster_config(ctx, cluster_config, deployer, container_exec_en
|
|||||||
container_config[directive].split(".")[0],
|
container_config[directive].split(".")[0],
|
||||||
container_config[directive].split(".")[1],
|
container_config[directive].split(".")[1],
|
||||||
container,
|
container,
|
||||||
directive
|
directive,
|
||||||
)
|
)
|
||||||
if ctx.verbose:
|
if ctx.verbose:
|
||||||
print(f"Setting {pd.destination_container}.{pd.destination_variable}"
|
print(
|
||||||
f" = {pd.source_container}.{pd.source_variable}")
|
f"Setting {pd.destination_container}.{pd.destination_variable}"
|
||||||
|
f" = {pd.source_container}.{pd.source_variable}"
|
||||||
|
)
|
||||||
# TODO: add a timeout
|
# TODO: add a timeout
|
||||||
waiting_for_data = True
|
waiting_for_data = True
|
||||||
destination_output = "*** no output received yet ***"
|
destination_output = "*** no output received yet ***"
|
||||||
while waiting_for_data:
|
while waiting_for_data:
|
||||||
# TODO: fix the script paths so they're consistent between containers
|
# TODO: fix the script paths so they're consistent between
|
||||||
|
# containers
|
||||||
source_value = None
|
source_value = None
|
||||||
try:
|
try:
|
||||||
source_value = deployer.execute(pd.source_container,
|
source_value = deployer.execute(
|
||||||
["sh", "-c",
|
pd.source_container,
|
||||||
"sh /docker-entrypoint-scripts.d/export-"
|
[
|
||||||
f"{pd.source_variable}.sh"],
|
"sh",
|
||||||
tty=False,
|
"-c",
|
||||||
envs=container_exec_env)
|
"sh /docker-entrypoint-scripts.d/export-"
|
||||||
|
f"{pd.source_variable}.sh",
|
||||||
|
],
|
||||||
|
tty=False,
|
||||||
|
envs=container_exec_env,
|
||||||
|
)
|
||||||
except DeployerException as error:
|
except DeployerException as error:
|
||||||
if ctx.debug:
|
if ctx.debug:
|
||||||
print(f"Docker exception reading config source: {error}")
|
print(f"Docker exception reading config source: {error}")
|
||||||
@@ -438,20 +567,28 @@ def _orchestrate_cluster_config(ctx, cluster_config, deployer, container_exec_en
|
|||||||
# "It returned with code 1"
|
# "It returned with code 1"
|
||||||
if "It returned with code 1" in str(error):
|
if "It returned with code 1" in str(error):
|
||||||
if ctx.verbose:
|
if ctx.verbose:
|
||||||
print("Config export script returned an error, re-trying")
|
print(
|
||||||
# If the script failed to execute (e.g. the file is not there) then we get:
|
"Config export script returned an error, re-trying"
|
||||||
|
)
|
||||||
|
# If the script failed to execute
|
||||||
|
# (e.g. the file is not there) then we get:
|
||||||
# "It returned with code 2"
|
# "It returned with code 2"
|
||||||
if "It returned with code 2" in str(error):
|
if "It returned with code 2" in str(error):
|
||||||
print(f"Fatal error reading config source: {error}")
|
print(f"Fatal error reading config source: {error}")
|
||||||
if source_value:
|
if source_value:
|
||||||
if ctx.debug:
|
if ctx.debug:
|
||||||
print(f"fetched source value: {source_value}")
|
print(f"fetched source value: {source_value}")
|
||||||
destination_output = deployer.execute(pd.destination_container,
|
destination_output = deployer.execute(
|
||||||
["sh", "-c",
|
pd.destination_container,
|
||||||
f"sh /scripts/import-{pd.destination_variable}.sh"
|
[
|
||||||
f" {source_value}"],
|
"sh",
|
||||||
tty=False,
|
"-c",
|
||||||
envs=container_exec_env)
|
f"sh /scripts/import-{pd.destination_variable}.sh"
|
||||||
|
f" {source_value}",
|
||||||
|
],
|
||||||
|
tty=False,
|
||||||
|
envs=container_exec_env,
|
||||||
|
)
|
||||||
waiting_for_data = False
|
waiting_for_data = False
|
||||||
if ctx.debug and not waiting_for_data:
|
if ctx.debug and not waiting_for_data:
|
||||||
print(f"destination output: {destination_output}")
|
print(f"destination output: {destination_output}")
|
||||||
@@ -460,3 +597,4 @@ def _orchestrate_cluster_config(ctx, cluster_config, deployer, container_exec_en
|
|||||||
command.add_command(deployment_init)
|
command.add_command(deployment_init)
|
||||||
command.add_command(deployment_create)
|
command.add_command(deployment_create)
|
||||||
command.add_command(deployment_setup)
|
command.add_command(deployment_setup)
|
||||||
|
command.add_command(k8s_command.command, "k8s")
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <http:#www.gnu.org/licenses/>.
|
# along with this program. If not, see <http:#www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from typing import List, Mapping
|
from typing import List, Mapping, Optional
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from stack_orchestrator.command_types import CommandOptions
|
from stack_orchestrator.command_types import CommandOptions
|
||||||
from stack_orchestrator.deploy.deployer import Deployer
|
from stack_orchestrator.deploy.deployer import Deployer
|
||||||
@@ -21,20 +21,21 @@ from stack_orchestrator.deploy.deployer import Deployer
|
|||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ClusterContext:
|
class ClusterContext:
|
||||||
options: CommandOptions # TODO: this should be in its own object not stuffed in here
|
# TODO: this should be in its own object not stuffed in here
|
||||||
cluster: str
|
options: CommandOptions
|
||||||
|
cluster: Optional[str]
|
||||||
compose_files: List[str]
|
compose_files: List[str]
|
||||||
pre_start_commands: List[str]
|
pre_start_commands: List[str]
|
||||||
post_start_commands: List[str]
|
post_start_commands: List[str]
|
||||||
config: str
|
config: Optional[str]
|
||||||
env_file: str
|
env_file: Optional[str]
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class DeployCommandContext:
|
class DeployCommandContext:
|
||||||
stack: str
|
stack: str
|
||||||
cluster_context: ClusterContext
|
cluster_context: ClusterContext
|
||||||
deployer: Deployer
|
deployer: Optional[Deployer]
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@@ -50,8 +51,10 @@ class LaconicStackSetupCommand:
|
|||||||
key_name: str
|
key_name: str
|
||||||
initialize_network: bool
|
initialize_network: bool
|
||||||
join_network: bool
|
join_network: bool
|
||||||
|
connect_network: bool
|
||||||
create_network: bool
|
create_network: bool
|
||||||
gentx_file_list: str
|
gentx_file_list: str
|
||||||
|
gentx_address_list: str
|
||||||
genesis_file: str
|
genesis_file: str
|
||||||
network_dir: str
|
network_dir: str
|
||||||
|
|
||||||
|
|||||||
@@ -13,10 +13,14 @@
|
|||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <http:#www.gnu.org/licenses/>.
|
# along with this program. If not, see <http:#www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import os
|
|
||||||
from typing import List, Any
|
from typing import List, Any
|
||||||
from stack_orchestrator.deploy.deploy_types import DeployCommandContext, VolumeMapping
|
from stack_orchestrator.deploy.deploy_types import DeployCommandContext, VolumeMapping
|
||||||
from stack_orchestrator.util import get_parsed_stack_config, get_yaml, get_pod_list, resolve_compose_file
|
from stack_orchestrator.util import (
|
||||||
|
get_parsed_stack_config,
|
||||||
|
get_yaml,
|
||||||
|
get_pod_list,
|
||||||
|
resolve_compose_file,
|
||||||
|
)
|
||||||
from stack_orchestrator.opts import opts
|
from stack_orchestrator.opts import opts
|
||||||
|
|
||||||
|
|
||||||
@@ -39,7 +43,7 @@ def _container_image_from_service(stack: str, service: str):
|
|||||||
|
|
||||||
|
|
||||||
def parsed_pod_files_map_from_file_names(pod_files):
|
def parsed_pod_files_map_from_file_names(pod_files):
|
||||||
parsed_pod_yaml_map : Any = {}
|
parsed_pod_yaml_map: Any = {}
|
||||||
for pod_file in pod_files:
|
for pod_file in pod_files:
|
||||||
with open(pod_file, "r") as pod_file_descriptor:
|
with open(pod_file, "r") as pod_file_descriptor:
|
||||||
parsed_pod_file = get_yaml().load(pod_file_descriptor)
|
parsed_pod_file = get_yaml().load(pod_file_descriptor)
|
||||||
@@ -74,17 +78,28 @@ def _volumes_to_docker(mounts: List[VolumeMapping]):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def run_container_command(ctx: DeployCommandContext, service: str, command: str, mounts: List[VolumeMapping]):
|
def run_container_command(
|
||||||
|
ctx: DeployCommandContext, service: str, command: str, mounts: List[VolumeMapping]
|
||||||
|
):
|
||||||
deployer = ctx.deployer
|
deployer = ctx.deployer
|
||||||
|
if deployer is None:
|
||||||
|
raise ValueError("Deployer is not configured")
|
||||||
container_image = _container_image_from_service(ctx.stack, service)
|
container_image = _container_image_from_service(ctx.stack, service)
|
||||||
|
if container_image is None:
|
||||||
|
raise ValueError(f"Container image not found for service: {service}")
|
||||||
docker_volumes = _volumes_to_docker(mounts)
|
docker_volumes = _volumes_to_docker(mounts)
|
||||||
if ctx.cluster_context.options.debug:
|
if ctx.cluster_context.options.debug:
|
||||||
print(f"Running this command in {service} container: {command}")
|
print(f"Running this command in {service} container: {command}")
|
||||||
docker_output = deployer.run(
|
docker_output = deployer.run(
|
||||||
container_image,
|
container_image,
|
||||||
["-c", command], entrypoint="sh",
|
["-c", command],
|
||||||
user=f"{os.getuid()}:{os.getgid()}",
|
entrypoint="sh",
|
||||||
volumes=docker_volumes
|
# Current laconicd container has a bug where it crashes when run not
|
||||||
)
|
# as root
|
||||||
|
# Commented out line below is a workaround. Created files end up
|
||||||
|
# owned by root on the host
|
||||||
|
# user=f"{os.getuid()}:{os.getgid()}",
|
||||||
|
volumes=docker_volumes,
|
||||||
|
)
|
||||||
# There doesn't seem to be a way to get an exit code from docker.run()
|
# There doesn't seem to be a way to get an exit code from docker.run()
|
||||||
return (docker_output, 0)
|
return (docker_output, 0)
|
||||||
|
|||||||
@@ -15,16 +15,16 @@
|
|||||||
|
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
|
||||||
class Deployer(ABC):
|
class Deployer(ABC):
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def up(self, detach, services):
|
def up(self, detach, skip_cluster_management, services):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def down(self, timeout, volumes):
|
def down(self, timeout, volumes, skip_cluster_management):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
@@ -52,7 +52,21 @@ class Deployer(ABC):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def run(self, image: str, command=None, user=None, volumes=None, entrypoint=None, env={}, ports=[], detach=False):
|
def run(
|
||||||
|
self,
|
||||||
|
image: str,
|
||||||
|
command=None,
|
||||||
|
user=None,
|
||||||
|
volumes=None,
|
||||||
|
entrypoint=None,
|
||||||
|
env={},
|
||||||
|
ports=[],
|
||||||
|
detach=False,
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def run_job(self, job_name: str, release_name: Optional[str] = None):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@@ -62,7 +76,6 @@ class DeployerException(Exception):
|
|||||||
|
|
||||||
|
|
||||||
class DeployerConfigGenerator(ABC):
|
class DeployerConfigGenerator(ABC):
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def generate(self, deployment_dir: Path):
|
def generate(self, deployment_dir: Path):
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -14,8 +14,14 @@
|
|||||||
# along with this program. If not, see <http:#www.gnu.org/licenses/>.
|
# along with this program. If not, see <http:#www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from stack_orchestrator import constants
|
from stack_orchestrator import constants
|
||||||
from stack_orchestrator.deploy.k8s.deploy_k8s import K8sDeployer, K8sDeployerConfigGenerator
|
from stack_orchestrator.deploy.k8s.deploy_k8s import (
|
||||||
from stack_orchestrator.deploy.compose.deploy_docker import DockerDeployer, DockerDeployerConfigGenerator
|
K8sDeployer,
|
||||||
|
K8sDeployerConfigGenerator,
|
||||||
|
)
|
||||||
|
from stack_orchestrator.deploy.compose.deploy_docker import (
|
||||||
|
DockerDeployer,
|
||||||
|
DockerDeployerConfigGenerator,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def getDeployerConfigGenerator(type: str, deployment_context):
|
def getDeployerConfigGenerator(type: str, deployment_context):
|
||||||
@@ -27,10 +33,27 @@ def getDeployerConfigGenerator(type: str, deployment_context):
|
|||||||
print(f"ERROR: deploy-to {type} is not valid")
|
print(f"ERROR: deploy-to {type} is not valid")
|
||||||
|
|
||||||
|
|
||||||
def getDeployer(type: str, deployment_context, compose_files, compose_project_name, compose_env_file):
|
def getDeployer(
|
||||||
|
type: str, deployment_context, compose_files, compose_project_name, compose_env_file
|
||||||
|
):
|
||||||
if type == "compose" or type is None:
|
if type == "compose" or type is None:
|
||||||
return DockerDeployer(type, deployment_context, compose_files, compose_project_name, compose_env_file)
|
return DockerDeployer(
|
||||||
elif type == type == constants.k8s_deploy_type or type == constants.k8s_kind_deploy_type:
|
type,
|
||||||
return K8sDeployer(type, deployment_context, compose_files, compose_project_name, compose_env_file)
|
deployment_context,
|
||||||
|
compose_files,
|
||||||
|
compose_project_name,
|
||||||
|
compose_env_file,
|
||||||
|
)
|
||||||
|
elif (
|
||||||
|
type == type == constants.k8s_deploy_type
|
||||||
|
or type == constants.k8s_kind_deploy_type
|
||||||
|
):
|
||||||
|
return K8sDeployer(
|
||||||
|
type,
|
||||||
|
deployment_context,
|
||||||
|
compose_files,
|
||||||
|
compose_project_name,
|
||||||
|
compose_env_file,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
print(f"ERROR: deploy-to {type} is not valid")
|
print(f"ERROR: deploy-to {type} is not valid")
|
||||||
|
|||||||
@@ -18,8 +18,19 @@ from pathlib import Path
|
|||||||
import sys
|
import sys
|
||||||
from stack_orchestrator import constants
|
from stack_orchestrator import constants
|
||||||
from stack_orchestrator.deploy.images import push_images_operation
|
from stack_orchestrator.deploy.images import push_images_operation
|
||||||
from stack_orchestrator.deploy.deploy import up_operation, down_operation, ps_operation, port_operation, status_operation
|
from stack_orchestrator.deploy.deploy import (
|
||||||
from stack_orchestrator.deploy.deploy import exec_operation, logs_operation, create_deploy_context, update_operation
|
up_operation,
|
||||||
|
down_operation,
|
||||||
|
ps_operation,
|
||||||
|
port_operation,
|
||||||
|
status_operation,
|
||||||
|
)
|
||||||
|
from stack_orchestrator.deploy.deploy import (
|
||||||
|
exec_operation,
|
||||||
|
logs_operation,
|
||||||
|
create_deploy_context,
|
||||||
|
update_operation,
|
||||||
|
)
|
||||||
from stack_orchestrator.deploy.deploy_types import DeployCommandContext
|
from stack_orchestrator.deploy.deploy_types import DeployCommandContext
|
||||||
from stack_orchestrator.deploy.deployment_context import DeploymentContext
|
from stack_orchestrator.deploy.deployment_context import DeploymentContext
|
||||||
|
|
||||||
@@ -28,7 +39,7 @@ from stack_orchestrator.deploy.deployment_context import DeploymentContext
|
|||||||
@click.option("--dir", required=True, help="path to deployment directory")
|
@click.option("--dir", required=True, help="path to deployment directory")
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def command(ctx, dir):
|
def command(ctx, dir):
|
||||||
'''manage a deployment'''
|
"""manage a deployment"""
|
||||||
|
|
||||||
# Check that --stack wasn't supplied
|
# Check that --stack wasn't supplied
|
||||||
if ctx.parent.obj.stack:
|
if ctx.parent.obj.stack:
|
||||||
@@ -40,7 +51,10 @@ def command(ctx, dir):
|
|||||||
print(f"Error: deployment directory {dir} does not exist")
|
print(f"Error: deployment directory {dir} does not exist")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
if not dir_path.is_dir():
|
if not dir_path.is_dir():
|
||||||
print(f"Error: supplied deployment directory path {dir} exists but is a file not a directory")
|
print(
|
||||||
|
f"Error: supplied deployment directory path {dir} exists but is a "
|
||||||
|
"file not a directory"
|
||||||
|
)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
# Store the deployment context for subcommands
|
# Store the deployment context for subcommands
|
||||||
deployment_context = DeploymentContext()
|
deployment_context = DeploymentContext()
|
||||||
@@ -57,51 +71,93 @@ def make_deploy_context(ctx) -> DeployCommandContext:
|
|||||||
else:
|
else:
|
||||||
deployment_type = constants.compose_deploy_type
|
deployment_type = constants.compose_deploy_type
|
||||||
stack = context.deployment_dir
|
stack = context.deployment_dir
|
||||||
return create_deploy_context(ctx.parent.parent.obj, context, stack, None, None,
|
return create_deploy_context(
|
||||||
cluster_name, env_file, deployment_type)
|
ctx.parent.parent.obj,
|
||||||
|
context,
|
||||||
|
stack,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
cluster_name,
|
||||||
|
env_file,
|
||||||
|
deployment_type,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: remove legacy up command since it's an alias for start
|
||||||
@command.command()
|
@command.command()
|
||||||
@click.option("--stay-attached/--detatch-terminal", default=False, help="detatch or not to see container stdout")
|
@click.option(
|
||||||
@click.argument('extra_args', nargs=-1) # help: command: up <service1> <service2>
|
"--stay-attached/--detatch-terminal",
|
||||||
|
default=False,
|
||||||
|
help="detatch or not to see container stdout",
|
||||||
|
)
|
||||||
|
@click.option(
|
||||||
|
"--skip-cluster-management/--perform-cluster-management",
|
||||||
|
default=False,
|
||||||
|
help="Skip cluster initialization/tear-down (only for kind-k8s deployments)",
|
||||||
|
)
|
||||||
|
@click.argument("extra_args", nargs=-1) # help: command: up <service1> <service2>
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def up(ctx, stay_attached, extra_args):
|
def up(ctx, stay_attached, skip_cluster_management, extra_args):
|
||||||
ctx.obj = make_deploy_context(ctx)
|
ctx.obj = make_deploy_context(ctx)
|
||||||
services_list = list(extra_args) or None
|
services_list = list(extra_args) or None
|
||||||
up_operation(ctx, services_list, stay_attached)
|
up_operation(ctx, services_list, stay_attached, skip_cluster_management)
|
||||||
|
|
||||||
|
|
||||||
# start is the preferred alias for up
|
# start is the preferred alias for up
|
||||||
@command.command()
|
@command.command()
|
||||||
@click.option("--stay-attached/--detatch-terminal", default=False, help="detatch or not to see container stdout")
|
@click.option(
|
||||||
@click.argument('extra_args', nargs=-1) # help: command: up <service1> <service2>
|
"--stay-attached/--detatch-terminal",
|
||||||
|
default=False,
|
||||||
|
help="detatch or not to see container stdout",
|
||||||
|
)
|
||||||
|
@click.option(
|
||||||
|
"--skip-cluster-management/--perform-cluster-management",
|
||||||
|
default=False,
|
||||||
|
help="Skip cluster initialization/tear-down (only for kind-k8s deployments)",
|
||||||
|
)
|
||||||
|
@click.argument("extra_args", nargs=-1) # help: command: up <service1> <service2>
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def start(ctx, stay_attached, extra_args):
|
def start(ctx, stay_attached, skip_cluster_management, extra_args):
|
||||||
ctx.obj = make_deploy_context(ctx)
|
ctx.obj = make_deploy_context(ctx)
|
||||||
services_list = list(extra_args) or None
|
services_list = list(extra_args) or None
|
||||||
up_operation(ctx, services_list, stay_attached)
|
up_operation(ctx, services_list, stay_attached, skip_cluster_management)
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: remove legacy up command since it's an alias for stop
|
||||||
@command.command()
|
@command.command()
|
||||||
@click.option("--delete-volumes/--preserve-volumes", default=False, help="delete data volumes")
|
@click.option(
|
||||||
@click.argument('extra_args', nargs=-1) # help: command: down <service1> <service2>
|
"--delete-volumes/--preserve-volumes", default=False, help="delete data volumes"
|
||||||
|
)
|
||||||
|
@click.option(
|
||||||
|
"--skip-cluster-management/--perform-cluster-management",
|
||||||
|
default=False,
|
||||||
|
help="Skip cluster initialization/tear-down (only for kind-k8s deployments)",
|
||||||
|
)
|
||||||
|
@click.argument("extra_args", nargs=-1) # help: command: down <service1> <service2>
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def down(ctx, delete_volumes, extra_args):
|
def down(ctx, delete_volumes, skip_cluster_management, extra_args):
|
||||||
# Get the stack config file name
|
# Get the stack config file name
|
||||||
# TODO: add cluster name and env file here
|
# TODO: add cluster name and env file here
|
||||||
ctx.obj = make_deploy_context(ctx)
|
ctx.obj = make_deploy_context(ctx)
|
||||||
down_operation(ctx, delete_volumes, extra_args)
|
down_operation(ctx, delete_volumes, extra_args, skip_cluster_management)
|
||||||
|
|
||||||
|
|
||||||
# stop is the preferred alias for down
|
# stop is the preferred alias for down
|
||||||
@command.command()
|
@command.command()
|
||||||
@click.option("--delete-volumes/--preserve-volumes", default=False, help="delete data volumes")
|
@click.option(
|
||||||
@click.argument('extra_args', nargs=-1) # help: command: down <service1> <service2>
|
"--delete-volumes/--preserve-volumes", default=False, help="delete data volumes"
|
||||||
|
)
|
||||||
|
@click.option(
|
||||||
|
"--skip-cluster-management/--perform-cluster-management",
|
||||||
|
default=False,
|
||||||
|
help="Skip cluster initialization/tear-down (only for kind-k8s deployments)",
|
||||||
|
)
|
||||||
|
@click.argument("extra_args", nargs=-1) # help: command: down <service1> <service2>
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def stop(ctx, delete_volumes, extra_args):
|
def stop(ctx, delete_volumes, skip_cluster_management, extra_args):
|
||||||
# TODO: add cluster name and env file here
|
# TODO: add cluster name and env file here
|
||||||
ctx.obj = make_deploy_context(ctx)
|
ctx.obj = make_deploy_context(ctx)
|
||||||
down_operation(ctx, delete_volumes, extra_args)
|
down_operation(ctx, delete_volumes, extra_args, skip_cluster_management)
|
||||||
|
|
||||||
|
|
||||||
@command.command()
|
@command.command()
|
||||||
@@ -120,7 +176,7 @@ def push_images(ctx):
|
|||||||
|
|
||||||
|
|
||||||
@command.command()
|
@command.command()
|
||||||
@click.argument('extra_args', nargs=-1) # help: command: port <service1> <service2>
|
@click.argument("extra_args", nargs=-1) # help: command: port <service1> <service2>
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def port(ctx, extra_args):
|
def port(ctx, extra_args):
|
||||||
ctx.obj = make_deploy_context(ctx)
|
ctx.obj = make_deploy_context(ctx)
|
||||||
@@ -128,7 +184,7 @@ def port(ctx, extra_args):
|
|||||||
|
|
||||||
|
|
||||||
@command.command()
|
@command.command()
|
||||||
@click.argument('extra_args', nargs=-1) # help: command: exec <service> <command>
|
@click.argument("extra_args", nargs=-1) # help: command: exec <service> <command>
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def exec(ctx, extra_args):
|
def exec(ctx, extra_args):
|
||||||
ctx.obj = make_deploy_context(ctx)
|
ctx.obj = make_deploy_context(ctx)
|
||||||
@@ -138,7 +194,7 @@ def exec(ctx, extra_args):
|
|||||||
@command.command()
|
@command.command()
|
||||||
@click.option("--tail", "-n", default=None, help="number of lines to display")
|
@click.option("--tail", "-n", default=None, help="number of lines to display")
|
||||||
@click.option("--follow", "-f", is_flag=True, default=False, help="follow log output")
|
@click.option("--follow", "-f", is_flag=True, default=False, help="follow log output")
|
||||||
@click.argument('extra_args', nargs=-1) # help: command: logs <service1> <service2>
|
@click.argument("extra_args", nargs=-1) # help: command: logs <service1> <service2>
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def logs(ctx, tail, follow, extra_args):
|
def logs(ctx, tail, follow, extra_args):
|
||||||
ctx.obj = make_deploy_context(ctx)
|
ctx.obj = make_deploy_context(ctx)
|
||||||
@@ -157,3 +213,18 @@ def status(ctx):
|
|||||||
def update(ctx):
|
def update(ctx):
|
||||||
ctx.obj = make_deploy_context(ctx)
|
ctx.obj = make_deploy_context(ctx)
|
||||||
update_operation(ctx)
|
update_operation(ctx)
|
||||||
|
|
||||||
|
|
||||||
|
@command.command()
|
||||||
|
@click.argument("job_name")
|
||||||
|
@click.option(
|
||||||
|
"--helm-release",
|
||||||
|
help="Helm release name (for k8s helm chart deployments, defaults to chart name)",
|
||||||
|
)
|
||||||
|
@click.pass_context
|
||||||
|
def run_job(ctx, job_name, helm_release):
|
||||||
|
"""run a one-time job from the stack"""
|
||||||
|
from stack_orchestrator.deploy.deploy import run_job_operation
|
||||||
|
|
||||||
|
ctx.obj = make_deploy_context(ctx)
|
||||||
|
run_job_operation(ctx, job_name, helm_release)
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
# Copyright © 2022, 2023 Vulcanize
|
# Copyright © 2022, 2023 Vulcanize
|
||||||
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
@@ -45,20 +44,22 @@ class DeploymentContext:
|
|||||||
def get_compose_dir(self):
|
def get_compose_dir(self):
|
||||||
return self.deployment_dir.joinpath(constants.compose_dir_name)
|
return self.deployment_dir.joinpath(constants.compose_dir_name)
|
||||||
|
|
||||||
|
def get_compose_file(self, name: str):
|
||||||
|
return self.get_compose_dir() / f"docker-compose-{name}.yml"
|
||||||
|
|
||||||
def get_cluster_id(self):
|
def get_cluster_id(self):
|
||||||
return self.id
|
return self.id
|
||||||
|
|
||||||
def init(self, dir):
|
def init(self, dir: Path):
|
||||||
self.deployment_dir = dir
|
self.deployment_dir = dir.absolute()
|
||||||
self.spec = Spec()
|
self.spec = Spec()
|
||||||
self.spec.init_from_file(self.get_spec_file())
|
self.spec.init_from_file(self.get_spec_file())
|
||||||
self.stack = Stack(self.spec.obj["stack"])
|
self.stack = Stack(self.spec.obj["stack"])
|
||||||
self.stack.init_from_file(self.get_stack_file())
|
self.stack.init_from_file(self.get_stack_file())
|
||||||
deployment_file_path = self.get_deployment_file()
|
deployment_file_path = self.get_deployment_file()
|
||||||
if deployment_file_path.exists():
|
if deployment_file_path.exists():
|
||||||
with deployment_file_path:
|
obj = get_yaml().load(open(deployment_file_path, "r"))
|
||||||
obj = get_yaml().load(open(deployment_file_path, "r"))
|
self.id = obj[constants.cluster_id_key]
|
||||||
self.id = obj[constants.cluster_id_key]
|
|
||||||
# Handle the case of a legacy deployment with no file
|
# Handle the case of a legacy deployment with no file
|
||||||
# Code below is intended to match the output from _make_default_cluster_name()
|
# Code below is intended to match the output from _make_default_cluster_name()
|
||||||
# TODO: remove when we no longer need to support legacy deployments
|
# TODO: remove when we no longer need to support legacy deployments
|
||||||
@@ -67,3 +68,17 @@ class DeploymentContext:
|
|||||||
unique_cluster_descriptor = f"{path},{self.get_stack_file()},None,None"
|
unique_cluster_descriptor = f"{path},{self.get_stack_file()},None,None"
|
||||||
hash = hashlib.md5(unique_cluster_descriptor.encode()).hexdigest()[:16]
|
hash = hashlib.md5(unique_cluster_descriptor.encode()).hexdigest()[:16]
|
||||||
self.id = f"{constants.cluster_name_prefix}{hash}"
|
self.id = f"{constants.cluster_name_prefix}{hash}"
|
||||||
|
|
||||||
|
def modify_yaml(self, file_path: Path, modifier_func):
|
||||||
|
"""Load a YAML, apply a modification function, and write it back."""
|
||||||
|
if not file_path.absolute().is_relative_to(self.deployment_dir):
|
||||||
|
raise ValueError(f"File is not inside deployment directory: {file_path}")
|
||||||
|
|
||||||
|
yaml = get_yaml()
|
||||||
|
with open(file_path, "r") as f:
|
||||||
|
yaml_data = yaml.load(f)
|
||||||
|
|
||||||
|
modifier_func(yaml_data)
|
||||||
|
|
||||||
|
with open(file_path, "w") as f:
|
||||||
|
yaml.dump(yaml_data, f)
|
||||||
|
|||||||
@@ -24,10 +24,23 @@ from secrets import token_hex
|
|||||||
import sys
|
import sys
|
||||||
from stack_orchestrator import constants
|
from stack_orchestrator import constants
|
||||||
from stack_orchestrator.opts import opts
|
from stack_orchestrator.opts import opts
|
||||||
from stack_orchestrator.util import (get_stack_path, get_parsed_deployment_spec, get_parsed_stack_config,
|
from stack_orchestrator.util import (
|
||||||
global_options, get_yaml, get_pod_list, get_pod_file_path, pod_has_scripts,
|
get_stack_path,
|
||||||
get_pod_script_paths, get_plugin_code_paths, error_exit, env_var_map_from_file,
|
get_parsed_deployment_spec,
|
||||||
resolve_config_dir)
|
get_parsed_stack_config,
|
||||||
|
global_options,
|
||||||
|
get_yaml,
|
||||||
|
get_pod_list,
|
||||||
|
get_pod_file_path,
|
||||||
|
pod_has_scripts,
|
||||||
|
get_pod_script_paths,
|
||||||
|
get_plugin_code_paths,
|
||||||
|
error_exit,
|
||||||
|
env_var_map_from_file,
|
||||||
|
resolve_config_dir,
|
||||||
|
get_job_list,
|
||||||
|
get_job_file_path,
|
||||||
|
)
|
||||||
from stack_orchestrator.deploy.spec import Spec
|
from stack_orchestrator.deploy.spec import Spec
|
||||||
from stack_orchestrator.deploy.deploy_types import LaconicStackSetupCommand
|
from stack_orchestrator.deploy.deploy_types import LaconicStackSetupCommand
|
||||||
from stack_orchestrator.deploy.deployer_factory import getDeployerConfigGenerator
|
from stack_orchestrator.deploy.deployer_factory import getDeployerConfigGenerator
|
||||||
@@ -45,21 +58,21 @@ def _get_ports(stack):
|
|||||||
yaml = get_yaml()
|
yaml = get_yaml()
|
||||||
for pod in pods:
|
for pod in pods:
|
||||||
pod_file_path = get_pod_file_path(stack, parsed_stack, pod)
|
pod_file_path = get_pod_file_path(stack, parsed_stack, pod)
|
||||||
|
if pod_file_path is None:
|
||||||
|
continue
|
||||||
parsed_pod_file = yaml.load(open(pod_file_path, "r"))
|
parsed_pod_file = yaml.load(open(pod_file_path, "r"))
|
||||||
if "services" in parsed_pod_file:
|
if "services" in parsed_pod_file:
|
||||||
for svc_name, svc in parsed_pod_file["services"].items():
|
for svc_name, svc in parsed_pod_file["services"].items():
|
||||||
if "ports" in svc:
|
if "ports" in svc:
|
||||||
# Ports can appear as strings or numbers. We normalize them as strings.
|
# Ports can appear as strings or numbers. We normalize them as
|
||||||
|
# strings.
|
||||||
ports[svc_name] = [str(x) for x in svc["ports"]]
|
ports[svc_name] = [str(x) for x in svc["ports"]]
|
||||||
return ports
|
return ports
|
||||||
|
|
||||||
|
|
||||||
def _get_named_volumes(stack):
|
def _get_named_volumes(stack):
|
||||||
# Parse the compose files looking for named volumes
|
# Parse the compose files looking for named volumes
|
||||||
named_volumes = {
|
named_volumes = {"rw": [], "ro": []}
|
||||||
"rw": [],
|
|
||||||
"ro": []
|
|
||||||
}
|
|
||||||
parsed_stack = get_parsed_stack_config(stack)
|
parsed_stack = get_parsed_stack_config(stack)
|
||||||
pods = get_pod_list(parsed_stack)
|
pods = get_pod_list(parsed_stack)
|
||||||
yaml = get_yaml()
|
yaml = get_yaml()
|
||||||
@@ -75,12 +88,14 @@ def _get_named_volumes(stack):
|
|||||||
ret[svc_name] = {
|
ret[svc_name] = {
|
||||||
"volume": parts[0],
|
"volume": parts[0],
|
||||||
"mount": parts[1],
|
"mount": parts[1],
|
||||||
"options": parts[2] if len(parts) == 3 else None
|
"options": parts[2] if len(parts) == 3 else None,
|
||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
for pod in pods:
|
for pod in pods:
|
||||||
pod_file_path = get_pod_file_path(stack, parsed_stack, pod)
|
pod_file_path = get_pod_file_path(stack, parsed_stack, pod)
|
||||||
|
if pod_file_path is None:
|
||||||
|
continue
|
||||||
parsed_pod_file = yaml.load(open(pod_file_path, "r"))
|
parsed_pod_file = yaml.load(open(pod_file_path, "r"))
|
||||||
if "volumes" in parsed_pod_file:
|
if "volumes" in parsed_pod_file:
|
||||||
volumes = parsed_pod_file["volumes"]
|
volumes = parsed_pod_file["volumes"]
|
||||||
@@ -88,7 +103,10 @@ def _get_named_volumes(stack):
|
|||||||
for vu in find_vol_usage(parsed_pod_file, volume).values():
|
for vu in find_vol_usage(parsed_pod_file, volume).values():
|
||||||
read_only = vu["options"] == "ro"
|
read_only = vu["options"] == "ro"
|
||||||
if read_only:
|
if read_only:
|
||||||
if vu["volume"] not in named_volumes["rw"] and vu["volume"] not in named_volumes["ro"]:
|
if (
|
||||||
|
vu["volume"] not in named_volumes["rw"]
|
||||||
|
and vu["volume"] not in named_volumes["ro"]
|
||||||
|
):
|
||||||
named_volumes["ro"].append(vu["volume"])
|
named_volumes["ro"].append(vu["volume"])
|
||||||
else:
|
else:
|
||||||
if vu["volume"] not in named_volumes["rw"]:
|
if vu["volume"] not in named_volumes["rw"]:
|
||||||
@@ -108,10 +126,13 @@ def _create_bind_dir_if_relative(volume, path_string, compose_dir):
|
|||||||
absolute_path.mkdir(parents=True, exist_ok=True)
|
absolute_path.mkdir(parents=True, exist_ok=True)
|
||||||
else:
|
else:
|
||||||
if not path.exists():
|
if not path.exists():
|
||||||
print(f"WARNING: mount path for volume {volume} does not exist: {path_string}")
|
print(
|
||||||
|
f"WARNING: mount path for volume {volume} does not exist: {path_string}"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# See: https://stackoverflow.com/questions/45699189/editing-docker-compose-yml-with-pyyaml
|
# See:
|
||||||
|
# https://stackoverflow.com/questions/45699189/editing-docker-compose-yml-with-pyyaml
|
||||||
def _fixup_pod_file(pod, spec, compose_dir):
|
def _fixup_pod_file(pod, spec, compose_dir):
|
||||||
deployment_type = spec[constants.deploy_to_key]
|
deployment_type = spec[constants.deploy_to_key]
|
||||||
# Fix up volumes
|
# Fix up volumes
|
||||||
@@ -123,7 +144,11 @@ def _fixup_pod_file(pod, spec, compose_dir):
|
|||||||
if volume in spec_volumes:
|
if volume in spec_volumes:
|
||||||
volume_spec = spec_volumes[volume]
|
volume_spec = spec_volumes[volume]
|
||||||
if volume_spec:
|
if volume_spec:
|
||||||
volume_spec_fixedup = volume_spec if Path(volume_spec).is_absolute() else f".{volume_spec}"
|
volume_spec_fixedup = (
|
||||||
|
volume_spec
|
||||||
|
if Path(volume_spec).is_absolute()
|
||||||
|
else f".{volume_spec}"
|
||||||
|
)
|
||||||
_create_bind_dir_if_relative(volume, volume_spec, compose_dir)
|
_create_bind_dir_if_relative(volume, volume_spec, compose_dir)
|
||||||
# this is Docker specific
|
# this is Docker specific
|
||||||
if spec.is_docker_deployment():
|
if spec.is_docker_deployment():
|
||||||
@@ -132,8 +157,8 @@ def _fixup_pod_file(pod, spec, compose_dir):
|
|||||||
"driver_opts": {
|
"driver_opts": {
|
||||||
"type": "none",
|
"type": "none",
|
||||||
"device": volume_spec_fixedup,
|
"device": volume_spec_fixedup,
|
||||||
"o": "bind"
|
"o": "bind",
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
pod["volumes"][volume] = new_volume_spec
|
pod["volumes"][volume] = new_volume_spec
|
||||||
|
|
||||||
@@ -181,6 +206,8 @@ def call_stack_deploy_init(deploy_command_context):
|
|||||||
for python_file_path in python_file_paths:
|
for python_file_path in python_file_paths:
|
||||||
if python_file_path.exists():
|
if python_file_path.exists():
|
||||||
spec = util.spec_from_file_location("commands", python_file_path)
|
spec = util.spec_from_file_location("commands", python_file_path)
|
||||||
|
if spec is None or spec.loader is None:
|
||||||
|
continue
|
||||||
imported_stack = util.module_from_spec(spec)
|
imported_stack = util.module_from_spec(spec)
|
||||||
spec.loader.exec_module(imported_stack)
|
spec.loader.exec_module(imported_stack)
|
||||||
if _has_method(imported_stack, "init"):
|
if _has_method(imported_stack, "init"):
|
||||||
@@ -189,12 +216,17 @@ def call_stack_deploy_init(deploy_command_context):
|
|||||||
init_done = True
|
init_done = True
|
||||||
else:
|
else:
|
||||||
# TODO: remove this restriction
|
# TODO: remove this restriction
|
||||||
print(f"Skipping init() from plugin {python_file_path}. Only one init() is allowed.")
|
print(
|
||||||
|
f"Skipping init() from plugin {python_file_path}. "
|
||||||
|
"Only one init() is allowed."
|
||||||
|
)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
# TODO: fold this with function above
|
# TODO: fold this with function above
|
||||||
def call_stack_deploy_setup(deploy_command_context, parameters: LaconicStackSetupCommand, extra_args):
|
def call_stack_deploy_setup(
|
||||||
|
deploy_command_context, parameters: LaconicStackSetupCommand, extra_args
|
||||||
|
):
|
||||||
# Link with the python file in the stack
|
# Link with the python file in the stack
|
||||||
# Call a function in it
|
# Call a function in it
|
||||||
# If no function found, return None
|
# If no function found, return None
|
||||||
@@ -202,6 +234,8 @@ def call_stack_deploy_setup(deploy_command_context, parameters: LaconicStackSetu
|
|||||||
for python_file_path in python_file_paths:
|
for python_file_path in python_file_paths:
|
||||||
if python_file_path.exists():
|
if python_file_path.exists():
|
||||||
spec = util.spec_from_file_location("commands", python_file_path)
|
spec = util.spec_from_file_location("commands", python_file_path)
|
||||||
|
if spec is None or spec.loader is None:
|
||||||
|
continue
|
||||||
imported_stack = util.module_from_spec(spec)
|
imported_stack = util.module_from_spec(spec)
|
||||||
spec.loader.exec_module(imported_stack)
|
spec.loader.exec_module(imported_stack)
|
||||||
if _has_method(imported_stack, "setup"):
|
if _has_method(imported_stack, "setup"):
|
||||||
@@ -217,6 +251,8 @@ def call_stack_deploy_create(deployment_context, extra_args):
|
|||||||
for python_file_path in python_file_paths:
|
for python_file_path in python_file_paths:
|
||||||
if python_file_path.exists():
|
if python_file_path.exists():
|
||||||
spec = util.spec_from_file_location("commands", python_file_path)
|
spec = util.spec_from_file_location("commands", python_file_path)
|
||||||
|
if spec is None or spec.loader is None:
|
||||||
|
continue
|
||||||
imported_stack = util.module_from_spec(spec)
|
imported_stack = util.module_from_spec(spec)
|
||||||
spec.loader.exec_module(imported_stack)
|
spec.loader.exec_module(imported_stack)
|
||||||
if _has_method(imported_stack, "create"):
|
if _has_method(imported_stack, "create"):
|
||||||
@@ -247,7 +283,13 @@ def _find_extra_config_dirs(parsed_pod_file, pod):
|
|||||||
|
|
||||||
|
|
||||||
def _get_mapped_ports(stack: str, map_recipe: str):
|
def _get_mapped_ports(stack: str, map_recipe: str):
|
||||||
port_map_recipes = ["any-variable-random", "localhost-same", "any-same", "localhost-fixed-random", "any-fixed-random"]
|
port_map_recipes = [
|
||||||
|
"any-variable-random",
|
||||||
|
"localhost-same",
|
||||||
|
"any-same",
|
||||||
|
"localhost-fixed-random",
|
||||||
|
"any-fixed-random",
|
||||||
|
]
|
||||||
ports = _get_ports(stack)
|
ports = _get_ports(stack)
|
||||||
if ports:
|
if ports:
|
||||||
# Implement any requested mapping recipe
|
# Implement any requested mapping recipe
|
||||||
@@ -259,7 +301,9 @@ def _get_mapped_ports(stack: str, map_recipe: str):
|
|||||||
orig_port = ports_array[x]
|
orig_port = ports_array[x]
|
||||||
# Strip /udp suffix if present
|
# Strip /udp suffix if present
|
||||||
bare_orig_port = orig_port.replace("/udp", "")
|
bare_orig_port = orig_port.replace("/udp", "")
|
||||||
random_port = random.randint(20000, 50000) # Beware: we're relying on luck to not collide
|
random_port = random.randint(
|
||||||
|
20000, 50000
|
||||||
|
) # Beware: we're relying on luck to not collide
|
||||||
if map_recipe == "any-variable-random":
|
if map_recipe == "any-variable-random":
|
||||||
# This is the default so take no action
|
# This is the default so take no action
|
||||||
pass
|
pass
|
||||||
@@ -278,7 +322,10 @@ def _get_mapped_ports(stack: str, map_recipe: str):
|
|||||||
else:
|
else:
|
||||||
print("Error: bad map_recipe")
|
print("Error: bad map_recipe")
|
||||||
else:
|
else:
|
||||||
print(f"Error: --map-ports-to-host must specify one of: {port_map_recipes}")
|
print(
|
||||||
|
f"Error: --map-ports-to-host must specify one of: "
|
||||||
|
f"{port_map_recipes}"
|
||||||
|
)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
return ports
|
return ports
|
||||||
|
|
||||||
@@ -303,33 +350,54 @@ def _parse_config_variables(variable_values: str):
|
|||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
@click.option("--config", help="Provide config variables for the deployment")
|
@click.option("--config", help="Provide config variables for the deployment")
|
||||||
@click.option("--config-file", help="Provide config variables in a file for the deployment")
|
@click.option(
|
||||||
|
"--config-file", help="Provide config variables in a file for the deployment"
|
||||||
|
)
|
||||||
@click.option("--kube-config", help="Provide a config file for a k8s deployment")
|
@click.option("--kube-config", help="Provide a config file for a k8s deployment")
|
||||||
@click.option("--image-registry", help="Provide a container image registry url for this k8s cluster")
|
@click.option(
|
||||||
|
"--image-registry",
|
||||||
|
help="Provide a container image registry url for this k8s cluster",
|
||||||
|
)
|
||||||
@click.option("--output", required=True, help="Write yaml spec file here")
|
@click.option("--output", required=True, help="Write yaml spec file here")
|
||||||
@click.option("--map-ports-to-host", required=False,
|
@click.option(
|
||||||
help="Map ports to the host as one of: any-variable-random (default), "
|
"--map-ports-to-host",
|
||||||
"localhost-same, any-same, localhost-fixed-random, any-fixed-random")
|
required=False,
|
||||||
|
help="Map ports to the host as one of: any-variable-random (default), "
|
||||||
|
"localhost-same, any-same, localhost-fixed-random, any-fixed-random",
|
||||||
|
)
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def init(ctx, config, config_file, kube_config, image_registry, output, map_ports_to_host):
|
def init(
|
||||||
|
ctx, config, config_file, kube_config, image_registry, output, map_ports_to_host
|
||||||
|
):
|
||||||
stack = global_options(ctx).stack
|
stack = global_options(ctx).stack
|
||||||
deployer_type = ctx.obj.deployer.type
|
deployer_type = ctx.obj.deployer.type
|
||||||
deploy_command_context = ctx.obj
|
deploy_command_context = ctx.obj
|
||||||
return init_operation(
|
return init_operation(
|
||||||
deploy_command_context,
|
deploy_command_context,
|
||||||
stack, deployer_type,
|
stack,
|
||||||
config, config_file,
|
deployer_type,
|
||||||
|
config,
|
||||||
|
config_file,
|
||||||
kube_config,
|
kube_config,
|
||||||
image_registry,
|
image_registry,
|
||||||
output,
|
output,
|
||||||
map_ports_to_host)
|
map_ports_to_host,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# The init command's implementation is in a separate function so that we can
|
# The init command's implementation is in a separate function so that we can
|
||||||
# call it from other commands, bypassing the click decoration stuff
|
# call it from other commands, bypassing the click decoration stuff
|
||||||
def init_operation(deploy_command_context, stack, deployer_type, config,
|
def init_operation(
|
||||||
config_file, kube_config, image_registry, output, map_ports_to_host):
|
deploy_command_context,
|
||||||
|
stack,
|
||||||
|
deployer_type,
|
||||||
|
config,
|
||||||
|
config_file,
|
||||||
|
kube_config,
|
||||||
|
image_registry,
|
||||||
|
output,
|
||||||
|
map_ports_to_host,
|
||||||
|
):
|
||||||
default_spec_file_content = call_stack_deploy_init(deploy_command_context)
|
default_spec_file_content = call_stack_deploy_init(deploy_command_context)
|
||||||
spec_file_content = {"stack": stack, constants.deploy_to_key: deployer_type}
|
spec_file_content = {"stack": stack, constants.deploy_to_key: deployer_type}
|
||||||
if deployer_type == "k8s":
|
if deployer_type == "k8s":
|
||||||
@@ -340,13 +408,20 @@ def init_operation(deploy_command_context, stack, deployer_type, config,
|
|||||||
if image_registry:
|
if image_registry:
|
||||||
spec_file_content.update({constants.image_registry_key: image_registry})
|
spec_file_content.update({constants.image_registry_key: image_registry})
|
||||||
else:
|
else:
|
||||||
print("WARNING: --image-registry not specified, only default container registries (eg, Docker Hub) will be available")
|
print(
|
||||||
|
"WARNING: --image-registry not specified, only default container "
|
||||||
|
"registries (eg, Docker Hub) will be available"
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
# Check for --kube-config supplied for non-relevant deployer types
|
# Check for --kube-config supplied for non-relevant deployer types
|
||||||
if kube_config is not None:
|
if kube_config is not None:
|
||||||
error_exit(f"--kube-config is not allowed with a {deployer_type} deployment")
|
error_exit(
|
||||||
|
f"--kube-config is not allowed with a {deployer_type} deployment"
|
||||||
|
)
|
||||||
if image_registry is not None:
|
if image_registry is not None:
|
||||||
error_exit(f"--image-registry is not allowed with a {deployer_type} deployment")
|
error_exit(
|
||||||
|
f"--image-registry is not allowed with a {deployer_type} deployment"
|
||||||
|
)
|
||||||
if default_spec_file_content:
|
if default_spec_file_content:
|
||||||
spec_file_content.update(default_spec_file_content)
|
spec_file_content.update(default_spec_file_content)
|
||||||
config_variables = _parse_config_variables(config)
|
config_variables = _parse_config_variables(config)
|
||||||
@@ -368,7 +443,9 @@ def init_operation(deploy_command_context, stack, deployer_type, config,
|
|||||||
spec_file_content.update({"config": merged_config})
|
spec_file_content.update({"config": merged_config})
|
||||||
|
|
||||||
ports = _get_mapped_ports(stack, map_ports_to_host)
|
ports = _get_mapped_ports(stack, map_ports_to_host)
|
||||||
spec_file_content.update({"network": {"ports": ports}})
|
orig_network = spec_file_content.get("network", {})
|
||||||
|
orig_network["ports"] = ports
|
||||||
|
spec_file_content["network"] = orig_network
|
||||||
|
|
||||||
named_volumes = _get_named_volumes(stack)
|
named_volumes = _get_named_volumes(stack)
|
||||||
if named_volumes:
|
if named_volumes:
|
||||||
@@ -393,7 +470,9 @@ def init_operation(deploy_command_context, stack, deployer_type, config,
|
|||||||
spec_file_content["configmaps"] = configmap_descriptors
|
spec_file_content["configmaps"] = configmap_descriptors
|
||||||
|
|
||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print(f"Creating spec file for stack: {stack} with content: {spec_file_content}")
|
print(
|
||||||
|
f"Creating spec file for stack: {stack} with content: {spec_file_content}"
|
||||||
|
)
|
||||||
|
|
||||||
with open(output, "w") as output_file:
|
with open(output, "w") as output_file:
|
||||||
get_yaml().dump(spec_file_content, output_file)
|
get_yaml().dump(spec_file_content, output_file)
|
||||||
@@ -441,24 +520,54 @@ def _check_volume_definitions(spec):
|
|||||||
|
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
@click.option("--spec-file", required=True, help="Spec file to use to create this deployment")
|
@click.option(
|
||||||
|
"--spec-file", required=True, help="Spec file to use to create this deployment"
|
||||||
|
)
|
||||||
@click.option("--deployment-dir", help="Create deployment files in this directory")
|
@click.option("--deployment-dir", help="Create deployment files in this directory")
|
||||||
|
@click.option(
|
||||||
|
"--helm-chart",
|
||||||
|
is_flag=True,
|
||||||
|
default=False,
|
||||||
|
help="Generate Helm chart instead of deploying (k8s only)",
|
||||||
|
)
|
||||||
# TODO: Hack
|
# TODO: Hack
|
||||||
@click.option("--network-dir", help="Network configuration supplied in this directory")
|
@click.option("--network-dir", help="Network configuration supplied in this directory")
|
||||||
@click.option("--initial-peers", help="Initial set of persistent peers")
|
@click.option("--initial-peers", help="Initial set of persistent peers")
|
||||||
|
@click.argument("extra_args", nargs=-1, type=click.UNPROCESSED)
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def create(ctx, spec_file, deployment_dir, network_dir, initial_peers):
|
def create(
|
||||||
|
ctx, spec_file, deployment_dir, helm_chart, network_dir, initial_peers, extra_args
|
||||||
|
):
|
||||||
deployment_command_context = ctx.obj
|
deployment_command_context = ctx.obj
|
||||||
return create_operation(deployment_command_context, spec_file, deployment_dir, network_dir, initial_peers)
|
return create_operation(
|
||||||
|
deployment_command_context,
|
||||||
|
spec_file,
|
||||||
|
deployment_dir,
|
||||||
|
helm_chart,
|
||||||
|
network_dir,
|
||||||
|
initial_peers,
|
||||||
|
extra_args,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# The init command's implementation is in a separate function so that we can
|
# The init command's implementation is in a separate function so that we can
|
||||||
# call it from other commands, bypassing the click decoration stuff
|
# call it from other commands, bypassing the click decoration stuff
|
||||||
def create_operation(deployment_command_context, spec_file, deployment_dir, network_dir, initial_peers):
|
def create_operation(
|
||||||
parsed_spec = Spec(os.path.abspath(spec_file), get_parsed_deployment_spec(spec_file))
|
deployment_command_context,
|
||||||
|
spec_file,
|
||||||
|
deployment_dir,
|
||||||
|
helm_chart=False,
|
||||||
|
network_dir=None,
|
||||||
|
initial_peers=None,
|
||||||
|
extra_args=(),
|
||||||
|
):
|
||||||
|
parsed_spec = Spec(
|
||||||
|
os.path.abspath(spec_file), get_parsed_deployment_spec(spec_file)
|
||||||
|
)
|
||||||
_check_volume_definitions(parsed_spec)
|
_check_volume_definitions(parsed_spec)
|
||||||
stack_name = parsed_spec["stack"]
|
stack_name = parsed_spec["stack"]
|
||||||
deployment_type = parsed_spec[constants.deploy_to_key]
|
deployment_type = parsed_spec[constants.deploy_to_key]
|
||||||
|
|
||||||
stack_file = get_stack_path(stack_name).joinpath(constants.stack_file_name)
|
stack_file = get_stack_path(stack_name).joinpath(constants.stack_file_name)
|
||||||
parsed_stack = get_parsed_stack_config(stack_name)
|
parsed_stack = get_parsed_stack_config(stack_name)
|
||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
@@ -473,13 +582,30 @@ def create_operation(deployment_command_context, spec_file, deployment_dir, netw
|
|||||||
# Copy spec file and the stack file into the deployment dir
|
# Copy spec file and the stack file into the deployment dir
|
||||||
copyfile(spec_file, deployment_dir_path.joinpath(constants.spec_file_name))
|
copyfile(spec_file, deployment_dir_path.joinpath(constants.spec_file_name))
|
||||||
copyfile(stack_file, deployment_dir_path.joinpath(constants.stack_file_name))
|
copyfile(stack_file, deployment_dir_path.joinpath(constants.stack_file_name))
|
||||||
|
|
||||||
|
# Create deployment.yml with cluster-id
|
||||||
_create_deployment_file(deployment_dir_path)
|
_create_deployment_file(deployment_dir_path)
|
||||||
|
|
||||||
|
# Branch to Helm chart generation flow if --helm-chart flag is set
|
||||||
|
if deployment_type == "k8s" and helm_chart:
|
||||||
|
from stack_orchestrator.deploy.k8s.helm.chart_generator import (
|
||||||
|
generate_helm_chart,
|
||||||
|
)
|
||||||
|
|
||||||
|
generate_helm_chart(stack_name, spec_file, deployment_dir_path)
|
||||||
|
return # Exit early for helm chart generation
|
||||||
|
|
||||||
|
# Existing deployment flow continues unchanged
|
||||||
# Copy any config varibles from the spec file into an env file suitable for compose
|
# Copy any config varibles from the spec file into an env file suitable for compose
|
||||||
_write_config_file(spec_file, deployment_dir_path.joinpath(constants.config_file_name))
|
_write_config_file(
|
||||||
|
spec_file, deployment_dir_path.joinpath(constants.config_file_name)
|
||||||
|
)
|
||||||
# Copy any k8s config file into the deployment dir
|
# Copy any k8s config file into the deployment dir
|
||||||
if deployment_type == "k8s":
|
if deployment_type == "k8s":
|
||||||
_write_kube_config_file(Path(parsed_spec[constants.kube_config_key]),
|
_write_kube_config_file(
|
||||||
deployment_dir_path.joinpath(constants.kube_config_filename))
|
Path(parsed_spec[constants.kube_config_key]),
|
||||||
|
deployment_dir_path.joinpath(constants.kube_config_filename),
|
||||||
|
)
|
||||||
# Copy the pod files into the deployment dir, fixing up content
|
# Copy the pod files into the deployment dir, fixing up content
|
||||||
pods = get_pod_list(parsed_stack)
|
pods = get_pod_list(parsed_stack)
|
||||||
destination_compose_dir = deployment_dir_path.joinpath("compose")
|
destination_compose_dir = deployment_dir_path.joinpath("compose")
|
||||||
@@ -489,6 +615,8 @@ def create_operation(deployment_command_context, spec_file, deployment_dir, netw
|
|||||||
yaml = get_yaml()
|
yaml = get_yaml()
|
||||||
for pod in pods:
|
for pod in pods:
|
||||||
pod_file_path = get_pod_file_path(stack_name, parsed_stack, pod)
|
pod_file_path = get_pod_file_path(stack_name, parsed_stack, pod)
|
||||||
|
if pod_file_path is None:
|
||||||
|
continue
|
||||||
parsed_pod_file = yaml.load(open(pod_file_path, "r"))
|
parsed_pod_file = yaml.load(open(pod_file_path, "r"))
|
||||||
extra_config_dirs = _find_extra_config_dirs(parsed_pod_file, pod)
|
extra_config_dirs = _find_extra_config_dirs(parsed_pod_file, pod)
|
||||||
destination_pod_dir = destination_pods_dir.joinpath(pod)
|
destination_pod_dir = destination_pods_dir.joinpath(pod)
|
||||||
@@ -496,7 +624,9 @@ def create_operation(deployment_command_context, spec_file, deployment_dir, netw
|
|||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print(f"extra config dirs: {extra_config_dirs}")
|
print(f"extra config dirs: {extra_config_dirs}")
|
||||||
_fixup_pod_file(parsed_pod_file, parsed_spec, destination_compose_dir)
|
_fixup_pod_file(parsed_pod_file, parsed_spec, destination_compose_dir)
|
||||||
with open(destination_compose_dir.joinpath("docker-compose-%s.yml" % pod), "w") as output_file:
|
with open(
|
||||||
|
destination_compose_dir.joinpath("docker-compose-%s.yml" % pod), "w"
|
||||||
|
) as output_file:
|
||||||
yaml.dump(parsed_pod_file, output_file)
|
yaml.dump(parsed_pod_file, output_file)
|
||||||
# Copy the config files for the pod, if any
|
# Copy the config files for the pod, if any
|
||||||
config_dirs = {pod}
|
config_dirs = {pod}
|
||||||
@@ -504,8 +634,11 @@ def create_operation(deployment_command_context, spec_file, deployment_dir, netw
|
|||||||
for config_dir in config_dirs:
|
for config_dir in config_dirs:
|
||||||
source_config_dir = resolve_config_dir(stack_name, config_dir)
|
source_config_dir = resolve_config_dir(stack_name, config_dir)
|
||||||
if os.path.exists(source_config_dir):
|
if os.path.exists(source_config_dir):
|
||||||
destination_config_dir = deployment_dir_path.joinpath("config", config_dir)
|
destination_config_dir = deployment_dir_path.joinpath(
|
||||||
# If the same config dir appears in multiple pods, it may already have been copied
|
"config", config_dir
|
||||||
|
)
|
||||||
|
# If the same config dir appears in multiple pods, it may already have
|
||||||
|
# been copied
|
||||||
if not os.path.exists(destination_config_dir):
|
if not os.path.exists(destination_config_dir):
|
||||||
copytree(source_config_dir, destination_config_dir)
|
copytree(source_config_dir, destination_config_dir)
|
||||||
# Copy the script files for the pod, if any
|
# Copy the script files for the pod, if any
|
||||||
@@ -514,17 +647,69 @@ def create_operation(deployment_command_context, spec_file, deployment_dir, netw
|
|||||||
os.mkdir(destination_script_dir)
|
os.mkdir(destination_script_dir)
|
||||||
script_paths = get_pod_script_paths(parsed_stack, pod)
|
script_paths = get_pod_script_paths(parsed_stack, pod)
|
||||||
_copy_files_to_directory(script_paths, destination_script_dir)
|
_copy_files_to_directory(script_paths, destination_script_dir)
|
||||||
|
if parsed_spec.is_kubernetes_deployment():
|
||||||
|
for configmap in parsed_spec.get_configmaps():
|
||||||
|
source_config_dir = resolve_config_dir(stack_name, configmap)
|
||||||
|
if os.path.exists(source_config_dir):
|
||||||
|
destination_config_dir = deployment_dir_path.joinpath(
|
||||||
|
"configmaps", configmap
|
||||||
|
)
|
||||||
|
copytree(
|
||||||
|
source_config_dir, destination_config_dir, dirs_exist_ok=True
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
# TODO: We should probably only do this if the volume is marked :ro.
|
||||||
|
for volume_name, volume_path in parsed_spec.get_volumes().items():
|
||||||
|
source_config_dir = resolve_config_dir(stack_name, volume_name)
|
||||||
|
# Only copy if the source exists and is _not_ empty.
|
||||||
|
if os.path.exists(source_config_dir) and os.listdir(source_config_dir):
|
||||||
|
destination_config_dir = deployment_dir_path.joinpath(volume_path)
|
||||||
|
# Only copy if the destination exists and _is_ empty.
|
||||||
|
if os.path.exists(destination_config_dir) and not os.listdir(
|
||||||
|
destination_config_dir
|
||||||
|
):
|
||||||
|
copytree(
|
||||||
|
source_config_dir,
|
||||||
|
destination_config_dir,
|
||||||
|
dirs_exist_ok=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Copy the job files into the deployment dir (for Docker deployments)
|
||||||
|
jobs = get_job_list(parsed_stack)
|
||||||
|
if jobs and not parsed_spec.is_kubernetes_deployment():
|
||||||
|
destination_compose_jobs_dir = deployment_dir_path.joinpath("compose-jobs")
|
||||||
|
os.mkdir(destination_compose_jobs_dir)
|
||||||
|
for job in jobs:
|
||||||
|
job_file_path = get_job_file_path(stack_name, parsed_stack, job)
|
||||||
|
if job_file_path and job_file_path.exists():
|
||||||
|
parsed_job_file = yaml.load(open(job_file_path, "r"))
|
||||||
|
_fixup_pod_file(parsed_job_file, parsed_spec, destination_compose_dir)
|
||||||
|
with open(
|
||||||
|
destination_compose_jobs_dir.joinpath(
|
||||||
|
"docker-compose-%s.yml" % job
|
||||||
|
),
|
||||||
|
"w",
|
||||||
|
) as output_file:
|
||||||
|
yaml.dump(parsed_job_file, output_file)
|
||||||
|
if opts.o.debug:
|
||||||
|
print(f"Copied job compose file: {job}")
|
||||||
|
|
||||||
# Delegate to the stack's Python code
|
# Delegate to the stack's Python code
|
||||||
# The deploy create command doesn't require a --stack argument so we need to insert the
|
# The deploy create command doesn't require a --stack argument so we need
|
||||||
# stack member here.
|
# to insert the stack member here.
|
||||||
deployment_command_context.stack = stack_name
|
deployment_command_context.stack = stack_name
|
||||||
deployment_context = DeploymentContext()
|
deployment_context = DeploymentContext()
|
||||||
deployment_context.init(deployment_dir_path)
|
deployment_context.init(deployment_dir_path)
|
||||||
# Call the deployer to generate any deployer-specific files (e.g. for kind)
|
# Call the deployer to generate any deployer-specific files (e.g. for kind)
|
||||||
deployer_config_generator = getDeployerConfigGenerator(deployment_type, deployment_context)
|
deployer_config_generator = getDeployerConfigGenerator(
|
||||||
|
deployment_type, deployment_context
|
||||||
|
)
|
||||||
# TODO: make deployment_dir_path a Path above
|
# TODO: make deployment_dir_path a Path above
|
||||||
deployer_config_generator.generate(deployment_dir_path)
|
if deployer_config_generator is not None:
|
||||||
call_stack_deploy_create(deployment_context, [network_dir, initial_peers, deployment_command_context])
|
deployer_config_generator.generate(deployment_dir_path)
|
||||||
|
call_stack_deploy_create(
|
||||||
|
deployment_context, [network_dir, initial_peers, *extra_args]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# TODO: this code should be in the stack .py files but
|
# TODO: this code should be in the stack .py files but
|
||||||
@@ -534,16 +719,50 @@ def create_operation(deployment_command_context, spec_file, deployment_dir, netw
|
|||||||
@click.option("--node-moniker", help="Moniker for this node")
|
@click.option("--node-moniker", help="Moniker for this node")
|
||||||
@click.option("--chain-id", help="The new chain id")
|
@click.option("--chain-id", help="The new chain id")
|
||||||
@click.option("--key-name", help="Name for new node key")
|
@click.option("--key-name", help="Name for new node key")
|
||||||
@click.option("--gentx-files", help="List of comma-delimited gentx filenames from other nodes")
|
@click.option(
|
||||||
|
"--gentx-files", help="List of comma-delimited gentx filenames from other nodes"
|
||||||
|
)
|
||||||
|
@click.option(
|
||||||
|
"--gentx-addresses",
|
||||||
|
type=str,
|
||||||
|
help="List of comma-delimited validator addresses for other nodes",
|
||||||
|
)
|
||||||
@click.option("--genesis-file", help="Genesis file for the network")
|
@click.option("--genesis-file", help="Genesis file for the network")
|
||||||
@click.option("--initialize-network", is_flag=True, default=False, help="Initialize phase")
|
@click.option(
|
||||||
|
"--initialize-network", is_flag=True, default=False, help="Initialize phase"
|
||||||
|
)
|
||||||
@click.option("--join-network", is_flag=True, default=False, help="Join phase")
|
@click.option("--join-network", is_flag=True, default=False, help="Join phase")
|
||||||
|
@click.option("--connect-network", is_flag=True, default=False, help="Connect phase")
|
||||||
@click.option("--create-network", is_flag=True, default=False, help="Create phase")
|
@click.option("--create-network", is_flag=True, default=False, help="Create phase")
|
||||||
@click.option("--network-dir", help="Directory for network files")
|
@click.option("--network-dir", help="Directory for network files")
|
||||||
@click.argument('extra_args', nargs=-1)
|
@click.argument("extra_args", nargs=-1)
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def setup(ctx, node_moniker, chain_id, key_name, gentx_files, genesis_file, initialize_network, join_network, create_network,
|
def setup(
|
||||||
network_dir, extra_args):
|
ctx,
|
||||||
parmeters = LaconicStackSetupCommand(chain_id, node_moniker, key_name, initialize_network, join_network, create_network,
|
node_moniker,
|
||||||
gentx_files, genesis_file, network_dir)
|
chain_id,
|
||||||
|
key_name,
|
||||||
|
gentx_files,
|
||||||
|
gentx_addresses,
|
||||||
|
genesis_file,
|
||||||
|
initialize_network,
|
||||||
|
join_network,
|
||||||
|
connect_network,
|
||||||
|
create_network,
|
||||||
|
network_dir,
|
||||||
|
extra_args,
|
||||||
|
):
|
||||||
|
parmeters = LaconicStackSetupCommand(
|
||||||
|
chain_id,
|
||||||
|
node_moniker,
|
||||||
|
key_name,
|
||||||
|
initialize_network,
|
||||||
|
join_network,
|
||||||
|
connect_network,
|
||||||
|
create_network,
|
||||||
|
gentx_files,
|
||||||
|
gentx_addresses,
|
||||||
|
genesis_file,
|
||||||
|
network_dir,
|
||||||
|
)
|
||||||
call_stack_deploy_setup(ctx.obj, parmeters, extra_args)
|
call_stack_deploy_setup(ctx.obj, parmeters, extra_args)
|
||||||
|
|||||||
@@ -32,7 +32,9 @@ def _image_needs_pushed(image: str):
|
|||||||
def _remote_tag_for_image(image: str, remote_repo_url: str):
|
def _remote_tag_for_image(image: str, remote_repo_url: str):
|
||||||
# Turns image tags of the form: foo/bar:local into remote.repo/org/bar:deploy
|
# Turns image tags of the form: foo/bar:local into remote.repo/org/bar:deploy
|
||||||
major_parts = image.split("/", 2)
|
major_parts = image.split("/", 2)
|
||||||
image_name_with_version = major_parts[1] if 2 == len(major_parts) else major_parts[0]
|
image_name_with_version = (
|
||||||
|
major_parts[1] if 2 == len(major_parts) else major_parts[0]
|
||||||
|
)
|
||||||
(image_name, image_version) = image_name_with_version.split(":")
|
(image_name, image_version) = image_name_with_version.split(":")
|
||||||
if image_version == "local":
|
if image_version == "local":
|
||||||
return f"{remote_repo_url}/{image_name}:deploy"
|
return f"{remote_repo_url}/{image_name}:deploy"
|
||||||
@@ -61,17 +63,22 @@ def add_tags_to_image(remote_repo_url: str, local_tag: str, *additional_tags):
|
|||||||
|
|
||||||
docker = DockerClient()
|
docker = DockerClient()
|
||||||
remote_tag = _remote_tag_for_image(local_tag, remote_repo_url)
|
remote_tag = _remote_tag_for_image(local_tag, remote_repo_url)
|
||||||
new_remote_tags = [_remote_tag_for_image(tag, remote_repo_url) for tag in additional_tags]
|
new_remote_tags = [
|
||||||
|
_remote_tag_for_image(tag, remote_repo_url) for tag in additional_tags
|
||||||
|
]
|
||||||
docker.buildx.imagetools.create(sources=[remote_tag], tags=new_remote_tags)
|
docker.buildx.imagetools.create(sources=[remote_tag], tags=new_remote_tags)
|
||||||
|
|
||||||
|
|
||||||
def remote_tag_for_image_unique(image: str, remote_repo_url: str, deployment_id: str):
|
def remote_tag_for_image_unique(image: str, remote_repo_url: str, deployment_id: str):
|
||||||
# Turns image tags of the form: foo/bar:local into remote.repo/org/bar:deploy
|
# Turns image tags of the form: foo/bar:local into remote.repo/org/bar:deploy
|
||||||
major_parts = image.split("/", 2)
|
major_parts = image.split("/", 2)
|
||||||
image_name_with_version = major_parts[1] if 2 == len(major_parts) else major_parts[0]
|
image_name_with_version = (
|
||||||
|
major_parts[1] if 2 == len(major_parts) else major_parts[0]
|
||||||
|
)
|
||||||
(image_name, image_version) = image_name_with_version.split(":")
|
(image_name, image_version) = image_name_with_version.split(":")
|
||||||
if image_version == "local":
|
if image_version == "local":
|
||||||
# Salt the tag with part of the deployment id to make it unique to this deployment
|
# Salt the tag with part of the deployment id to make it unique to this
|
||||||
|
# deployment
|
||||||
deployment_tag = deployment_id[-8:]
|
deployment_tag = deployment_id[-8:]
|
||||||
return f"{remote_repo_url}/{image_name}:deploy-{deployment_tag}"
|
return f"{remote_repo_url}/{image_name}:deploy-{deployment_tag}"
|
||||||
else:
|
else:
|
||||||
@@ -79,7 +86,9 @@ def remote_tag_for_image_unique(image: str, remote_repo_url: str, deployment_id:
|
|||||||
|
|
||||||
|
|
||||||
# TODO: needs lots of error handling
|
# TODO: needs lots of error handling
|
||||||
def push_images_operation(command_context: DeployCommandContext, deployment_context: DeploymentContext):
|
def push_images_operation(
|
||||||
|
command_context: DeployCommandContext, deployment_context: DeploymentContext
|
||||||
|
):
|
||||||
# Get the list of images for the stack
|
# Get the list of images for the stack
|
||||||
cluster_context = command_context.cluster_context
|
cluster_context = command_context.cluster_context
|
||||||
images: Set[str] = images_for_deployment(cluster_context.compose_files)
|
images: Set[str] = images_for_deployment(cluster_context.compose_files)
|
||||||
@@ -88,14 +97,18 @@ def push_images_operation(command_context: DeployCommandContext, deployment_cont
|
|||||||
docker = DockerClient()
|
docker = DockerClient()
|
||||||
for image in images:
|
for image in images:
|
||||||
if _image_needs_pushed(image):
|
if _image_needs_pushed(image):
|
||||||
remote_tag = remote_tag_for_image_unique(image, remote_repo_url, deployment_context.id)
|
remote_tag = remote_tag_for_image_unique(
|
||||||
|
image, remote_repo_url, deployment_context.id
|
||||||
|
)
|
||||||
if opts.o.verbose:
|
if opts.o.verbose:
|
||||||
print(f"Tagging {image} to {remote_tag}")
|
print(f"Tagging {image} to {remote_tag}")
|
||||||
docker.image.tag(image, remote_tag)
|
docker.image.tag(image, remote_tag)
|
||||||
# Run docker push commands to upload
|
# Run docker push commands to upload
|
||||||
for image in images:
|
for image in images:
|
||||||
if _image_needs_pushed(image):
|
if _image_needs_pushed(image):
|
||||||
remote_tag = remote_tag_for_image_unique(image, remote_repo_url, deployment_context.id)
|
remote_tag = remote_tag_for_image_unique(
|
||||||
|
image, remote_repo_url, deployment_context.id
|
||||||
|
)
|
||||||
if opts.o.verbose:
|
if opts.o.verbose:
|
||||||
print(f"Pushing image {remote_tag}")
|
print(f"Pushing image {remote_tag}")
|
||||||
docker.image.push(remote_tag)
|
docker.image.push(remote_tag)
|
||||||
|
|||||||
@@ -14,32 +14,44 @@
|
|||||||
# along with this program. If not, see <http:#www.gnu.org/licenses/>.
|
# along with this program. If not, see <http:#www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import base64
|
||||||
|
|
||||||
from kubernetes import client
|
from kubernetes import client
|
||||||
from typing import Any, List, Set
|
from typing import Any, List, Optional, Set
|
||||||
|
|
||||||
from stack_orchestrator.opts import opts
|
from stack_orchestrator.opts import opts
|
||||||
from stack_orchestrator.util import env_var_map_from_file
|
from stack_orchestrator.util import env_var_map_from_file
|
||||||
from stack_orchestrator.deploy.k8s.helpers import named_volumes_from_pod_files, volume_mounts_for_service, volumes_for_pod_files
|
from stack_orchestrator.deploy.k8s.helpers import (
|
||||||
|
named_volumes_from_pod_files,
|
||||||
|
volume_mounts_for_service,
|
||||||
|
volumes_for_pod_files,
|
||||||
|
)
|
||||||
from stack_orchestrator.deploy.k8s.helpers import get_kind_pv_bind_mount_path
|
from stack_orchestrator.deploy.k8s.helpers import get_kind_pv_bind_mount_path
|
||||||
from stack_orchestrator.deploy.k8s.helpers import envs_from_environment_variables_map, envs_from_compose_file, merge_envs
|
from stack_orchestrator.deploy.k8s.helpers import (
|
||||||
from stack_orchestrator.deploy.deploy_util import parsed_pod_files_map_from_file_names, images_for_deployment
|
envs_from_environment_variables_map,
|
||||||
|
envs_from_compose_file,
|
||||||
|
merge_envs,
|
||||||
|
)
|
||||||
|
from stack_orchestrator.deploy.deploy_util import (
|
||||||
|
parsed_pod_files_map_from_file_names,
|
||||||
|
images_for_deployment,
|
||||||
|
)
|
||||||
from stack_orchestrator.deploy.deploy_types import DeployEnvVars
|
from stack_orchestrator.deploy.deploy_types import DeployEnvVars
|
||||||
from stack_orchestrator.deploy.spec import Spec, Resources, ResourceLimits
|
from stack_orchestrator.deploy.spec import Spec, Resources, ResourceLimits
|
||||||
from stack_orchestrator.deploy.images import remote_tag_for_image_unique
|
from stack_orchestrator.deploy.images import remote_tag_for_image_unique
|
||||||
|
|
||||||
DEFAULT_VOLUME_RESOURCES = Resources({
|
DEFAULT_VOLUME_RESOURCES = Resources({"reservations": {"storage": "2Gi"}})
|
||||||
"reservations": {"storage": "2Gi"}
|
|
||||||
})
|
|
||||||
|
|
||||||
DEFAULT_CONTAINER_RESOURCES = Resources({
|
DEFAULT_CONTAINER_RESOURCES = Resources(
|
||||||
"reservations": {"cpus": "0.1", "memory": "200M"},
|
{
|
||||||
"limits": {"cpus": "1.0", "memory": "2000M"},
|
"reservations": {"cpus": "1.0", "memory": "2000M"},
|
||||||
})
|
"limits": {"cpus": "4.0", "memory": "8000M"},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def to_k8s_resource_requirements(resources: Resources) -> client.V1ResourceRequirements:
|
def to_k8s_resource_requirements(resources: Resources) -> client.V1ResourceRequirements:
|
||||||
def to_dict(limits: ResourceLimits):
|
def to_dict(limits: Optional[ResourceLimits]):
|
||||||
if not limits:
|
if not limits:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@@ -53,8 +65,7 @@ def to_k8s_resource_requirements(resources: Resources) -> client.V1ResourceRequi
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
return client.V1ResourceRequirements(
|
return client.V1ResourceRequirements(
|
||||||
requests=to_dict(resources.reservations),
|
requests=to_dict(resources.reservations), limits=to_dict(resources.limits)
|
||||||
limits=to_dict(resources.limits)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -72,118 +83,171 @@ class ClusterInfo:
|
|||||||
self.parsed_pod_yaml_map = parsed_pod_files_map_from_file_names(pod_files)
|
self.parsed_pod_yaml_map = parsed_pod_files_map_from_file_names(pod_files)
|
||||||
# Find the set of images in the pods
|
# Find the set of images in the pods
|
||||||
self.image_set = images_for_deployment(pod_files)
|
self.image_set = images_for_deployment(pod_files)
|
||||||
self.environment_variables = DeployEnvVars(env_var_map_from_file(compose_env_file))
|
# Filter out None values from env file
|
||||||
|
env_vars = {
|
||||||
|
k: v for k, v in env_var_map_from_file(compose_env_file).items() if v
|
||||||
|
}
|
||||||
|
self.environment_variables = DeployEnvVars(env_vars)
|
||||||
self.app_name = deployment_name
|
self.app_name = deployment_name
|
||||||
self.spec = spec
|
self.spec = spec
|
||||||
if (opts.o.debug):
|
if opts.o.debug:
|
||||||
print(f"Env vars: {self.environment_variables.map}")
|
print(f"Env vars: {self.environment_variables.map}")
|
||||||
|
|
||||||
def get_nodeport(self):
|
def get_nodeports(self):
|
||||||
|
nodeports = []
|
||||||
for pod_name in self.parsed_pod_yaml_map:
|
for pod_name in self.parsed_pod_yaml_map:
|
||||||
pod = self.parsed_pod_yaml_map[pod_name]
|
pod = self.parsed_pod_yaml_map[pod_name]
|
||||||
services = pod["services"]
|
services = pod["services"]
|
||||||
for service_name in services:
|
for service_name in services:
|
||||||
service_info = services[service_name]
|
service_info = services[service_name]
|
||||||
if "ports" in service_info:
|
if "ports" in service_info:
|
||||||
port = int(service_info["ports"][0])
|
for raw_port in [str(p) for p in service_info["ports"]]:
|
||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print(f"service port: {port}")
|
print(f"service port: {raw_port}")
|
||||||
service = client.V1Service(
|
# Parse protocol suffix (e.g., "8001/udp" -> port=8001,
|
||||||
metadata=client.V1ObjectMeta(name=f"{self.app_name}-nodeport"),
|
# protocol=UDP)
|
||||||
spec=client.V1ServiceSpec(
|
protocol = "TCP"
|
||||||
type="NodePort",
|
port_str = raw_port
|
||||||
ports=[client.V1ServicePort(
|
if "/" in raw_port:
|
||||||
port=port,
|
port_str, proto = raw_port.rsplit("/", 1)
|
||||||
target_port=port
|
protocol = proto.upper()
|
||||||
)],
|
if ":" in port_str:
|
||||||
selector={"app": self.app_name}
|
parts = port_str.split(":")
|
||||||
)
|
if len(parts) != 2:
|
||||||
)
|
raise Exception(f"Invalid port definition: {raw_port}")
|
||||||
return service
|
node_port = int(parts[0])
|
||||||
|
pod_port = int(parts[1])
|
||||||
|
else:
|
||||||
|
node_port = None
|
||||||
|
pod_port = int(port_str)
|
||||||
|
service = client.V1Service(
|
||||||
|
metadata=client.V1ObjectMeta(
|
||||||
|
name=(
|
||||||
|
f"{self.app_name}-nodeport-"
|
||||||
|
f"{pod_port}-{protocol.lower()}"
|
||||||
|
)
|
||||||
|
),
|
||||||
|
spec=client.V1ServiceSpec(
|
||||||
|
type="NodePort",
|
||||||
|
ports=[
|
||||||
|
client.V1ServicePort(
|
||||||
|
port=pod_port,
|
||||||
|
target_port=pod_port,
|
||||||
|
node_port=node_port,
|
||||||
|
protocol=protocol,
|
||||||
|
)
|
||||||
|
],
|
||||||
|
selector={"app": self.app_name},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
nodeports.append(service)
|
||||||
|
return nodeports
|
||||||
|
|
||||||
def get_ingress(self, use_tls=False, certificate=None, cluster_issuer="letsencrypt-prod"):
|
def get_ingress(
|
||||||
|
self, use_tls=False, certificates=None, cluster_issuer="letsencrypt-prod"
|
||||||
|
):
|
||||||
# No ingress for a deployment that has no http-proxy defined, for now
|
# No ingress for a deployment that has no http-proxy defined, for now
|
||||||
http_proxy_info_list = self.spec.get_http_proxy()
|
http_proxy_info_list = self.spec.get_http_proxy()
|
||||||
ingress = None
|
ingress = None
|
||||||
if http_proxy_info_list:
|
if http_proxy_info_list:
|
||||||
# TODO: handle multiple definitions
|
|
||||||
http_proxy_info = http_proxy_info_list[0]
|
|
||||||
if opts.o.debug:
|
|
||||||
print(f"http-proxy: {http_proxy_info}")
|
|
||||||
# TODO: good enough parsing for webapp deployment for now
|
|
||||||
host_name = http_proxy_info["host-name"]
|
|
||||||
rules = []
|
rules = []
|
||||||
tls = [client.V1IngressTLS(
|
tls = [] if use_tls else None
|
||||||
hosts=certificate["spec"]["dnsNames"] if certificate else [host_name],
|
|
||||||
secret_name=certificate["spec"]["secretName"] if certificate else f"{self.app_name}-tls"
|
for http_proxy_info in http_proxy_info_list:
|
||||||
)] if use_tls else None
|
|
||||||
paths = []
|
|
||||||
for route in http_proxy_info["routes"]:
|
|
||||||
path = route["path"]
|
|
||||||
proxy_to = route["proxy-to"]
|
|
||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print(f"proxy config: {path} -> {proxy_to}")
|
print(f"http-proxy: {http_proxy_info}")
|
||||||
# proxy_to has the form <service>:<port>
|
host_name = http_proxy_info["host-name"]
|
||||||
proxy_to_port = int(proxy_to.split(":")[1])
|
certificate = (certificates or {}).get(host_name)
|
||||||
paths.append(client.V1HTTPIngressPath(
|
|
||||||
path_type="Prefix",
|
if use_tls:
|
||||||
path=path,
|
tls.append(
|
||||||
backend=client.V1IngressBackend(
|
client.V1IngressTLS(
|
||||||
service=client.V1IngressServiceBackend(
|
hosts=certificate["spec"]["dnsNames"]
|
||||||
# TODO: this looks wrong
|
if certificate
|
||||||
name=f"{self.app_name}-service",
|
else [host_name],
|
||||||
# TODO: pull port number from the service
|
secret_name=certificate["spec"]["secretName"]
|
||||||
port=client.V1ServiceBackendPort(number=proxy_to_port)
|
if certificate
|
||||||
|
else f"{self.app_name}-{host_name}-tls",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
))
|
|
||||||
rules.append(client.V1IngressRule(
|
paths = []
|
||||||
host=host_name,
|
for route in http_proxy_info["routes"]:
|
||||||
http=client.V1HTTPIngressRuleValue(
|
path = route["path"]
|
||||||
paths=paths
|
proxy_to = route["proxy-to"]
|
||||||
|
if opts.o.debug:
|
||||||
|
print(f"proxy config: {path} -> {proxy_to}")
|
||||||
|
# proxy_to has the form <service>:<port>
|
||||||
|
proxy_to_port = int(proxy_to.split(":")[1])
|
||||||
|
paths.append(
|
||||||
|
client.V1HTTPIngressPath(
|
||||||
|
path_type="Prefix",
|
||||||
|
path=path,
|
||||||
|
backend=client.V1IngressBackend(
|
||||||
|
service=client.V1IngressServiceBackend(
|
||||||
|
# TODO: this looks wrong
|
||||||
|
name=f"{self.app_name}-service",
|
||||||
|
# TODO: pull port number from the service
|
||||||
|
port=client.V1ServiceBackendPort(
|
||||||
|
number=proxy_to_port
|
||||||
|
),
|
||||||
|
)
|
||||||
|
),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
rules.append(
|
||||||
|
client.V1IngressRule(
|
||||||
|
host=host_name,
|
||||||
|
http=client.V1HTTPIngressRuleValue(paths=paths),
|
||||||
|
)
|
||||||
)
|
)
|
||||||
))
|
|
||||||
spec = client.V1IngressSpec(
|
spec = client.V1IngressSpec(tls=tls, rules=rules)
|
||||||
tls=tls,
|
|
||||||
rules=rules
|
|
||||||
)
|
|
||||||
|
|
||||||
ingress_annotations = {
|
ingress_annotations = {
|
||||||
"kubernetes.io/ingress.class": "nginx",
|
"kubernetes.io/ingress.class": "caddy",
|
||||||
}
|
}
|
||||||
if not certificate:
|
if not certificates:
|
||||||
ingress_annotations["cert-manager.io/cluster-issuer"] = cluster_issuer
|
ingress_annotations["cert-manager.io/cluster-issuer"] = cluster_issuer
|
||||||
|
|
||||||
ingress = client.V1Ingress(
|
ingress = client.V1Ingress(
|
||||||
metadata=client.V1ObjectMeta(
|
metadata=client.V1ObjectMeta(
|
||||||
name=f"{self.app_name}-ingress",
|
name=f"{self.app_name}-ingress", annotations=ingress_annotations
|
||||||
annotations=ingress_annotations
|
|
||||||
),
|
),
|
||||||
spec=spec
|
spec=spec,
|
||||||
)
|
)
|
||||||
return ingress
|
return ingress
|
||||||
|
|
||||||
# TODO: suppoprt multiple services
|
# TODO: suppoprt multiple services
|
||||||
def get_service(self):
|
def get_service(self):
|
||||||
for pod_name in self.parsed_pod_yaml_map:
|
# Collect all ports from http-proxy routes
|
||||||
pod = self.parsed_pod_yaml_map[pod_name]
|
ports_set = set()
|
||||||
services = pod["services"]
|
http_proxy_list = self.spec.get_http_proxy()
|
||||||
for service_name in services:
|
if http_proxy_list:
|
||||||
service_info = services[service_name]
|
for http_proxy in http_proxy_list:
|
||||||
if "ports" in service_info:
|
for route in http_proxy.get("routes", []):
|
||||||
port = int(service_info["ports"][0])
|
proxy_to = route.get("proxy-to", "")
|
||||||
if opts.o.debug:
|
if ":" in proxy_to:
|
||||||
print(f"service port: {port}")
|
port = int(proxy_to.split(":")[1])
|
||||||
|
ports_set.add(port)
|
||||||
|
if opts.o.debug:
|
||||||
|
print(f"http-proxy route port: {port}")
|
||||||
|
|
||||||
|
if not ports_set:
|
||||||
|
return None
|
||||||
|
|
||||||
|
service_ports = [
|
||||||
|
client.V1ServicePort(port=p, target_port=p, name=f"port-{p}")
|
||||||
|
for p in sorted(ports_set)
|
||||||
|
]
|
||||||
|
|
||||||
service = client.V1Service(
|
service = client.V1Service(
|
||||||
metadata=client.V1ObjectMeta(name=f"{self.app_name}-service"),
|
metadata=client.V1ObjectMeta(name=f"{self.app_name}-service"),
|
||||||
spec=client.V1ServiceSpec(
|
spec=client.V1ServiceSpec(
|
||||||
type="ClusterIP",
|
type="ClusterIP",
|
||||||
ports=[client.V1ServicePort(
|
ports=service_ports,
|
||||||
port=port,
|
selector={"app": self.app_name},
|
||||||
target_port=port
|
),
|
||||||
)],
|
|
||||||
selector={"app": self.app_name}
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
return service
|
return service
|
||||||
|
|
||||||
@@ -206,7 +270,7 @@ class ClusterInfo:
|
|||||||
|
|
||||||
labels = {
|
labels = {
|
||||||
"app": self.app_name,
|
"app": self.app_name,
|
||||||
"volume-label": f"{self.app_name}-{volume_name}"
|
"volume-label": f"{self.app_name}-{volume_name}",
|
||||||
}
|
}
|
||||||
if volume_path:
|
if volume_path:
|
||||||
storage_class_name = "manual"
|
storage_class_name = "manual"
|
||||||
@@ -220,11 +284,13 @@ class ClusterInfo:
|
|||||||
access_modes=["ReadWriteOnce"],
|
access_modes=["ReadWriteOnce"],
|
||||||
storage_class_name=storage_class_name,
|
storage_class_name=storage_class_name,
|
||||||
resources=to_k8s_resource_requirements(resources),
|
resources=to_k8s_resource_requirements(resources),
|
||||||
volume_name=k8s_volume_name
|
volume_name=k8s_volume_name,
|
||||||
)
|
)
|
||||||
pvc = client.V1PersistentVolumeClaim(
|
pvc = client.V1PersistentVolumeClaim(
|
||||||
metadata=client.V1ObjectMeta(name=f"{self.app_name}-{volume_name}", labels=labels),
|
metadata=client.V1ObjectMeta(
|
||||||
spec=spec
|
name=f"{self.app_name}-{volume_name}", labels=labels
|
||||||
|
),
|
||||||
|
spec=spec,
|
||||||
)
|
)
|
||||||
result.append(pvc)
|
result.append(pvc)
|
||||||
return result
|
return result
|
||||||
@@ -239,21 +305,28 @@ class ClusterInfo:
|
|||||||
print(f"{cfg_map_name} not in pod files")
|
print(f"{cfg_map_name} not in pod files")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if not cfg_map_path.startswith("/"):
|
if not cfg_map_path.startswith("/") and self.spec.file_path is not None:
|
||||||
cfg_map_path = os.path.join(os.path.dirname(self.spec.file_path), cfg_map_path)
|
cfg_map_path = os.path.join(
|
||||||
|
os.path.dirname(str(self.spec.file_path)), cfg_map_path
|
||||||
|
)
|
||||||
|
|
||||||
# Read in all the files at a single-level of the directory. This mimics the behavior
|
# Read in all the files at a single-level of the directory.
|
||||||
# of `kubectl create configmap foo --from-file=/path/to/dir`
|
# This mimics the behavior of
|
||||||
|
# `kubectl create configmap foo --from-file=/path/to/dir`
|
||||||
data = {}
|
data = {}
|
||||||
for f in os.listdir(cfg_map_path):
|
for f in os.listdir(cfg_map_path):
|
||||||
full_path = os.path.join(cfg_map_path, f)
|
full_path = os.path.join(cfg_map_path, f)
|
||||||
if os.path.isfile(full_path):
|
if os.path.isfile(full_path):
|
||||||
data[f] = open(full_path, 'rt').read()
|
data[f] = base64.b64encode(open(full_path, "rb").read()).decode(
|
||||||
|
"ASCII"
|
||||||
|
)
|
||||||
|
|
||||||
spec = client.V1ConfigMap(
|
spec = client.V1ConfigMap(
|
||||||
metadata=client.V1ObjectMeta(name=f"{self.app_name}-{cfg_map_name}",
|
metadata=client.V1ObjectMeta(
|
||||||
labels={"configmap-label": cfg_map_name}),
|
name=f"{self.app_name}-{cfg_map_name}",
|
||||||
data=data
|
labels={"configmap-label": cfg_map_name},
|
||||||
|
),
|
||||||
|
binary_data=data,
|
||||||
)
|
)
|
||||||
result.append(spec)
|
result.append(spec)
|
||||||
return result
|
return result
|
||||||
@@ -267,10 +340,14 @@ class ClusterInfo:
|
|||||||
resources = DEFAULT_VOLUME_RESOURCES
|
resources = DEFAULT_VOLUME_RESOURCES
|
||||||
for volume_name, volume_path in spec_volumes.items():
|
for volume_name, volume_path in spec_volumes.items():
|
||||||
# We only need to create a volume if it is fully qualified HostPath.
|
# We only need to create a volume if it is fully qualified HostPath.
|
||||||
# Otherwise, we create the PVC and expect the node to allocate the volume for us.
|
# Otherwise, we create the PVC and expect the node to allocate the volume
|
||||||
|
# for us.
|
||||||
if not volume_path:
|
if not volume_path:
|
||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print(f"{volume_name} does not require an explicit PersistentVolume, since it is not a bind-mount.")
|
print(
|
||||||
|
f"{volume_name} does not require an explicit "
|
||||||
|
"PersistentVolume, since it is not a bind-mount."
|
||||||
|
)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if volume_name not in named_volumes:
|
if volume_name not in named_volumes:
|
||||||
@@ -279,30 +356,38 @@ class ClusterInfo:
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
if not os.path.isabs(volume_path):
|
if not os.path.isabs(volume_path):
|
||||||
print(f"WARNING: {volume_name}:{volume_path} is not absolute, cannot bind volume.")
|
print(
|
||||||
|
f"WARNING: {volume_name}:{volume_path} is not absolute, "
|
||||||
|
"cannot bind volume."
|
||||||
|
)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if self.spec.is_kind_deployment():
|
if self.spec.is_kind_deployment():
|
||||||
host_path = client.V1HostPathVolumeSource(path=get_kind_pv_bind_mount_path(volume_name))
|
host_path = client.V1HostPathVolumeSource(
|
||||||
|
path=get_kind_pv_bind_mount_path(volume_name)
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
host_path = client.V1HostPathVolumeSource(path=volume_path)
|
host_path = client.V1HostPathVolumeSource(path=volume_path)
|
||||||
spec = client.V1PersistentVolumeSpec(
|
spec = client.V1PersistentVolumeSpec(
|
||||||
storage_class_name="manual",
|
storage_class_name="manual",
|
||||||
access_modes=["ReadWriteOnce"],
|
access_modes=["ReadWriteOnce"],
|
||||||
capacity=to_k8s_resource_requirements(resources).requests,
|
capacity=to_k8s_resource_requirements(resources).requests,
|
||||||
host_path=host_path
|
host_path=host_path,
|
||||||
)
|
)
|
||||||
pv = client.V1PersistentVolume(
|
pv = client.V1PersistentVolume(
|
||||||
metadata=client.V1ObjectMeta(name=f"{self.app_name}-{volume_name}",
|
metadata=client.V1ObjectMeta(
|
||||||
labels={"volume-label": f"{self.app_name}-{volume_name}"}),
|
name=f"{self.app_name}-{volume_name}",
|
||||||
|
labels={"volume-label": f"{self.app_name}-{volume_name}"},
|
||||||
|
),
|
||||||
spec=spec,
|
spec=spec,
|
||||||
)
|
)
|
||||||
result.append(pv)
|
result.append(pv)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
# TODO: put things like image pull policy into an object-scope struct
|
# TODO: put things like image pull policy into an object-scope struct
|
||||||
def get_deployment(self, image_pull_policy: str = None):
|
def get_deployment(self, image_pull_policy: Optional[str] = None):
|
||||||
containers = []
|
containers = []
|
||||||
|
services = {}
|
||||||
resources = self.spec.get_container_resources()
|
resources = self.spec.get_container_resources()
|
||||||
if not resources:
|
if not resources:
|
||||||
resources = DEFAULT_CONTAINER_RESOURCES
|
resources = DEFAULT_CONTAINER_RESOURCES
|
||||||
@@ -313,46 +398,94 @@ class ClusterInfo:
|
|||||||
container_name = service_name
|
container_name = service_name
|
||||||
service_info = services[service_name]
|
service_info = services[service_name]
|
||||||
image = service_info["image"]
|
image = service_info["image"]
|
||||||
|
container_ports = []
|
||||||
if "ports" in service_info:
|
if "ports" in service_info:
|
||||||
port = int(service_info["ports"][0])
|
for raw_port in [str(p) for p in service_info["ports"]]:
|
||||||
|
# Parse protocol suffix (e.g., "8001/udp" -> port=8001,
|
||||||
|
# protocol=UDP)
|
||||||
|
protocol = "TCP"
|
||||||
|
port_str = raw_port
|
||||||
|
if "/" in raw_port:
|
||||||
|
port_str, proto = raw_port.rsplit("/", 1)
|
||||||
|
protocol = proto.upper()
|
||||||
|
# Handle host:container port mapping - use container port
|
||||||
|
if ":" in port_str:
|
||||||
|
port_str = port_str.split(":")[-1]
|
||||||
|
port = int(port_str)
|
||||||
|
container_ports.append(
|
||||||
|
client.V1ContainerPort(
|
||||||
|
container_port=port, protocol=protocol
|
||||||
|
)
|
||||||
|
)
|
||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print(f"image: {image}")
|
print(f"image: {image}")
|
||||||
print(f"service port: {port}")
|
print(f"service ports: {container_ports}")
|
||||||
merged_envs = merge_envs(
|
merged_envs = (
|
||||||
envs_from_compose_file(
|
merge_envs(
|
||||||
service_info["environment"]), self.environment_variables.map
|
envs_from_compose_file(
|
||||||
) if "environment" in service_info else self.environment_variables.map
|
service_info["environment"], self.environment_variables.map
|
||||||
|
),
|
||||||
|
self.environment_variables.map,
|
||||||
|
)
|
||||||
|
if "environment" in service_info
|
||||||
|
else self.environment_variables.map
|
||||||
|
)
|
||||||
envs = envs_from_environment_variables_map(merged_envs)
|
envs = envs_from_environment_variables_map(merged_envs)
|
||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print(f"Merged envs: {envs}")
|
print(f"Merged envs: {envs}")
|
||||||
# Re-write the image tag for remote deployment
|
# Re-write the image tag for remote deployment
|
||||||
# Note self.app_name has the same value as deployment_id
|
# Note self.app_name has the same value as deployment_id
|
||||||
image_to_use = remote_tag_for_image_unique(
|
image_to_use = (
|
||||||
image,
|
remote_tag_for_image_unique(
|
||||||
self.spec.get_image_registry(),
|
image, self.spec.get_image_registry(), self.app_name
|
||||||
self.app_name) if self.spec.get_image_registry() is not None else image
|
)
|
||||||
volume_mounts = volume_mounts_for_service(self.parsed_pod_yaml_map, service_name)
|
if self.spec.get_image_registry() is not None
|
||||||
|
else image
|
||||||
|
)
|
||||||
|
volume_mounts = volume_mounts_for_service(
|
||||||
|
self.parsed_pod_yaml_map, service_name
|
||||||
|
)
|
||||||
|
# Handle command/entrypoint from compose file
|
||||||
|
# In docker-compose: entrypoint -> k8s command, command -> k8s args
|
||||||
|
container_command = None
|
||||||
|
container_args = None
|
||||||
|
if "entrypoint" in service_info:
|
||||||
|
entrypoint = service_info["entrypoint"]
|
||||||
|
container_command = (
|
||||||
|
entrypoint if isinstance(entrypoint, list) else [entrypoint]
|
||||||
|
)
|
||||||
|
if "command" in service_info:
|
||||||
|
cmd = service_info["command"]
|
||||||
|
container_args = cmd if isinstance(cmd, list) else cmd.split()
|
||||||
container = client.V1Container(
|
container = client.V1Container(
|
||||||
name=container_name,
|
name=container_name,
|
||||||
image=image_to_use,
|
image=image_to_use,
|
||||||
image_pull_policy=image_pull_policy,
|
image_pull_policy=image_pull_policy,
|
||||||
|
command=container_command,
|
||||||
|
args=container_args,
|
||||||
env=envs,
|
env=envs,
|
||||||
ports=[client.V1ContainerPort(container_port=port)],
|
ports=container_ports if container_ports else None,
|
||||||
volume_mounts=volume_mounts,
|
volume_mounts=volume_mounts,
|
||||||
security_context=client.V1SecurityContext(
|
security_context=client.V1SecurityContext(
|
||||||
privileged=self.spec.get_privileged(),
|
privileged=self.spec.get_privileged(),
|
||||||
capabilities=client.V1Capabilities(
|
capabilities=client.V1Capabilities(
|
||||||
add=self.spec.get_capabilities()
|
add=self.spec.get_capabilities()
|
||||||
) if self.spec.get_capabilities() else None
|
)
|
||||||
|
if self.spec.get_capabilities()
|
||||||
|
else None,
|
||||||
),
|
),
|
||||||
resources=to_k8s_resource_requirements(resources),
|
resources=to_k8s_resource_requirements(resources),
|
||||||
)
|
)
|
||||||
containers.append(container)
|
containers.append(container)
|
||||||
volumes = volumes_for_pod_files(self.parsed_pod_yaml_map, self.spec, self.app_name)
|
volumes = volumes_for_pod_files(
|
||||||
|
self.parsed_pod_yaml_map, self.spec, self.app_name
|
||||||
|
)
|
||||||
image_pull_secrets = [client.V1LocalObjectReference(name="laconic-registry")]
|
image_pull_secrets = [client.V1LocalObjectReference(name="laconic-registry")]
|
||||||
|
|
||||||
annotations = None
|
annotations = None
|
||||||
labels = {"app": self.app_name}
|
labels = {"app": self.app_name}
|
||||||
|
affinity = None
|
||||||
|
tolerations = None
|
||||||
|
|
||||||
if self.spec.get_annotations():
|
if self.spec.get_annotations():
|
||||||
annotations = {}
|
annotations = {}
|
||||||
@@ -365,17 +498,60 @@ class ClusterInfo:
|
|||||||
for service_name in services:
|
for service_name in services:
|
||||||
labels[key.replace("{name}", service_name)] = value
|
labels[key.replace("{name}", service_name)] = value
|
||||||
|
|
||||||
|
if self.spec.get_node_affinities():
|
||||||
|
affinities = []
|
||||||
|
for rule in self.spec.get_node_affinities():
|
||||||
|
# TODO add some input validation here
|
||||||
|
label_name = rule["label"]
|
||||||
|
label_value = rule["value"]
|
||||||
|
affinities.append(
|
||||||
|
client.V1NodeSelectorTerm(
|
||||||
|
match_expressions=[
|
||||||
|
client.V1NodeSelectorRequirement(
|
||||||
|
key=label_name, operator="In", values=[label_value]
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
affinity = client.V1Affinity(
|
||||||
|
node_affinity=client.V1NodeAffinity(
|
||||||
|
required_during_scheduling_ignored_during_execution=(
|
||||||
|
client.V1NodeSelector(node_selector_terms=affinities)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if self.spec.get_node_tolerations():
|
||||||
|
tolerations = []
|
||||||
|
for toleration in self.spec.get_node_tolerations():
|
||||||
|
# TODO add some input validation here
|
||||||
|
toleration_key = toleration["key"]
|
||||||
|
toleration_value = toleration["value"]
|
||||||
|
tolerations.append(
|
||||||
|
client.V1Toleration(
|
||||||
|
effect="NoSchedule",
|
||||||
|
key=toleration_key,
|
||||||
|
operator="Equal",
|
||||||
|
value=toleration_value,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
template = client.V1PodTemplateSpec(
|
template = client.V1PodTemplateSpec(
|
||||||
metadata=client.V1ObjectMeta(
|
metadata=client.V1ObjectMeta(annotations=annotations, labels=labels),
|
||||||
annotations=annotations,
|
spec=client.V1PodSpec(
|
||||||
labels=labels
|
containers=containers,
|
||||||
|
image_pull_secrets=image_pull_secrets,
|
||||||
|
volumes=volumes,
|
||||||
|
affinity=affinity,
|
||||||
|
tolerations=tolerations,
|
||||||
|
runtime_class_name=self.spec.get_runtime_class(),
|
||||||
),
|
),
|
||||||
spec=client.V1PodSpec(containers=containers, image_pull_secrets=image_pull_secrets, volumes=volumes),
|
|
||||||
)
|
)
|
||||||
spec = client.V1DeploymentSpec(
|
spec = client.V1DeploymentSpec(
|
||||||
replicas=1, template=template, selector={
|
replicas=self.spec.get_replicas(),
|
||||||
"matchLabels":
|
template=template,
|
||||||
{"app": self.app_name}})
|
selector={"matchLabels": {"app": self.app_name}},
|
||||||
|
)
|
||||||
|
|
||||||
deployment = client.V1Deployment(
|
deployment = client.V1Deployment(
|
||||||
api_version="apps/v1",
|
api_version="apps/v1",
|
||||||
|
|||||||
@@ -16,13 +16,29 @@ from datetime import datetime, timezone
|
|||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from kubernetes import client, config
|
from kubernetes import client, config
|
||||||
|
from kubernetes.client.exceptions import ApiException
|
||||||
|
from typing import Any, Dict, List, Optional, cast
|
||||||
|
|
||||||
from stack_orchestrator import constants
|
from stack_orchestrator import constants
|
||||||
from stack_orchestrator.deploy.deployer import Deployer, DeployerConfigGenerator
|
from stack_orchestrator.deploy.deployer import Deployer, DeployerConfigGenerator
|
||||||
from stack_orchestrator.deploy.k8s.helpers import create_cluster, destroy_cluster, load_images_into_kind
|
from stack_orchestrator.deploy.k8s.helpers import (
|
||||||
from stack_orchestrator.deploy.k8s.helpers import install_ingress_for_kind, wait_for_ingress_in_kind
|
create_cluster,
|
||||||
from stack_orchestrator.deploy.k8s.helpers import pods_in_deployment, containers_in_pod, log_stream_from_string
|
destroy_cluster,
|
||||||
from stack_orchestrator.deploy.k8s.helpers import generate_kind_config
|
load_images_into_kind,
|
||||||
|
)
|
||||||
|
from stack_orchestrator.deploy.k8s.helpers import (
|
||||||
|
install_ingress_for_kind,
|
||||||
|
wait_for_ingress_in_kind,
|
||||||
|
)
|
||||||
|
from stack_orchestrator.deploy.k8s.helpers import (
|
||||||
|
pods_in_deployment,
|
||||||
|
containers_in_pod,
|
||||||
|
log_stream_from_string,
|
||||||
|
)
|
||||||
|
from stack_orchestrator.deploy.k8s.helpers import (
|
||||||
|
generate_kind_config,
|
||||||
|
generate_high_memlock_spec_json,
|
||||||
|
)
|
||||||
from stack_orchestrator.deploy.k8s.cluster_info import ClusterInfo
|
from stack_orchestrator.deploy.k8s.cluster_info import ClusterInfo
|
||||||
from stack_orchestrator.opts import opts
|
from stack_orchestrator.opts import opts
|
||||||
from stack_orchestrator.deploy.deployment_context import DeploymentContext
|
from stack_orchestrator.deploy.deployment_context import DeploymentContext
|
||||||
@@ -35,7 +51,7 @@ class AttrDict(dict):
|
|||||||
self.__dict__ = self
|
self.__dict__ = self
|
||||||
|
|
||||||
|
|
||||||
def _check_delete_exception(e: client.exceptions.ApiException):
|
def _check_delete_exception(e: ApiException) -> None:
|
||||||
if e.status == 404:
|
if e.status == 404:
|
||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print("Failed to delete object, continuing")
|
print("Failed to delete object, continuing")
|
||||||
@@ -43,6 +59,36 @@ def _check_delete_exception(e: client.exceptions.ApiException):
|
|||||||
error_exit(f"k8s api error: {e}")
|
error_exit(f"k8s api error: {e}")
|
||||||
|
|
||||||
|
|
||||||
|
def _create_runtime_class(name: str, handler: str):
|
||||||
|
"""Create a RuntimeClass resource for custom containerd runtime handlers.
|
||||||
|
|
||||||
|
RuntimeClass allows pods to specify which runtime handler to use, enabling
|
||||||
|
different pods to have different rlimit profiles (e.g., high-memlock).
|
||||||
|
|
||||||
|
Args:
|
||||||
|
name: The name of the RuntimeClass resource
|
||||||
|
handler: The containerd runtime handler name
|
||||||
|
(must match containerdConfigPatches)
|
||||||
|
"""
|
||||||
|
api = client.NodeV1Api()
|
||||||
|
runtime_class = client.V1RuntimeClass(
|
||||||
|
api_version="node.k8s.io/v1",
|
||||||
|
kind="RuntimeClass",
|
||||||
|
metadata=client.V1ObjectMeta(name=name),
|
||||||
|
handler=handler,
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
api.create_runtime_class(runtime_class)
|
||||||
|
if opts.o.debug:
|
||||||
|
print(f"Created RuntimeClass: {name}")
|
||||||
|
except ApiException as e:
|
||||||
|
if e.status == 409: # Already exists
|
||||||
|
if opts.o.debug:
|
||||||
|
print(f"RuntimeClass {name} already exists")
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
class K8sDeployer(Deployer):
|
class K8sDeployer(Deployer):
|
||||||
name: str = "k8s"
|
name: str = "k8s"
|
||||||
type: str
|
type: str
|
||||||
@@ -51,21 +97,36 @@ class K8sDeployer(Deployer):
|
|||||||
networking_api: client.NetworkingV1Api
|
networking_api: client.NetworkingV1Api
|
||||||
k8s_namespace: str = "default"
|
k8s_namespace: str = "default"
|
||||||
kind_cluster_name: str
|
kind_cluster_name: str
|
||||||
|
skip_cluster_management: bool
|
||||||
cluster_info: ClusterInfo
|
cluster_info: ClusterInfo
|
||||||
deployment_dir: Path
|
deployment_dir: Path
|
||||||
deployment_context: DeploymentContext
|
deployment_context: DeploymentContext
|
||||||
|
|
||||||
def __init__(self, type, deployment_context: DeploymentContext, compose_files, compose_project_name, compose_env_file) -> None:
|
def __init__(
|
||||||
|
self,
|
||||||
|
type,
|
||||||
|
deployment_context: DeploymentContext,
|
||||||
|
compose_files,
|
||||||
|
compose_project_name,
|
||||||
|
compose_env_file,
|
||||||
|
) -> None:
|
||||||
self.type = type
|
self.type = type
|
||||||
# TODO: workaround pending refactoring above to cope with being created with a null deployment_context
|
self.skip_cluster_management = False
|
||||||
|
# TODO: workaround pending refactoring above to cope with being
|
||||||
|
# created with a null deployment_context
|
||||||
if deployment_context is None:
|
if deployment_context is None:
|
||||||
return
|
return
|
||||||
self.deployment_dir = deployment_context.deployment_dir
|
self.deployment_dir = deployment_context.deployment_dir
|
||||||
self.deployment_context = deployment_context
|
self.deployment_context = deployment_context
|
||||||
self.kind_cluster_name = compose_project_name
|
self.kind_cluster_name = compose_project_name
|
||||||
self.cluster_info = ClusterInfo()
|
self.cluster_info = ClusterInfo()
|
||||||
self.cluster_info.int(compose_files, compose_env_file, compose_project_name, deployment_context.spec)
|
self.cluster_info.int(
|
||||||
if (opts.o.debug):
|
compose_files,
|
||||||
|
compose_env_file,
|
||||||
|
compose_project_name,
|
||||||
|
deployment_context.spec,
|
||||||
|
)
|
||||||
|
if opts.o.debug:
|
||||||
print(f"Deployment dir: {deployment_context.deployment_dir}")
|
print(f"Deployment dir: {deployment_context.deployment_dir}")
|
||||||
print(f"Compose files: {compose_files}")
|
print(f"Compose files: {compose_files}")
|
||||||
print(f"Project name: {compose_project_name}")
|
print(f"Project name: {compose_project_name}")
|
||||||
@@ -77,7 +138,11 @@ class K8sDeployer(Deployer):
|
|||||||
config.load_kube_config(context=f"kind-{self.kind_cluster_name}")
|
config.load_kube_config(context=f"kind-{self.kind_cluster_name}")
|
||||||
else:
|
else:
|
||||||
# Get the config file and pass to load_kube_config()
|
# Get the config file and pass to load_kube_config()
|
||||||
config.load_kube_config(config_file=self.deployment_dir.joinpath(constants.kube_config_filename).as_posix())
|
config.load_kube_config(
|
||||||
|
config_file=self.deployment_dir.joinpath(
|
||||||
|
constants.kube_config_filename
|
||||||
|
).as_posix()
|
||||||
|
)
|
||||||
self.core_api = client.CoreV1Api()
|
self.core_api = client.CoreV1Api()
|
||||||
self.networking_api = client.NetworkingV1Api()
|
self.networking_api = client.NetworkingV1Api()
|
||||||
self.apps_api = client.AppsV1Api()
|
self.apps_api = client.AppsV1Api()
|
||||||
@@ -91,7 +156,9 @@ class K8sDeployer(Deployer):
|
|||||||
print(f"Sending this pv: {pv}")
|
print(f"Sending this pv: {pv}")
|
||||||
if not opts.o.dry_run:
|
if not opts.o.dry_run:
|
||||||
try:
|
try:
|
||||||
pv_resp = self.core_api.read_persistent_volume(name=pv.metadata.name)
|
pv_resp = self.core_api.read_persistent_volume(
|
||||||
|
name=pv.metadata.name
|
||||||
|
)
|
||||||
if pv_resp:
|
if pv_resp:
|
||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print("PVs already present:")
|
print("PVs already present:")
|
||||||
@@ -114,7 +181,8 @@ class K8sDeployer(Deployer):
|
|||||||
if not opts.o.dry_run:
|
if not opts.o.dry_run:
|
||||||
try:
|
try:
|
||||||
pvc_resp = self.core_api.read_namespaced_persistent_volume_claim(
|
pvc_resp = self.core_api.read_namespaced_persistent_volume_claim(
|
||||||
name=pvc.metadata.name, namespace=self.k8s_namespace)
|
name=pvc.metadata.name, namespace=self.k8s_namespace
|
||||||
|
)
|
||||||
if pvc_resp:
|
if pvc_resp:
|
||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print("PVCs already present:")
|
print("PVCs already present:")
|
||||||
@@ -123,7 +191,9 @@ class K8sDeployer(Deployer):
|
|||||||
except: # noqa: E722
|
except: # noqa: E722
|
||||||
pass
|
pass
|
||||||
|
|
||||||
pvc_resp = self.core_api.create_namespaced_persistent_volume_claim(body=pvc, namespace=self.k8s_namespace)
|
pvc_resp = self.core_api.create_namespaced_persistent_volume_claim(
|
||||||
|
body=pvc, namespace=self.k8s_namespace
|
||||||
|
)
|
||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print("PVCs created:")
|
print("PVCs created:")
|
||||||
print(f"{pvc_resp}")
|
print(f"{pvc_resp}")
|
||||||
@@ -135,8 +205,7 @@ class K8sDeployer(Deployer):
|
|||||||
print(f"Sending this ConfigMap: {cfg_map}")
|
print(f"Sending this ConfigMap: {cfg_map}")
|
||||||
if not opts.o.dry_run:
|
if not opts.o.dry_run:
|
||||||
cfg_rsp = self.core_api.create_namespaced_config_map(
|
cfg_rsp = self.core_api.create_namespaced_config_map(
|
||||||
body=cfg_map,
|
body=cfg_map, namespace=self.k8s_namespace
|
||||||
namespace=self.k8s_namespace
|
|
||||||
)
|
)
|
||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print("ConfigMap created:")
|
print("ConfigMap created:")
|
||||||
@@ -144,26 +213,37 @@ class K8sDeployer(Deployer):
|
|||||||
|
|
||||||
def _create_deployment(self):
|
def _create_deployment(self):
|
||||||
# Process compose files into a Deployment
|
# Process compose files into a Deployment
|
||||||
deployment = self.cluster_info.get_deployment(image_pull_policy=None if self.is_kind() else "Always")
|
deployment = self.cluster_info.get_deployment(
|
||||||
|
image_pull_policy=None if self.is_kind() else "Always"
|
||||||
|
)
|
||||||
# Create the k8s objects
|
# Create the k8s objects
|
||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print(f"Sending this deployment: {deployment}")
|
print(f"Sending this deployment: {deployment}")
|
||||||
if not opts.o.dry_run:
|
if not opts.o.dry_run:
|
||||||
deployment_resp = self.apps_api.create_namespaced_deployment(
|
deployment_resp = cast(
|
||||||
body=deployment, namespace=self.k8s_namespace
|
client.V1Deployment,
|
||||||
|
self.apps_api.create_namespaced_deployment(
|
||||||
|
body=deployment, namespace=self.k8s_namespace
|
||||||
|
),
|
||||||
)
|
)
|
||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print("Deployment created:")
|
print("Deployment created:")
|
||||||
print(f"{deployment_resp.metadata.namespace} {deployment_resp.metadata.name} \
|
meta = deployment_resp.metadata
|
||||||
{deployment_resp.metadata.generation} {deployment_resp.spec.template.spec.containers[0].image}")
|
spec = deployment_resp.spec
|
||||||
|
if meta and spec and spec.template.spec:
|
||||||
|
ns = meta.namespace
|
||||||
|
name = meta.name
|
||||||
|
gen = meta.generation
|
||||||
|
containers = spec.template.spec.containers
|
||||||
|
img = containers[0].image if containers else None
|
||||||
|
print(f"{ns} {name} {gen} {img}")
|
||||||
|
|
||||||
service: client.V1Service = self.cluster_info.get_service()
|
service = self.cluster_info.get_service()
|
||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print(f"Sending this service: {service}")
|
print(f"Sending this service: {service}")
|
||||||
if not opts.o.dry_run:
|
if service and not opts.o.dry_run:
|
||||||
service_resp = self.core_api.create_namespaced_service(
|
service_resp = self.core_api.create_namespaced_service(
|
||||||
namespace=self.k8s_namespace,
|
namespace=self.k8s_namespace, body=service
|
||||||
body=service
|
|
||||||
)
|
)
|
||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print("Service created:")
|
print("Service created:")
|
||||||
@@ -174,7 +254,7 @@ class K8sDeployer(Deployer):
|
|||||||
group="cert-manager.io",
|
group="cert-manager.io",
|
||||||
version="v1",
|
version="v1",
|
||||||
namespace=self.k8s_namespace,
|
namespace=self.k8s_namespace,
|
||||||
plural="certificates"
|
plural="certificates",
|
||||||
)
|
)
|
||||||
|
|
||||||
host_parts = host_name.split(".", 1)
|
host_parts = host_name.split(".", 1)
|
||||||
@@ -182,6 +262,7 @@ class K8sDeployer(Deployer):
|
|||||||
if len(host_parts) == 2:
|
if len(host_parts) == 2:
|
||||||
host_as_wild = f"*.{host_parts[1]}"
|
host_as_wild = f"*.{host_parts[1]}"
|
||||||
|
|
||||||
|
# TODO: resolve method deprecation below
|
||||||
now = datetime.utcnow().replace(tzinfo=timezone.utc)
|
now = datetime.utcnow().replace(tzinfo=timezone.utc)
|
||||||
fmt = "%Y-%m-%dT%H:%M:%S%z"
|
fmt = "%Y-%m-%dT%H:%M:%S%z"
|
||||||
|
|
||||||
@@ -198,23 +279,38 @@ class K8sDeployer(Deployer):
|
|||||||
if before < now < after:
|
if before < now < after:
|
||||||
# Check the status is Ready
|
# Check the status is Ready
|
||||||
for condition in status.get("conditions", []):
|
for condition in status.get("conditions", []):
|
||||||
if "True" == condition.get("status") and "Ready" == condition.get("type"):
|
if "True" == condition.get(
|
||||||
|
"status"
|
||||||
|
) and "Ready" == condition.get("type"):
|
||||||
return cert
|
return cert
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def up(self, detach, services):
|
def up(self, detach, skip_cluster_management, services):
|
||||||
|
self.skip_cluster_management = skip_cluster_management
|
||||||
if not opts.o.dry_run:
|
if not opts.o.dry_run:
|
||||||
if self.is_kind():
|
if self.is_kind() and not self.skip_cluster_management:
|
||||||
# Create the kind cluster
|
# Create the kind cluster
|
||||||
create_cluster(self.kind_cluster_name, self.deployment_dir.joinpath(constants.kind_config_filename))
|
create_cluster(
|
||||||
|
self.kind_cluster_name,
|
||||||
|
str(self.deployment_dir.joinpath(constants.kind_config_filename)),
|
||||||
|
)
|
||||||
# Ensure the referenced containers are copied into kind
|
# Ensure the referenced containers are copied into kind
|
||||||
load_images_into_kind(self.kind_cluster_name, self.cluster_info.image_set)
|
load_images_into_kind(
|
||||||
|
self.kind_cluster_name, self.cluster_info.image_set
|
||||||
|
)
|
||||||
self.connect_api()
|
self.connect_api()
|
||||||
if self.is_kind():
|
if self.is_kind() and not self.skip_cluster_management:
|
||||||
# Now configure an ingress controller (not installed by default in kind)
|
# Configure ingress controller (not installed by default in kind)
|
||||||
install_ingress_for_kind()
|
install_ingress_for_kind()
|
||||||
# Wait for ingress to start (deployment provisioning will fail unless this is done)
|
# Wait for ingress to start
|
||||||
|
# (deployment provisioning will fail unless this is done)
|
||||||
wait_for_ingress_in_kind()
|
wait_for_ingress_in_kind()
|
||||||
|
# Create RuntimeClass if unlimited_memlock is enabled
|
||||||
|
if self.cluster_info.spec.get_unlimited_memlock():
|
||||||
|
_create_runtime_class(
|
||||||
|
constants.high_memlock_runtime,
|
||||||
|
constants.high_memlock_runtime,
|
||||||
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print("Dry run mode enabled, skipping k8s API connect")
|
print("Dry run mode enabled, skipping k8s API connect")
|
||||||
@@ -223,21 +319,28 @@ class K8sDeployer(Deployer):
|
|||||||
self._create_deployment()
|
self._create_deployment()
|
||||||
|
|
||||||
http_proxy_info = self.cluster_info.spec.get_http_proxy()
|
http_proxy_info = self.cluster_info.spec.get_http_proxy()
|
||||||
# Note: at present we don't support tls for kind (and enabling tls causes errors)
|
# Note: we don't support tls for kind (enabling tls causes errors)
|
||||||
use_tls = http_proxy_info and not self.is_kind()
|
use_tls = http_proxy_info and not self.is_kind()
|
||||||
certificate = self._find_certificate_for_host_name(http_proxy_info[0]["host-name"]) if use_tls else None
|
certificates = None
|
||||||
if opts.o.debug:
|
if use_tls:
|
||||||
if certificate:
|
certificates = {}
|
||||||
print(f"Using existing certificate: {certificate}")
|
for proxy in http_proxy_info:
|
||||||
|
host_name = proxy["host-name"]
|
||||||
|
cert = self._find_certificate_for_host_name(host_name)
|
||||||
|
if cert:
|
||||||
|
certificates[host_name] = cert
|
||||||
|
if opts.o.debug:
|
||||||
|
print(f"Using existing certificate for {host_name}: {cert}")
|
||||||
|
|
||||||
ingress: client.V1Ingress = self.cluster_info.get_ingress(use_tls=use_tls, certificate=certificate)
|
ingress = self.cluster_info.get_ingress(
|
||||||
|
use_tls=use_tls, certificates=certificates
|
||||||
|
)
|
||||||
if ingress:
|
if ingress:
|
||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print(f"Sending this ingress: {ingress}")
|
print(f"Sending this ingress: {ingress}")
|
||||||
if not opts.o.dry_run:
|
if not opts.o.dry_run:
|
||||||
ingress_resp = self.networking_api.create_namespaced_ingress(
|
ingress_resp = self.networking_api.create_namespaced_ingress(
|
||||||
namespace=self.k8s_namespace,
|
namespace=self.k8s_namespace, body=ingress
|
||||||
body=ingress
|
|
||||||
)
|
)
|
||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print("Ingress created:")
|
print("Ingress created:")
|
||||||
@@ -246,20 +349,20 @@ class K8sDeployer(Deployer):
|
|||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print("No ingress configured")
|
print("No ingress configured")
|
||||||
|
|
||||||
nodeport: client.V1Service = self.cluster_info.get_nodeport()
|
nodeports: List[client.V1Service] = self.cluster_info.get_nodeports()
|
||||||
if nodeport:
|
for nodeport in nodeports:
|
||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print(f"Sending this nodeport: {nodeport}")
|
print(f"Sending this nodeport: {nodeport}")
|
||||||
if not opts.o.dry_run:
|
if not opts.o.dry_run:
|
||||||
nodeport_resp = self.core_api.create_namespaced_service(
|
nodeport_resp = self.core_api.create_namespaced_service(
|
||||||
namespace=self.k8s_namespace,
|
namespace=self.k8s_namespace, body=nodeport
|
||||||
body=nodeport
|
|
||||||
)
|
)
|
||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print("NodePort created:")
|
print("NodePort created:")
|
||||||
print(f"{nodeport_resp}")
|
print(f"{nodeport_resp}")
|
||||||
|
|
||||||
def down(self, timeout, volumes): # noqa: C901
|
def down(self, timeout, volumes, skip_cluster_management): # noqa: C901
|
||||||
|
self.skip_cluster_management = skip_cluster_management
|
||||||
self.connect_api()
|
self.connect_api()
|
||||||
# Delete the k8s objects
|
# Delete the k8s objects
|
||||||
|
|
||||||
@@ -270,11 +373,13 @@ class K8sDeployer(Deployer):
|
|||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print(f"Deleting this pv: {pv}")
|
print(f"Deleting this pv: {pv}")
|
||||||
try:
|
try:
|
||||||
pv_resp = self.core_api.delete_persistent_volume(name=pv.metadata.name)
|
pv_resp = self.core_api.delete_persistent_volume(
|
||||||
|
name=pv.metadata.name
|
||||||
|
)
|
||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print("PV deleted:")
|
print("PV deleted:")
|
||||||
print(f"{pv_resp}")
|
print(f"{pv_resp}")
|
||||||
except client.exceptions.ApiException as e:
|
except ApiException as e:
|
||||||
_check_delete_exception(e)
|
_check_delete_exception(e)
|
||||||
|
|
||||||
# Figure out the PVCs for this deployment
|
# Figure out the PVCs for this deployment
|
||||||
@@ -289,7 +394,7 @@ class K8sDeployer(Deployer):
|
|||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print("PVCs deleted:")
|
print("PVCs deleted:")
|
||||||
print(f"{pvc_resp}")
|
print(f"{pvc_resp}")
|
||||||
except client.exceptions.ApiException as e:
|
except ApiException as e:
|
||||||
_check_delete_exception(e)
|
_check_delete_exception(e)
|
||||||
|
|
||||||
# Figure out the ConfigMaps for this deployment
|
# Figure out the ConfigMaps for this deployment
|
||||||
@@ -304,60 +409,61 @@ class K8sDeployer(Deployer):
|
|||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print("ConfigMap deleted:")
|
print("ConfigMap deleted:")
|
||||||
print(f"{cfg_map_resp}")
|
print(f"{cfg_map_resp}")
|
||||||
except client.exceptions.ApiException as e:
|
except ApiException as e:
|
||||||
_check_delete_exception(e)
|
_check_delete_exception(e)
|
||||||
|
|
||||||
deployment = self.cluster_info.get_deployment()
|
deployment = self.cluster_info.get_deployment()
|
||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print(f"Deleting this deployment: {deployment}")
|
print(f"Deleting this deployment: {deployment}")
|
||||||
try:
|
if deployment and deployment.metadata and deployment.metadata.name:
|
||||||
self.apps_api.delete_namespaced_deployment(
|
try:
|
||||||
name=deployment.metadata.name, namespace=self.k8s_namespace
|
self.apps_api.delete_namespaced_deployment(
|
||||||
)
|
name=deployment.metadata.name, namespace=self.k8s_namespace
|
||||||
except client.exceptions.ApiException as e:
|
)
|
||||||
_check_delete_exception(e)
|
except ApiException as e:
|
||||||
|
_check_delete_exception(e)
|
||||||
|
|
||||||
service: client.V1Service = self.cluster_info.get_service()
|
service = self.cluster_info.get_service()
|
||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print(f"Deleting service: {service}")
|
print(f"Deleting service: {service}")
|
||||||
try:
|
if service and service.metadata and service.metadata.name:
|
||||||
self.core_api.delete_namespaced_service(
|
try:
|
||||||
namespace=self.k8s_namespace,
|
self.core_api.delete_namespaced_service(
|
||||||
name=service.metadata.name
|
namespace=self.k8s_namespace, name=service.metadata.name
|
||||||
)
|
)
|
||||||
except client.exceptions.ApiException as e:
|
except ApiException as e:
|
||||||
_check_delete_exception(e)
|
_check_delete_exception(e)
|
||||||
|
|
||||||
ingress: client.V1Ingress = self.cluster_info.get_ingress(use_tls=not self.is_kind())
|
ingress = self.cluster_info.get_ingress(use_tls=not self.is_kind())
|
||||||
if ingress:
|
if ingress and ingress.metadata and ingress.metadata.name:
|
||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print(f"Deleting this ingress: {ingress}")
|
print(f"Deleting this ingress: {ingress}")
|
||||||
try:
|
try:
|
||||||
self.networking_api.delete_namespaced_ingress(
|
self.networking_api.delete_namespaced_ingress(
|
||||||
name=ingress.metadata.name, namespace=self.k8s_namespace
|
name=ingress.metadata.name, namespace=self.k8s_namespace
|
||||||
)
|
)
|
||||||
except client.exceptions.ApiException as e:
|
except ApiException as e:
|
||||||
_check_delete_exception(e)
|
_check_delete_exception(e)
|
||||||
else:
|
else:
|
||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print("No ingress to delete")
|
print("No ingress to delete")
|
||||||
|
|
||||||
nodeport: client.V1Service = self.cluster_info.get_nodeport()
|
nodeports: List[client.V1Service] = self.cluster_info.get_nodeports()
|
||||||
if nodeport:
|
for nodeport in nodeports:
|
||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print(f"Deleting this nodeport: {ingress}")
|
print(f"Deleting this nodeport: {nodeport}")
|
||||||
try:
|
if nodeport.metadata and nodeport.metadata.name:
|
||||||
self.core_api.delete_namespaced_service(
|
try:
|
||||||
namespace=self.k8s_namespace,
|
self.core_api.delete_namespaced_service(
|
||||||
name=nodeport.metadata.name
|
namespace=self.k8s_namespace, name=nodeport.metadata.name
|
||||||
)
|
)
|
||||||
except client.exceptions.ApiException as e:
|
except ApiException as e:
|
||||||
_check_delete_exception(e)
|
_check_delete_exception(e)
|
||||||
else:
|
else:
|
||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print("No nodeport to delete")
|
print("No nodeport to delete")
|
||||||
|
|
||||||
if self.is_kind():
|
if self.is_kind() and not self.skip_cluster_management:
|
||||||
# Destroy the kind cluster
|
# Destroy the kind cluster
|
||||||
destroy_cluster(self.kind_cluster_name)
|
destroy_cluster(self.kind_cluster_name)
|
||||||
|
|
||||||
@@ -369,8 +475,9 @@ class K8sDeployer(Deployer):
|
|||||||
|
|
||||||
if all_pods.items:
|
if all_pods.items:
|
||||||
for p in all_pods.items:
|
for p in all_pods.items:
|
||||||
if f"{self.cluster_info.app_name}-deployment" in p.metadata.name:
|
if p.metadata and p.metadata.name:
|
||||||
pods.append(p)
|
if f"{self.cluster_info.app_name}-deployment" in p.metadata.name:
|
||||||
|
pods.append(p)
|
||||||
|
|
||||||
if not pods:
|
if not pods:
|
||||||
return
|
return
|
||||||
@@ -379,21 +486,40 @@ class K8sDeployer(Deployer):
|
|||||||
ip = "?"
|
ip = "?"
|
||||||
tls = "?"
|
tls = "?"
|
||||||
try:
|
try:
|
||||||
ingress = self.networking_api.read_namespaced_ingress(namespace=self.k8s_namespace,
|
cluster_ingress = self.cluster_info.get_ingress()
|
||||||
name=self.cluster_info.get_ingress().metadata.name)
|
if cluster_ingress is None or cluster_ingress.metadata is None:
|
||||||
|
return
|
||||||
|
ingress = cast(
|
||||||
|
client.V1Ingress,
|
||||||
|
self.networking_api.read_namespaced_ingress(
|
||||||
|
namespace=self.k8s_namespace,
|
||||||
|
name=cluster_ingress.metadata.name,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
if not ingress.spec or not ingress.spec.tls or not ingress.spec.rules:
|
||||||
|
return
|
||||||
|
|
||||||
cert = self.custom_obj_api.get_namespaced_custom_object(
|
cert = cast(
|
||||||
group="cert-manager.io",
|
Dict[str, Any],
|
||||||
version="v1",
|
self.custom_obj_api.get_namespaced_custom_object(
|
||||||
namespace=self.k8s_namespace,
|
group="cert-manager.io",
|
||||||
plural="certificates",
|
version="v1",
|
||||||
name=ingress.spec.tls[0].secret_name
|
namespace=self.k8s_namespace,
|
||||||
|
plural="certificates",
|
||||||
|
name=ingress.spec.tls[0].secret_name,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
hostname = ingress.spec.rules[0].host
|
hostname = ingress.spec.rules[0].host
|
||||||
ip = ingress.status.load_balancer.ingress[0].ip
|
if ingress.status and ingress.status.load_balancer:
|
||||||
|
lb_ingress = ingress.status.load_balancer.ingress
|
||||||
|
if lb_ingress:
|
||||||
|
ip = lb_ingress[0].ip or "?"
|
||||||
|
cert_status = cert.get("status", {})
|
||||||
tls = "notBefore: %s; notAfter: %s; names: %s" % (
|
tls = "notBefore: %s; notAfter: %s; names: %s" % (
|
||||||
cert["status"]["notBefore"], cert["status"]["notAfter"], ingress.spec.tls[0].hosts
|
cert_status.get("notBefore", "?"),
|
||||||
|
cert_status.get("notAfter", "?"),
|
||||||
|
ingress.spec.tls[0].hosts,
|
||||||
)
|
)
|
||||||
except: # noqa: E722
|
except: # noqa: E722
|
||||||
pass
|
pass
|
||||||
@@ -406,10 +532,16 @@ class K8sDeployer(Deployer):
|
|||||||
print("Pods:")
|
print("Pods:")
|
||||||
|
|
||||||
for p in pods:
|
for p in pods:
|
||||||
|
if not p.metadata:
|
||||||
|
continue
|
||||||
|
ns = p.metadata.namespace
|
||||||
|
name = p.metadata.name
|
||||||
if p.metadata.deletion_timestamp:
|
if p.metadata.deletion_timestamp:
|
||||||
print(f"\t{p.metadata.namespace}/{p.metadata.name}: Terminating ({p.metadata.deletion_timestamp})")
|
ts = p.metadata.deletion_timestamp
|
||||||
|
print(f"\t{ns}/{name}: Terminating ({ts})")
|
||||||
else:
|
else:
|
||||||
print(f"\t{p.metadata.namespace}/{p.metadata.name}: Running ({p.metadata.creation_timestamp})")
|
ts = p.metadata.creation_timestamp
|
||||||
|
print(f"\t{ns}/{name}: Running ({ts})")
|
||||||
|
|
||||||
def ps(self):
|
def ps(self):
|
||||||
self.connect_api()
|
self.connect_api()
|
||||||
@@ -424,19 +556,22 @@ class K8sDeployer(Deployer):
|
|||||||
for c in p.spec.containers:
|
for c in p.spec.containers:
|
||||||
if c.ports:
|
if c.ports:
|
||||||
for prt in c.ports:
|
for prt in c.ports:
|
||||||
ports[str(prt.container_port)] = [AttrDict({
|
ports[str(prt.container_port)] = [
|
||||||
"HostIp": pod_ip,
|
AttrDict(
|
||||||
"HostPort": prt.container_port
|
{"HostIp": pod_ip, "HostPort": prt.container_port}
|
||||||
})]
|
)
|
||||||
|
]
|
||||||
|
|
||||||
ret.append(AttrDict({
|
ret.append(
|
||||||
"id": f"{p.metadata.namespace}/{p.metadata.name}",
|
AttrDict(
|
||||||
"name": p.metadata.name,
|
{
|
||||||
"namespace": p.metadata.namespace,
|
"id": f"{p.metadata.namespace}/{p.metadata.name}",
|
||||||
"network_settings": AttrDict({
|
"name": p.metadata.name,
|
||||||
"ports": ports
|
"namespace": p.metadata.namespace,
|
||||||
})
|
"network_settings": AttrDict({"ports": ports}),
|
||||||
}))
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
@@ -459,15 +594,17 @@ class K8sDeployer(Deployer):
|
|||||||
else:
|
else:
|
||||||
k8s_pod_name = pods[0]
|
k8s_pod_name = pods[0]
|
||||||
containers = containers_in_pod(self.core_api, k8s_pod_name)
|
containers = containers_in_pod(self.core_api, k8s_pod_name)
|
||||||
# If the pod is not yet started, the logs request below will throw an exception
|
# If pod not started, logs request below will throw an exception
|
||||||
try:
|
try:
|
||||||
log_data = ""
|
log_data = ""
|
||||||
for container in containers:
|
for container in containers:
|
||||||
container_log = self.core_api.read_namespaced_pod_log(k8s_pod_name, namespace="default", container=container)
|
container_log = self.core_api.read_namespaced_pod_log(
|
||||||
|
k8s_pod_name, namespace="default", container=container
|
||||||
|
)
|
||||||
container_log_lines = container_log.splitlines()
|
container_log_lines = container_log.splitlines()
|
||||||
for line in container_log_lines:
|
for line in container_log_lines:
|
||||||
log_data += f"{container}: {line}\n"
|
log_data += f"{container}: {line}\n"
|
||||||
except client.exceptions.ApiException as e:
|
except ApiException as e:
|
||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print(f"Error from read_namespaced_pod_log: {e}")
|
print(f"Error from read_namespaced_pod_log: {e}")
|
||||||
log_data = "******* No logs available ********\n"
|
log_data = "******* No logs available ********\n"
|
||||||
@@ -476,34 +613,85 @@ class K8sDeployer(Deployer):
|
|||||||
def update(self):
|
def update(self):
|
||||||
self.connect_api()
|
self.connect_api()
|
||||||
ref_deployment = self.cluster_info.get_deployment()
|
ref_deployment = self.cluster_info.get_deployment()
|
||||||
|
if not ref_deployment or not ref_deployment.metadata:
|
||||||
|
return
|
||||||
|
ref_name = ref_deployment.metadata.name
|
||||||
|
if not ref_name:
|
||||||
|
return
|
||||||
|
|
||||||
deployment = self.apps_api.read_namespaced_deployment(
|
deployment = cast(
|
||||||
name=ref_deployment.metadata.name,
|
client.V1Deployment,
|
||||||
namespace=self.k8s_namespace
|
self.apps_api.read_namespaced_deployment(
|
||||||
|
name=ref_name, namespace=self.k8s_namespace
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
if not deployment.spec or not deployment.spec.template:
|
||||||
|
return
|
||||||
|
template_spec = deployment.spec.template.spec
|
||||||
|
if not template_spec or not template_spec.containers:
|
||||||
|
return
|
||||||
|
|
||||||
new_env = ref_deployment.spec.template.spec.containers[0].env
|
ref_spec = ref_deployment.spec
|
||||||
for container in deployment.spec.template.spec.containers:
|
if ref_spec and ref_spec.template and ref_spec.template.spec:
|
||||||
old_env = container.env
|
ref_containers = ref_spec.template.spec.containers
|
||||||
if old_env != new_env:
|
if ref_containers:
|
||||||
container.env = new_env
|
new_env = ref_containers[0].env
|
||||||
|
for container in template_spec.containers:
|
||||||
|
old_env = container.env
|
||||||
|
if old_env != new_env:
|
||||||
|
container.env = new_env
|
||||||
|
|
||||||
deployment.spec.template.metadata.annotations = {
|
template_meta = deployment.spec.template.metadata
|
||||||
"kubectl.kubernetes.io/restartedAt": datetime.utcnow()
|
if template_meta:
|
||||||
.replace(tzinfo=timezone.utc)
|
template_meta.annotations = {
|
||||||
.isoformat()
|
"kubectl.kubernetes.io/restartedAt": datetime.utcnow()
|
||||||
}
|
.replace(tzinfo=timezone.utc)
|
||||||
|
.isoformat()
|
||||||
|
}
|
||||||
|
|
||||||
self.apps_api.patch_namespaced_deployment(
|
self.apps_api.patch_namespaced_deployment(
|
||||||
name=ref_deployment.metadata.name,
|
name=ref_name,
|
||||||
namespace=self.k8s_namespace,
|
namespace=self.k8s_namespace,
|
||||||
body=deployment
|
body=deployment,
|
||||||
)
|
)
|
||||||
|
|
||||||
def run(self, image: str, command=None, user=None, volumes=None, entrypoint=None, env={}, ports=[], detach=False):
|
def run(
|
||||||
|
self,
|
||||||
|
image: str,
|
||||||
|
command=None,
|
||||||
|
user=None,
|
||||||
|
volumes=None,
|
||||||
|
entrypoint=None,
|
||||||
|
env={},
|
||||||
|
ports=[],
|
||||||
|
detach=False,
|
||||||
|
):
|
||||||
# We need to figure out how to do this -- check why we're being called first
|
# We need to figure out how to do this -- check why we're being called first
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def run_job(self, job_name: str, helm_release: Optional[str] = None):
|
||||||
|
if not opts.o.dry_run:
|
||||||
|
from stack_orchestrator.deploy.k8s.helm.job_runner import run_helm_job
|
||||||
|
|
||||||
|
# Check if this is a helm-based deployment
|
||||||
|
chart_dir = self.deployment_dir / "chart"
|
||||||
|
if not chart_dir.exists():
|
||||||
|
# TODO: Implement job support for compose-based K8s deployments
|
||||||
|
raise Exception(
|
||||||
|
f"Job support is only available for helm-based "
|
||||||
|
f"deployments. Chart directory not found: {chart_dir}"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Run the job using the helm job runner
|
||||||
|
run_helm_job(
|
||||||
|
chart_dir=chart_dir,
|
||||||
|
job_name=job_name,
|
||||||
|
release=helm_release,
|
||||||
|
namespace=self.k8s_namespace,
|
||||||
|
timeout=600,
|
||||||
|
verbose=opts.o.verbose,
|
||||||
|
)
|
||||||
|
|
||||||
def is_kind(self):
|
def is_kind(self):
|
||||||
return self.type == "k8s-kind"
|
return self.type == "k8s-kind"
|
||||||
|
|
||||||
@@ -519,6 +707,20 @@ class K8sDeployerConfigGenerator(DeployerConfigGenerator):
|
|||||||
def generate(self, deployment_dir: Path):
|
def generate(self, deployment_dir: Path):
|
||||||
# No need to do this for the remote k8s case
|
# No need to do this for the remote k8s case
|
||||||
if self.type == "k8s-kind":
|
if self.type == "k8s-kind":
|
||||||
|
# Generate high-memlock-spec.json if unlimited_memlock is enabled.
|
||||||
|
# Must be done before generate_kind_config() which references it.
|
||||||
|
if self.deployment_context.spec.get_unlimited_memlock():
|
||||||
|
spec_content = generate_high_memlock_spec_json()
|
||||||
|
spec_file = deployment_dir.joinpath(
|
||||||
|
constants.high_memlock_spec_filename
|
||||||
|
)
|
||||||
|
if opts.o.debug:
|
||||||
|
print(
|
||||||
|
f"Creating high-memlock spec for unlimited memlock: {spec_file}"
|
||||||
|
)
|
||||||
|
with open(spec_file, "w") as output_file:
|
||||||
|
output_file.write(spec_content)
|
||||||
|
|
||||||
# Check the file isn't already there
|
# Check the file isn't already there
|
||||||
# Get the config file contents
|
# Get the config file contents
|
||||||
content = generate_kind_config(deployment_dir, self.deployment_context)
|
content = generate_kind_config(deployment_dir, self.deployment_context)
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
# Copyright © 2025 Vulcanize
|
||||||
|
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http:#www.gnu.org/licenses/>.
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user