Skip to content

Commit

Permalink
feat: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
davidvasandani committed Aug 15, 2022
0 parents commit 2933728
Show file tree
Hide file tree
Showing 25 changed files with 2,146 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .bashrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

figlet -w 70 "haste.heart dev env" | lolcat
115 changes: 115 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
FROM amazonlinux:2.0.20220606.1 as base

# install node
RUN curl --silent --location https://rpm.nodesource.com/setup_16.x | bash -

RUN yum update -y \
&& amazon-linux-extras install -y \
docker \
postgresql14 \
epel \
&& amazon-linux-extras enable -y \
python3.8 \
&& yum install -y \
figlet \
file \
gcc \
git \
golang \
nodejs \
python38 \
ruby \
tar \
unzip \
wget \
which \
&& yum -y clean all \
&& rm -rf /var/cache

RUN python3.8 -m pip install --no-cache-dir pre-commit

RUN wget https://github.com/busyloop/lolcat/archive/master.zip \
&& unzip master.zip \
&& pushd lolcat-master/bin \
&& gem install lolcat \
&& popd \
&& rm -rf master.zip lolcat-master

FROM base as terraform
ENV TERRAFORM_VERSION=1.2.7
RUN if [ "$(uname -m)" = "aarch64" ]; then \
curl -sL https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_arm64.zip -o terraform.zip; \
else \
curl -sL https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip -o terraform.zip; \
fi \
&& unzip terraform.zip -d /usr/local/bin \
&& chmod +x \
/usr/local/bin/terraform \
&& rm -rf \
terraform.zip

FROM base as taskfile
ENV TASKFILE_VERSION=3.14.1
RUN if [ "$(uname -m)" = "aarch64" ]; then \
curl -sL https://github.com/go-task/task/releases/download/v${TASKFILE_VERSION}/task_linux_arm64.tar.gz -o taskfile.tar.gz; \
else \
curl -sL https://github.com/go-task/task/releases/download/v${TASKFILE_VERSION}/task_linux_amd64.tar.gz -o taskfile.tar.gz; \
fi \
&& tar -zxvf taskfile.tar.gz \
&& mv task /usr/local/bin/task \
&& chmod +x \
/usr/local/bin/task \
&& rm -rf \
taskfile.tar.gz

FROM base as tflint
ENV TFLINK_VERSION=0.39.3
RUN if [ "$(uname -m)" = "aarch64" ]; then \
curl -sL https://github.com/terraform-linters/tflint/releases/download/v${TFLINK_VERSION}/tflint_linux_arm64.zip -o tflint.zip; \
else \
curl -sL https://github.com/terraform-linters/tflint/releases/download/v${TFLINK_VERSION}/tflint_linux_amd64.zip -o tflint.zip; \
fi \
&& unzip tflint.zip -d /usr/local/bin \
&& chmod +x \
/usr/local/bin/tflint \
&& rm -rf \
tflint.zip

FROM base as shellcheck
ENV SHELLCHECK_VERSION=0.8.0
RUN if [ "$(uname -m)" = "aarch64" ]; then \
curl -sL https://github.com/koalaman/shellcheck/releases/download/v${SHELLCHECK_VERSION}/shellcheck-v${SHELLCHECK_VERSION}.linux.aarch64.tar.xz -o shellcheck.tar.xz; \
else \
curl -sL https://github.com/koalaman/shellcheck/releases/download/v${SHELLCHECK_VERSION}/shellcheck-v${SHELLCHECK_VERSION}.linux.x86_64.tar.xz -o shellcheck.tar.xz; \
fi \
&& tar -xvf shellcheck.tar.xz \
&& mv shellcheck-v${SHELLCHECK_VERSION}/shellcheck /usr/local/bin/shellcheck \
&& chmod +x \
/usr/local/bin/shellcheck \
&& rm -rf \
shellcheck.tar.xz

FROM base as docker-compose
RUN export LATEST_COMPOSE_VERSION=$(curl -sSL "https://api.github.com/repos/docker/compose/releases/latest" | grep -o -P '(?<="tag_name": ").+(?=")') \
&& curl -sSL "https://github.com/docker/compose/releases/download/${LATEST_COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose \
&& chmod +x /usr/local/bin/docker-compose

FROM base as dockerize
ENV DOCKERIZE_VERSION=0.6.1
RUN if [ "$(uname -m)" = "aarch64" ]; then \
echo "CPU architecture not supported"; \
else \
curl -sL https://github.com/jwilder/dockerize/releases/download/v${DOCKERIZE_VERSION}/dockerize-linux-amd64-v${DOCKERIZE_VERSION}.tar.gz -o dockerize.tar.gz; \
fi \
&& tar -C /usr/local/bin -xzvf dockerize.tar.gz \
&& chmod +x /usr/local/bin/dockerize \
&& rm -rf dockerize.tar.gz

FROM base as main
COPY --from=terraform /usr/local/bin/terraform /usr/local/bin/terraform
COPY --from=taskfile /usr/local/bin/task /usr/local/bin/task
COPY --from=tflint /usr/local/bin/tflint /usr/local/bin/tflint
COPY --from=shellcheck /usr/local/bin/shellcheck /usr/local/bin/shellcheck
COPY --from=docker-compose /usr/local/bin/docker-compose /usr/local/bin/docker-compose
COPY --from=dockerize /usr/local/bin/dockerize /usr/local/bin/dockerize
COPY .bashrc /root/.bashrc
7 changes: 7 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "Haste Heart",
"dockerComposeFile": "../docker-compose.yml",
"service": "development",
"workspaceFolder": "/workspace",
"shutdownAction": "stopCompose"
}
Empty file added .dockerignore
Empty file.
62 changes: 62 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

