Skip to content

Commit b02d4f6

Browse files
committed
updated action
1 parent a80f5d6 commit b02d4f6

18 files changed

+921
-2
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: '[BUG]'
5+
labels: 'bug'
6+
assignees: ''
7+
8+
---
9+
10+
**Describe the bug**
11+
A clear and concise description of what the bug is.
12+
13+
**To Reproduce**
14+
Steps to reproduce the behavior:
15+
1. Go to '...'
16+
2. Click on '....'
17+
3. Scroll down to '....'
18+
4. See error
19+
20+
**Expected behavior**
21+
A clear and concise description of what you expected to happen.
22+
23+
**Screenshots**
24+
If applicable, add screenshots to help explain your problem.
25+
26+
**Desktop (please complete the following information):**
27+
- OS: [e.g. iOS]
28+
- Browser [e.g. chrome, safari]
29+
- Version [e.g. 22]
30+
31+
**Smartphone (please complete the following information):**
32+
- Device: [e.g. iPhone6]
33+
- OS: [e.g. iOS8.1]
34+
- Browser [e.g. stock browser, safari]
35+
- Version [e.g. 22]
36+
37+
**Additional context**
38+
Add any other context about the problem here.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: "[FEATURE]"
5+
labels: enhancement
6+
assignees: ''
7+
8+
---
9+
10+
**Feature Description**
11+
A clear and concise description of what you want to happen.
12+
13+
**Example(s)**
14+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
15+
16+
**Possible Approaches or Libraries to Consider**
17+
A clear and concise description of any alternative solutions or features you've considered.
18+
19+
**Additional context**
20+
Add any other context or screenshots about the feature request here.

.github/ISSUE_TEMPLATE/question.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
name: Question
3+
about: Pose a question to the StackQL team
4+
title: "[QUESTION]"
5+
labels: question
6+
assignees: ''
7+
8+
---
9+
10+
11+
## Question
12+
13+
This channel is an opportunity to ask ad-hoc questions to the `stackql` team. This channel is in lieu of an official platform for ongoing discussions and questions. Please ask your question :)
14+
15+
**Note**: Questions over github issues will be deprecated and retired once we settle on a platform / process ongoing.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Test StackQL Deploy Action
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
jobs:
8+
stackql-actions-test:
9+
name: StackQL Actions Test
10+
runs-on: ubuntu-latest
11+
env:
12+
GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}
13+
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4.1.7
17+
18+
- name: Run StackQL Deploy Action
19+
uses: ./
20+
with:
21+
command: 'test'
22+
stack_dir: 'examples/k8s-the-hard-way'
23+
stack_env: 'dev'
24+
env_vars: 'GOOGLE_PROJECT=stackql-k8s-the-hard-way-demo'

