generated from dfds/aws-modules-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
313 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -196,3 +196,6 @@ cython_debug/ | |
|
||
.trunk/ | ||
*.pem | ||
|
||
# Auto-generated files | ||
auto-generated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
FROM python:slim | ||
|
||
RUN apt update && \ | ||
apt install -y curl libpq-dev less jq tar unzip | ||
|
||
|
||
# Adding GitHub public SSH key to known hosts | ||
RUN ssh -T -o "StrictHostKeyChecking no" -o "PubkeyAuthentication no" [email protected] || true | ||
|
||
# ======================================== | ||
# TERRAFORM DOCS | ||
# ======================================== | ||
ENV TERRAFORM_DOCS_VERSION=0.17.0 | ||
RUN export BUILD_ARCHITECTURE=$(uname -m); \ | ||
if [ "$BUILD_ARCHITECTURE" = "x86_64" ]; then export BUILD_ARCHITECTURE_ARCH=amd64; fi; \ | ||
if [ "$BUILD_ARCHITECTURE" = "aarch64" ]; then export BUILD_ARCHITECTURE_ARCH=arm64; fi; \ | ||
curl -sSLo ./terraform-docs.tar.gz https://terraform-docs.io/dl/v${TERRAFORM_DOCS_VERSION}/terraform-docs-v${TERRAFORM_DOCS_VERSION}-linux-${BUILD_ARCHITECTURE_ARCH}.tar.gz | ||
RUN tar -xzf terraform-docs.tar.gz | ||
RUN chmod +x terraform-docs | ||
RUN mv terraform-docs /usr/local/bin/ | ||
|
||
# ======================================== | ||
# TERRAFORM | ||
# ======================================== | ||
|
||
ENV TERRAFORM_VERSION=1.4.6 | ||
|
||
RUN export BUILD_ARCHITECTURE=$(uname -m); \ | ||
if [ "$BUILD_ARCHITECTURE" = "x86_64" ]; then export BUILD_ARCHITECTURE_ARCH=amd64; fi; \ | ||
if [ "$BUILD_ARCHITECTURE" = "aarch64" ]; then export BUILD_ARCHITECTURE_ARCH=arm64; fi; \ | ||
curl -Os https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_${BUILD_ARCHITECTURE_ARCH}.zip \ | ||
&& unzip terraform_${TERRAFORM_VERSION}_linux_${BUILD_ARCHITECTURE_ARCH}.zip \ | ||
&& mv terraform /usr/local/bin/ \ | ||
&& terraform -install-autocomplete | ||
|
||
|
||
COPY scaffolding/scripts /scripts | ||
COPY scaffolding/templates /templates | ||
|
||
ENTRYPOINT [ "bash", "/scripts/entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Run docker file: | ||
|
||
cd /dfds/aws-modules-rds/tools | ||
|
||
```bash | ||
docker build -t scaffold . | ||
``` | ||
|
||
mkdir auto-generated | ||
|
||
```bash | ||
docker run -v <absolute-path>/aws-modules-rds/:/input -v <absolute-path>/aws-modules-rds/tools/auto-generated:/output scaffold:latest | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
scripts_path="/scripts" | ||
source_module_path="/input" | ||
|
||
if [ ! -d "/output" ]; then | ||
echo "output folder does not exist" | ||
exit 1 | ||
fi | ||
|
||
# TERRAFORM DOCS | ||
output_json_file="/tmp/doc.json" | ||
|
||
# TERRAFORM | ||
source_json_doc=$output_json_file | ||
generated_tf_module_data="/tmp/tf_module.json" | ||
tf_module_template="/templates/main.tf.template" | ||
tf_module_output="/output/terraform/module.tf" | ||
tf_output_folders="/output/terraform" | ||
mkdir -p $tf_output_folders | ||
|
||
# DOCKER | ||
docker_compose_template="/templates/compose.yml.template" | ||
docker_compose_output="/output/docker/compose.yml" | ||
docker_env_template="/templates/.env.template" | ||
docker_env_output="/output/docker/.env" | ||
docker_script_template="/templates/restore.sh.template" | ||
docker_script_output="/output/docker/restore.sh" | ||
docker_output_folders="/output/docker" | ||
|
||
mkdir -p $docker_output_folders | ||
|
||
if [ -z "$(ls -a $source_module_path)" ]; then | ||
echo "empty $source_module_path" | ||
exit 1 | ||
fi | ||
|
||
|
||
# TODO: CHECK FOR output folder mount | ||
|
||
# 1) Generate docs for all modules in a repo | ||
terraform-docs json --show "all" $source_module_path --output-file $output_json_file | ||
|
||
# # 2) Generate TF files | ||
python3 $scripts_path/generate_tf_module.py --source-tf-doc $source_json_doc --temp-work-folder $generated_tf_module_data --tf-module-template $tf_module_template --tf-output-path $tf_module_output | ||
|
||
# # 3) Format TF files | ||
terraform fmt $tf_output_folders | ||
|
||
# 3) Generate Docker files | ||
python3 $scripts_path/generate_docker.py --docker-compose-template $docker_compose_template --docker-compose-output $docker_compose_output --env-template $docker_env_template --env-output $docker_env_output --docker-script-template $docker_script_template --docker-script-output $docker_script_output | ||
# 4) Generate pipeline files | ||
# TODO: generate pipeline |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"""This scripts generates boiler plates for using docker compose files. Input: Template files, Output: Docker compose files.""" | ||
from string import Template | ||
import shutil | ||
import argparse | ||
|
||
parser = argparse.ArgumentParser( | ||
prog='Docker Compose Generator', | ||
description='This scripts generates boiler plates for using docker compose files. Input: Template files, Output: Docker compose files.', | ||
epilog='.') | ||
parser.add_argument('--docker-compose-template', type=str, required=True, help='The template file for the docker compose.') | ||
parser.add_argument('--docker-compose-output', type=str, required=True, help='The output path for the docker compose.') | ||
parser.add_argument('--env-template', type=str, required=True, help='The template file for the env file.') | ||
parser.add_argument('--env-output', type=str, required=True, help='The output path for the env file.') | ||
parser.add_argument('--docker-script-template', type=str, required=True, help='The template file for the script that is used by the generated docker compose file.') | ||
parser.add_argument('--docker-script-output', type=str, required=True, help='The output path for the script used that is by the generated docker compose file.') | ||
args = parser.parse_args() | ||
|
||
docker_template = args.docker_compose_template | ||
output_docker = args.docker_compose_output | ||
env_template = args.env_template | ||
output_env = args.env_output | ||
docker_script_template = args.docker_script_template | ||
output_docker_script = args.docker_script_output | ||
|
||
vars_sub = { | ||
'pgpassword': 'example', | ||
'pgdatabase': 'example', | ||
'pghost': 'example', | ||
'pgport': 'example', | ||
'pguser': 'example' | ||
} | ||
|
||
with open(env_template, 'r', encoding='UTF-8') as f: | ||
src = Template(f.read()) | ||
result = src.substitute(vars_sub) | ||
|
||
with open(output_env, "w", encoding='UTF-8') as f: | ||
f.write(result) | ||
|
||
shutil.copy(docker_template, output_docker) | ||
|
||
shutil.copy(docker_script_template, output_docker_script) |
Oops, something went wrong.