# Local .terraform directories
**/.terraform/*

# .tfstate files
*.tfstate
*.tfstate.*

# Crash log files
crash.log
crash.*.log

# Exclude all .tfvars files, which are likely to contain sensitive data, such as
# password, private keys, and other secrets. These should not be part of version
# control as they are data points which are potentially sensitive and subject
# to change depending on the environment.
*.tfvars
*.tfvars.json

# Ignore override files as they are usually used to override resources locally and so
# are not checked in
override.tf
override.tf.json
*_override.tf
*_override.tf.json

# Include override files you do wish to add to version control using negated pattern
# !example_override.tf

# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# example: *tfplan*

# Ignore CLI configuration files
.terraformrc
terraform.rc
17 changes: 17 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
repos:
- repo: https://github.com/gruntwork-io/pre-commit
rev: v0.1.17
hooks:
- id: terraform-fmt
- id: terraform-validate
- id: tflint
- id: shellcheck
- repo: https://github.com/streetsidesoftware/cspell-cli
rev: v6.6.0
hooks:
- id: cspell
- repo: https://github.com/dnephin/pre-commit-golang
rev: v0.5.0
hooks:
- id: go-fmt
# - id: go-vet
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Haste.Heart Code Challenge

**NOTE:** This project uses [VSCode Remote [Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) for local development.

The initial `docker build` takes 105.5s. Once launched run the command `task`. This launches `terratest` for all three parts of the code challenge and takes 1m35s.
73 changes: 73 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# https://taskfile.dev

version: "3"

tasks:
default:
cmds:
- go mod init terraform_test.go || true
- go test -v -timeout 30m
dir: test
env:
PGPASSFILE: "/workspace/question_3/.pgpass"
up:
cmds:
- docker compose up -d
bash:
interactive: true
cmds:
- docker compose exec development bash
rebuild:
cmds:
- docker compose up -d --build
- docker exec hasteheart-development-1 file /usr/local/bin/dockerize
env:
BUILDKIT_PROGRESS: plain
test:
cmds:
- pre-commit run --all-files --verbose
q1:
cmds:
- terraform init
- terraform apply --auto-approve
silent: true
dir: "./question_1/"
q2:
cmds:
- terraform init
- terraform apply --auto-approve
silent: true
dir: "./question_2/"
q3:
cmds:
- terraform init
- terraform apply --auto-approve
silent: true
dir: "./question_3/"
destroy:
cmds:
- task: q1d
- task: q2d
- task: q3d
q1d:
cmds:
- terraform destroy --auto-approve
silent: true
dir: "./question_1/"
q2d:
cmds:
- terraform destroy --auto-approve
silent: true
dir: "./question_2/"
q3d:
cmds:
- terraform destroy --auto-approve
silent: true
dir: "./question_3/"
psql:
cmds:
- psql --host "localhost" --username "user" --dbname "hasteheart"
env:
PGPASSFILE: "./.pgpass"
interactive: true
dir: "./question_3/"
74 changes: 74 additions & 0 deletions cspell.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"version": "0.2",
"ignorePaths": [
"**/tfstate/**",
"**/*.tfstate",
"**/*.tfstate.backup",
"go.mod",
"go.sum",
"**/.terraform"
],
"dictionaries": [],
"words": [
"aarch",
"Adpjw",
"amazonlinux",
"apdisk",
"bgqi",
"Bixl",
"BUILDKIT",
"chdir",
"circleci",
"cmds",
"CYHP",
"cyrilgdn",
"dbname",
"devcontainer",
"donotpresent",
"fileset",
"filesha",
"fseventsd",
"gofmt",
"golangci",
"golint",
"gruntwork",
"hashicorp",
"hasteheart",
"icanhazip",
"icns",
"kreuzwerker",
"Krjj",
"mendhak",
"Mtvenfpk",
"myip",
"pgpass",
"PGPASSFILE",
"psql",
"retryable",
"Retryable",
"Sfrgzsv",
"shellcheck",
"Smcki",
"sslmode",
"stretchr",
"substr",
"taskfile",
"TASKFILE",
"terratest",
"TFLINK",
"tflint",
"tfstate",
"TIHM",
"timemachine",
"viewonly",
"Wbavm",
"zxvf",
"epel",
"figlet",
"pushd",
"popd",
"xzvf"
],
"ignoreWords": [],
"import": []
}
24 changes: 24 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: "3.8"
services:
development:
build:
context: .
dockerfile: .devcontainer/Dockerfile
working_dir: /workspace
network_mode: host
init: true
volumes:
- .:/workspace:cached
- /var/run/docker.sock:/var/run/docker-host.sock
- go-cache:/root/go
environment:
- DOCKER_HOST=unix:///var/run/docker-host.sock
- PGPASSFILE=/workspace/question_3/.pgpass"

command: /bin/sh -c "while sleep 1000; do :; done"
#
# Source:
# https://github.com/microsoft/vscode-dev-containers/blob/main/containers/docker-existing-docker-compose/.devcontainer/docker-compose.yml

volumes:
go-cache:
Loading

0 comments on commit 2933728

Please sign in to comment.