Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Templatize via Cookiecutter for enhanced audience utility #10

Merged
merged 45 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
552c2a2
add cookiecutter json defaults
d33bs Sep 20, 2023
9516ea7
add cookiecutter dependency
d33bs Sep 20, 2023
e820fe6
utilize cookiecutter values within tf and docs
d33bs Sep 20, 2023
df23933
remove comments and final comma
d33bs Sep 20, 2023
e420e30
move to template directory structure
d33bs Sep 20, 2023
b9f5f09
new default values
d33bs Sep 20, 2023
15be5c2
update tests for template
d33bs Sep 20, 2023
28473aa
lint tf readme
d33bs Sep 20, 2023
818f465
update template test to run git init for lint chks
d33bs Sep 20, 2023
5921e74
update template readme
d33bs Sep 20, 2023
6673aec
remove irrelevant pre-commit hooks for template
d33bs Sep 20, 2023
bc40527
Update readme.md
d33bs Sep 20, 2023
97a598d
Update readme.md
d33bs Sep 20, 2023
f38dad2
test workflow on github
d33bs Sep 20, 2023
5727ecb
init git name and email
d33bs Sep 20, 2023
95f9236
move from gh to dagger action for template test
d33bs Sep 20, 2023
7e34ed6
formatting
d33bs Sep 20, 2023
f0ab421
add testing notes
d33bs Sep 20, 2023
9d268e2
linting
d33bs Sep 20, 2023
03f5780
formatting for readability
d33bs Sep 20, 2023
48ffdca
remove dev branch for gh actions testing
d33bs Sep 20, 2023
c3c2419
specifics in action docs
d33bs Sep 20, 2023
db0f605
json linting additions + application
d33bs Sep 20, 2023
eebb4d7
add gh actions for pre-commit checks on template
d33bs Sep 20, 2023
855b6a4
move to using root terraform.tfvars file
d33bs Sep 20, 2023
10b6c3b
Revert "move to using root terraform.tfvars file"
d33bs Sep 20, 2023
8b678bc
update versions of tf
d33bs Sep 20, 2023
aa3f381
remove no longer applicable files
d33bs Sep 20, 2023
a4e7e48
update to use variables.tfvars
d33bs Sep 20, 2023
cf9aa3b
update readme content
d33bs Sep 20, 2023
4ffc201
rename and add tfvars where appropriate
d33bs Sep 22, 2023
d2d1640
update template tf readme files
d33bs Sep 22, 2023
f7b9e26
dagger testing updates for corrections
d33bs Sep 22, 2023
9eaaa68
remove readme for testing
d33bs Sep 22, 2023
7fd59cd
simplify and build distinct tests
d33bs Sep 22, 2023
3f4388a
readd readme
d33bs Sep 22, 2023
0ab2860
update tests to be inclusive as a group
d33bs Sep 22, 2023
d30a753
formatting for cue file
d33bs Sep 22, 2023
acfc9af
lint cuefile
d33bs Sep 22, 2023
f8a486f
ignore readmes under template terraform
d33bs Sep 22, 2023
3b288be
ignore template md's
d33bs Sep 22, 2023
f109c90
update to use appropriate names for state mgmt
d33bs Sep 22, 2023
05f010f
add mock gcp credentials for testing
d33bs Sep 22, 2023
88aff9e
formatting and ignoring mock key for checks
d33bs Sep 22, 2023
16537a7
Updated references to variables.tfvars with the new filename, terrafo…
falquaddoomi Sep 28, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/pre-commit-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
# used for running pre-commit checks
name: pre-commit checks

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
run_pre_commit_tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: "3.10"
- uses: pre-commit/action@v3.0.0
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
---
# note: this workflow definition will create a project from
# the cookiecutter template to test the results through dagger
name: run tests

on:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,6 @@ hashicorp/

# tf credential ignore
utilities/data-provider/service-account.json

# tests
tests/
21 changes: 3 additions & 18 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ repos:
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-json
- id: pretty-format-json
args: [--autofix, --no-sort-keys]
- id: check-yaml
- id: check-added-large-files
- id: check-toml
Expand All @@ -31,21 +34,3 @@ repos:
rev: 0.7.17
hooks:
- id: mdformat
# ignore terraform autogenerated docs
exclude: >
(?x)^(
terraform/.* |
terraform/.*/.*
)$
# linting for terraform
- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.83.3
hooks:
- id: terraform_docs
args:
- --hook-config=--path-to-file=README.md
- --hook-config=--add-to-existing-file=true
- --hook-config=--create-file-if-not-exist=true
- id: terraform_fmt
- id: terraform_tflint
- id: terraform_tfsec
8 changes: 8 additions & 0 deletions cookiecutter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"project_name": "lab-initiative-bucket",
"project_description": "Project for creating and managing a Cloud Storage bucket on Google Cloud.",
"project_author": "Username",
"project_license": "BSD-3-Clause License",
"project_gc_project": "cuhealthai-sandbox",
"project_gc_region": "us-central1"
}
588 changes: 507 additions & 81 deletions poetry.lock

Large diffs are not rendered by default.

