Skip to content

Adding Dockerfile, update Dependencies for Python 3.12 #138

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 25 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/python
{
"name": "Python 3",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/python:1-3.12-bullseye",
"features": {
"ghcr.io/devcontainers/features/terraform:1": {}
}

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "pip3 install --user -r requirements.txt",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
11 changes: 11 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.devcontainer
.github
.gitignore
Dockerfile
docs
images
tests
README.md
eks-*.json
buildspec.yml
clearcache.sh
2 changes: 1 addition & 1 deletion .github/workflows/lint-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
id: setup-python
uses: actions/setup-python@v4
with:
python-version: "3.11"
python-version: "3.12"

#----------------------------------------------
# ----- install & configure poetry -----
Expand Down
41 changes: 41 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
FROM alpine:3.21 AS base

# Install required packages, create zser
RUN apk update && \
apk add --no-cache git python3 py3-pip graphviz opentofu binutils && \
ln -s /usr/bin/tofu /usr/bin/terraform && \
rm /usr/lib/python*/EXTERNALLY-MANAGED && \
python3 -m ensurepip && \
addgroup -S -g 1000 terravision && \
adduser -S -u 1000 -G terravision terravision && \
rm -rf /root/.cache && \
rm -rf /var/cache/apk/*

USER terravision

FROM base

# Copy and Install terravision dependencies
COPY --chown=terravision:terravision requirements.txt /opt/terravision/requirements.txt

RUN export PATH=$PATH:/home/terravision/.local/bin && \
cd /opt/terravision && \
pip install -r requirements.txt

ENV PATH=$PATH:/opt/terravision

# Install terravision
COPY --chown=terravision:terravision . /opt/terravision

RUN chmod +x /opt/terravision/terravision

USER root

RUN mkdir -p /project && \
chown -R terravision:terravision /project

USER terravision

WORKDIR /project

ENTRYPOINT [ "terravision" ]
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,22 @@ Use the `//` character for subfolders within Git repos if the code you want is u
$ terravision draw --source https://github.com/your-repo/terraform-examples.git//mysubfolder/secondfolder/
```

## Docker

You can run `terravision` as a Docker Container. All you need to do is to build the image:

```sh
docker build -t terravision .
```

and then use it within you project, like:

```sh
$ docker run --rm -it -v $(pwd):/project terravision graphdata --source /project/ --varfile /project/your.tfvars

$ docker run --rm -it -v $(pwd):/project terravision draw --source https://github.com/your-repo/terraform-examples.git//mysubfolder/secondfolder/
```

# Annotating generated diagrams
No automatically generated diagram is going to have all the detail you need, at best it will get you 80-90% of the way there. To add custom annotations such as a main diagram title, additional labels on arrows or additional resources created outside your Terraform, include a `terravision.yml` file in the source code folder and it will be automatically loaded. Alternatively, specify a path to the annotations file as a parameter to terravision.

Expand Down
2 changes: 1 addition & 1 deletion buildspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 0.2
phases:
install:
runtime-versions:
python: 3.7
python: 3.12
commands:
- pip3 install -r requirements.txt
- git version
Expand Down
2 changes: 1 addition & 1 deletion clearcache.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
#!/usr/bin/env sh
rm -rf ~/.terravision
1 change: 0 additions & 1 deletion modules/fileparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from pathlib import Path
from sys import exit

from numpy import source
import click
import yaml
import hcl2
Expand Down
2 changes: 1 addition & 1 deletion modules/gitlibs.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def update(self, op_code, cur_count, max_count=None, message=""):
def handle_readme_source(resp) -> str:
readme = resp.json()["root"]["readme"]
githubURL = "ssh://git@" + find_between(readme, "(https://", ")")
found = re.findall("\.........\.net", githubURL)
found = re.findall(r"\.........\.net", githubURL)
for site in found:
githubURL = githubURL.replace(site, "-ssh" + site)
githubURL = githubURL.replace("/projects/", ":7999/")
Expand Down
10 changes: 5 additions & 5 deletions modules/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,11 @@ def replace_var_values(
def find_replace_values(varstring, module, tfdata):
# Regex string matching to create lists of different variable markers found
value = helpers.strip_var_curlies(str(varstring))
var_found_list = re.findall("var\.[A-Za-z0-9_\-]+", value)
data_found_list = re.findall("data\.[A-Za-z0-9_\-\.\[\]]+", value)
varobject_found_list = re.findall("var\.[A-Za-z0-9_\-]+\.[A-Za-z0-9_\-]+", value)
local_found_list = re.findall("local\.[A-Za-z0-9_\-\.\[\]]+", value)
modulevar_found_list = re.findall("module\.[A-Za-z0-9_\-\.\[\]]+", value)
var_found_list = re.findall(r"var\.[A-Za-z0-9_\-]+", value)
data_found_list = re.findall(r"data\.[A-Za-z0-9_\-\.\[\]]+", value)
varobject_found_list = re.findall(r"var\.[A-Za-z0-9_\-]+\.[A-Za-z0-9_\-]+", value)
local_found_list = re.findall(r"local\.[A-Za-z0-9_\-\.\[\]]+", value)
modulevar_found_list = re.findall(r"module\.[A-Za-z0-9_\-\.\[\]]+", value)
# Replace found variable strings with variable values
value = replace_data_values(data_found_list, value, tfdata)
value = replace_module_vars(modulevar_found_list, value, module, tfdata)
Expand Down
Loading