README.md

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,62 @@
1-
# stackql-deploy-action
2-
Runs stackql-deploy in your GitHub Actions workflow.
1+
[![StackQL Deploy Actions Test](https://github.com/stackql/stackql-deploy/actions/workflows/stackql-deploy-actions-test.yml/badge.svg)](https://github.com/stackql/stackql-deploy/actions/workflows/stackql-deploy-actions-test.yml)
2+
3+
# stackql-deploy
4+
Github Action to execute `stackql-deploy` to deploy or test a stack. [`stackql-deploy`](https://github.com/stackql/stackql-deploy) is a declarative, state-file-less IaC framework, based upon [`stackql`](https://github.com/stackql/stackql) queries.
5+
6+
# Usage
7+
8+
## Provider Authentication
9+
Authentication to StackQL providers is done via environment variables source from GitHub Actions Secrets. To learn more about authentication, see the setup instructions for your provider or providers at the [StackQL Provider Registry Docs](https://stackql.io/registry).
10+
11+
## Inputs
12+
- **`command`** - stackql-deploy command to run (__`build`__ or __`test`__)
13+
- **`stack_dir`** - repo directory containing `stackql_manifest.yml` and `resources` dir
14+
- **`stack_env`** - environment to deploy or test (e.g., `dev`, `prod`)
15+
- **`env_vars`** - (optional) environment variables or secrets imported into a stack (format: __`KEY=value,KEY2=value2`__)
16+
- **`env_file`** - (optional) environment variables sourced from a file
17+
- **`show_queries`** - (optional) show queries run in the output logs
18+
- **`log_level`** - (optional) set the logging level (__`INFO`__ or __`DEBUG`__, defaults to __`INFO`__)
19+
- **`dry_run`** - (optional) perform a dry run of the operation
20+
- **`custom_registry`** - (optional) custom registry URL to be used for stackql
21+
- **`on_failure`** - (optional) action on failure (*not implemented yet*)
22+
23+
## Examples
24+
25+
### Deploy a stack
26+
27+
this example shows how to build a stack (`examples/k8s-the-hard-way`) for a `dev` environment:
28+
29+
```yaml
30+
...
31+
jobs:
32+
stackql-actions-test:
33+
name: StackQL Actions Test
34+
runs-on: ubuntu-latest
35+
env:
36+
GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }} # add additional cloud provider creds here as needed
37+
38+
steps:
39+
- name: Checkout
40+
uses: actions/checkout@v4
41+
42+
- name: Deploy a Stack
43+
uses: stackql/setup-deploy@v1.0.0
44+
with:
45+
command: 'build'
46+
stack-dir: 'examples/k8s-the-hard-way'
47+
stack-env: 'dev'
48+
env-vars: 'GOOGLE_PROJECT=stackql-k8s-the-hard-way-demo'
49+
```
50+
51+
this example shows how to test stack for a given environment:
52+
53+
```yaml
54+
...
55+
- name: Test a Stack
56+
uses: stackql/setup-deploy@v1.0.0
57+
with:
58+
command: 'test'
59+
stack-dir: 'examples/k8s-the-hard-way'
60+
stack-env: 'sit'
61+
env-vars: 'GOOGLE_PROJECT=stackql-k8s-the-hard-way-demo'
62+
```

action.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: 'stackql-deploy'
2+
description: 'Deploy and test stacks using stackql-deploy'
3+
inputs:
4+
command:
5+
description: 'stackql-deploy command to run (`build` or `test`)'
6+
required: true
7+
stack_dir:
8+
description: 'repo directory containing `stackql_manifest.yml` and `resources` dir'
9+
required: true
10+
stack_env:
11+
description: 'environment to deploy or test (e.g., `dev`, `prod`)'
12+
required: true
13+
env_vars:
14+
description: 'environment variables or secrets imported into a stack (format: `KEY=value,KEY2=value2`)'
15+
required: false
16+
env_file:
17+
description: 'environment variables sourced from a file'
18+
required: false
19+
show_queries:
20+
description: 'show queries run in the output logs'
21+
required: false
22+
log_level:
23+
description: 'set the logging level (`INFO` or `DEBUG`, defaults to `INFO`)'
24+
required: false
25+
dry_run:
26+
description: 'perform a dry run of the operation'
27+
required: false
28+
custom_registry:
29+
description: 'custom registry URL to be used for stackql'
30+
required: false
31+
on_failure:
32+
description: 'action on failure'
33+
required: false
34+
35+
runs:
36+
using: 'composite'
37+
steps:
38+
- name: Install Python
39+
uses: actions/setup-python@v5.1.1
40+
with:
41+
python-version: '3.10'
42+
43+
- name: Install stackql-deploy
44+
shell: bash
45+
run: pip install -q stackql-deploy pyyaml || { echo "pip install failed"; exit 1; }
46+
47+
- name: Run stackql-deploy
48+
shell: bash
49+
run: |
50+
ENV_OPTS=""
51+
if [ -n "${{ inputs.env_vars }}" ]; then
52+
IFS=',' read -r -a env_array <<< "${{ inputs.env_vars }}"
53+
for env_var in "${env_array[@]}"; do
54+
ENV_OPTS+=" -e $env_var"
55+
done
56+
fi
57+
58+
STACKQL_DEPLOY_CMD="stackql-deploy ${{ inputs.command }} ${{ inputs.stack_dir }} ${{ inputs.stack_env }}"
59+
60+
if [ -n "${{ inputs.env_file }}" ]; then
61+
STACKQL_DEPLOY_CMD+=" --env-file ${{ inputs.env_file }}"
62+
fi
63+
if [ "${{ inputs.show_queries }}" == "true" ]; then
64+
STACKQL_DEPLOY_CMD+=" --show-queries"
65+
fi
66+
if [ -n "${{ inputs.log_level }}" ]; then
67+
STACKQL_DEPLOY_CMD+=" --log-level ${{ inputs.log_level }}"
68+
fi
69+
if [ "${{ inputs.dry_run }}" == "true" ]; then
70+
STACKQL_DEPLOY_CMD+=" --dry-run"
71+
fi
72+
if [ -n "${{ inputs.custom_registry }}" ]; then
73+
STACKQL_DEPLOY_CMD+=" --custom-registry ${{ inputs.custom_registry }}"
74+
fi
75+
if [ -n "${{ inputs.on_failure }}" ]; then
76+
STACKQL_DEPLOY_CMD+=" --on-failure ${{ inputs.on_failure }}"
77+
fi
78+
79+
echo "executing: $STACKQL_DEPLOY_CMD $ENV_OPTS"
80+
$STACKQL_DEPLOY_CMD $ENV_OPTS
81+
82+
branding:
83+
icon: 'server'
84+
color: 'blue'

examples/k8s-the-hard-way/README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# example `stackql-deploy` stack
2+
3+
Based upon the [Kubernetes the Hard Way](https://github.com/kelseyhightower/kubernetes-the-hard-way) project.
4+
5+
## about `stackql-deploy`
6+
7+
[`stackql-deploy`](https://pypi.org/project/stackql-deploy/) is a multi cloud deployment automation and testing framework which is an alternative to Terraform or similar IaC tools. `stackql-deploy` uses a declarative model/ELT based approach to cloud resource deployment (inspired by [`dbt`](https://www.getdbt.com/)). Advantages of `stackql-deploy` include:
8+
9+
- declarative framework
10+
- no state file (state is determined from the target environment)
11+
- multi-cloud/omni-cloud ready
12+
- includes resource tests which can include secure config tests
13+
14+
## instaling `stackql-deploy`
15+
16+
`stackql-deploy` is installed as a python based CLI using...
17+
18+
```bash
19+
pip install stackql-deploy
20+
```
21+
22+
## getting started with `stackql-deploy`
23+
24+
Once installed, use the `init` command to scaffold a sample project directory to get started:
25+
26+
```bash
27+
stackql-deploy init k8s-the-hard-way
28+
```
29+
30+
this will create a directory named `k8s-the-hard-way` which can be updated for your stack, as you can see in this project.
31+
32+
## deploying using `stackql-deploy`
33+
34+
```bash
35+
export GOOGLE_CREDENTIALS=$(cat ./creds.json)
36+
# deploy a stack
37+
stackql-deploy build \
38+
k8s-the-hard-way \
39+
dev \
40+
-e GOOGLE_PROJECT=stackql-k8s-the-hard-way-demo \
41+
--dry-run \
42+
--log-leve DEBUG
43+
44+
# test a stack
45+
stackql-deploy test \
46+
examples/k8s-the-hard-way \
47+
dev \
48+
-e GOOGLE_PROJECT=stackql-k8s-the-hard-way-demo \
49+
--dry-run
50+
51+
# teardown a stack
52+
stackql-deploy teardown \
53+
k8s-the-hard-way \
54+
dev \
55+
-e GOOGLE_PROJECT=stackql-k8s-the-hard-way-demo \
56+
--dry-run
57+
```
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*+ preflight */
2+
SELECT COUNT(*) as count FROM google.compute.firewalls
3+
WHERE project = '{{ project }}'
4+
AND name = '{{ fw_name }}'
5+
6+
/*+ create */
7+
INSERT INTO google.compute.firewalls
8+
(
9+
project,
10+
data__name,
11+
data__network,
12+
data__direction,
13+
data__sourceRanges,
14+
data__allowed
15+
)
16+
SELECT
17+
'{{ project }}',
18+
'{{ fw_name}}',
19+
'{{ vpc_link }}',
20+
'{{ fw_direction }}',
21+
'{{ fw_source_ranges }}',
22+
'{{ fw_allowed }}'
23+
24+
/*+ postdeploy, retries=5, retry_delay=10 */
25+
SELECT COUNT(*) as count FROM google.compute.firewalls
26+
WHERE project = '{{ project }}'
27+
AND name = '{{ fw_name }}'
28+
AND network = '{{ vpc_link }}'
29+
30+
/*+ delete, retries=20, retry_delay=10 */
31+
DELETE FROM google.compute.firewalls
32+
WHERE project = '{{ project }}'
33+
AND firewall = '{{ fw_name }}'
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*+ preflight */
2+
SELECT COUNT(*) as count FROM google.compute.forwarding_rules
3+
WHERE region = '{{ region }}'
4+
AND project = '{{ project }}'
5+
AND forwardingRule = '{{ forwarding_rule_name }}'
6+
7+
/*+ create */
8+
INSERT INTO google.compute.forwarding_rules(
9+
project,
10+
region,
11+
data__name,
12+
data__IPAddress,
13+
data__loadBalancingScheme,
14+
data__portRange,
15+
data__target
16+
)
17+
SELECT
18+
'{{ project }}',
19+
'{{ region }}',
20+
'{{ forwarding_rule_name }}',
21+
'{{ address }}',
22+
'{{ forwarding_rule_load_balancing_scheme }}',
23+
'{{ forwarding_rule_port_range }}',
24+
'{{ target_pool_link }}'
25+
26+
/*+ postdeploy, retries=5, retry_delay=10 */
27+
SELECT COUNT(*) as count FROM google.compute.forwarding_rules
28+
WHERE region = '{{ region }}'
29+
AND project = '{{ project }}'
30+
AND forwardingRule = '{{ forwarding_rule_name }}'
31+
32+
/*+ delete, retries=20, retry_delay=10 */
33+
DELETE FROM google.compute.forwarding_rules
34+
WHERE project = '{{ project }}'
35+
AND region = '{{ region }}'
36+
AND forwardingRule = '{{ forwarding_rule_name }}'
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/*+ exports */
2+
SELECT JSON_GROUP_ARRAY(json_object('instance', selfLink)) as controller_instances
3+
FROM google.compute.instances
4+
WHERE project = '{{ project }}'
5+
AND zone = '{{ default_zone }}'
6+
AND name like '%-{{ stack_env }}-controller-%'

0 commit comments

Comments
 (0)