47 changes: 16 additions & 31 deletions project.cue
Original file line number Diff line number Diff line change
Expand Up @@ -89,42 +89,32 @@ import "universe.dagger.io/docker"
// cue build for actions in this plan
_tf_build: docker.#Build & {
steps: [

docker.#Copy & {
input: _tf_pre_build.output
contents: filesystem
source: "./"
dest: "/lint"
dest: "/workdir"
exclude: ["./.pre-commit-config.yaml"]
},
]
}
bash.#Run & {
script: contents: """
# cd into the workdir
cd /workdir

}
# remove already existing test content
rm -rf ./tests/lab-initiative-bucket

// Convenience terraform build for implementation
#TerraformBuild: {
// client filesystem
filesystem: dagger.#FS
# install poetry and env
python3 -m pip install --no-cache-dir --upgrade poetry
poetry install --no-interaction --no-ansi

// output from the build
output: _tf_build.output
# run cookiecutter to create project from template
poetry run cookiecutter . --no-input --output-dir tests

// tf build
_tf_build: docker.#Build & {
steps: [
docker.#Pull & {
source: "hashicorp/terraform:1.4.6"
},
docker.#Run & {
command: {
name: "mkdir"
args: ["/workdir"]
}
},
docker.#Copy & {
contents: filesystem
source: "./"
dest: "/workdir/"
# move project from template into lintable dir for container
cp -r /workdir/tests/lab-initiative-bucket /lint
"""
},
]
}
Expand All @@ -147,11 +137,6 @@ dagger.#Plan & {
filesystem: client.filesystem."./".read.contents
}

// an internal terraform build for use with this repo
_tf_build: #TerraformBuild & {
filesystem: client.filesystem."./".read.contents
}

// an internal terraform build for use with this repo
_tf_lint_build: #TFLintBuild & {
filesystem: client.filesystem."./".read.contents
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ name = "gc-cloud-storage-bucket"
version = "0.0.1"
description = "Template for creating Cloud Storage bucket on Google Cloud."
authors = ["d33bs <dave.bunten@cuanschutz.edu>"]
license = "BSD-3-Clause license"
license = "BSD-3-Clause License"
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.10"
pre-commit = "^3.0.0"
cookiecutter = "^2.3.0"


[build-system]
Expand Down
66 changes: 66 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Google Cloud - Cloud Storage Bucket - Cookiecutter Template

```mermaid
flowchart LR
subgraph upload
files[("file(s)")]
data-provider["👤 Data Provider"]

end
subgraph download
data-receiver["👤 Data Receiver"]
files2[("file(s)")]
end
bucket[\"Cloud Storage\n Bucket"/]
files --> |to| bucket
data-provider --> |uploads| files
bucket --> |provides\naccess to| files2
files2 --> |received by| data-receiver

```

This project is a [Cookiecutter](https://github.com/cookiecutter/cookiecutter) template for creating a [Cloud Storage](https://cloud.google.com/storage/) bucket on [Google Cloud](https://cloud.google.com/) with a service account and related key to enable data or file upload and use.

The template uses [Terraform](https://developer.hashicorp.com/terraform/intro) to maintain cloud resources. See Terraform readme's under the `terraform` directory for documentation on Terraform elements.

## ✍️ Using the template

Install the latest version of Cookiecutter:

```shell
pip install cookiecutter
```

Generate a Python package project from the template in this repository:

```shell
python -m cookiecutter https://github.com/CU-DBMI/gc-cloud-storage-bucket.git
```

## 🧑‍💻 Development

Development for this repository is assisted by the following technologies:

- [Poetry](https://python-poetry.org/docs/): Used to help configure pre-commit for local development work.
- [Pre-commit](https://pre-commit.com): Used for performing checks within local development environment and via Github Actions automated testing. The following sub-items are used as checks through [pre-commit-terraform](https://github.com/antonbabenko/pre-commit-terraform) and require local installation when testing outside of Dagger:
- [terraform_docs](https://github.com/terraform-docs/terraform-docs/): Used to automatically generate Terraform-specific documentation.
- [tflint](https://github.com/terraform-linters/tflint): Used to perform static analysis (linting) on Terraform content.
- [tfsec](https://github.com/aquasecurity/tfsec): Used to perform security-focused static analysis (security linting) on Terraform content.
- [Dagger](https://docs.dagger.io/): Used to help orchestrate reproducible testing within local development environment and for automated testing.

### Testing

Tests for this project help ensure projects implemented from the Cookiecutter template function as expected.
These tests automatically will use the content found under the directory `{{ cookiecutter.project_name }}` to create a project and check the content.

Use [`dagger-cue`](https://docs.dagger.io/sdk/cue/) to run the tests.
These tests are also used by a Github Actions workflow to perform the same checks.

Example test command:

```shell
# update dagger project (only if needed)
dagger-cue project update
# run the tests
dagger-cue do test
```
39 changes: 0 additions & 39 deletions terraform/state-management/README.md

This file was deleted.

24 changes: 24 additions & 0 deletions {{ cookiecutter.project_name }}/.github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
name: run tests

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
run_tests:
runs-on: ubuntu-latest
env:
DAGGER_CACHE_FROM: type=gha,scope=gc-cloud-storage-bucket
DAGGER_CACHE_TO: type=gha,mode=max,scope=gc-cloud-storage-bucket
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Dagger
uses: dagger/dagger-for-github@v4
with:
cmds: |
project update
do test
Loading