Skip to content

Commit 54e82bc

Browse files
authored
Merge pull request #25 from zeroae/f-local-development
Initial commit of local install/development mode
2 parents aff955a + 9f09d44 commit 54e82bc

File tree

10 files changed

+200
-5
lines changed

10 files changed

+200
-5
lines changed

.chalice/config.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22
"version": "2.0",
33
"app_name": "terraform-registry",
44
"stages": {
5+
"local": {
6+
"api_gateway_stage": "local",
7+
"autogen_policy": true,
8+
"environment_variables": {
9+
"AWS_ACCESS_KEY_ID": "local_id",
10+
"AWS_SECRET_ACCESS_KEY": "local_key",
11+
"ZTR_DYNAMODB_URL": "http://backend:8000",
12+
"ZTR_DYNAMODB_TABLE_PREFIX": "ZTR-LOCAL"
13+
},
14+
"manage_iam_role": false
15+
},
516
"dev": {
617
"api_gateway_stage": "dev",
718
"autogen_policy": false,

.env

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# One of the LEGO DNS Providers https://go-acme.github.io/lego/dns/
2+
# Requires DNS Record: *.${ACME_DNS_SUFFIX} IN A 127.0.0.1
3+
# Changing the DNS_SUFFIX requires modifying tests/integration/tf.local.zeroae.net
4+
ACME_DNS_PROVIDER=route53
5+
ACME_DNS_SUFFIX=local.zeroae.net

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,9 @@
77

88
# IDEs
99
.idea
10+
11+
# Secrets
12+
/secrets/
13+
14+
# Ignore DynamoDB-local
15+
/.ddb/

README.md

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,76 @@
1-
# terraform-registry
2-
An implementation of the [Terraform Registry API][registry-api] using [Chalice][chalice] and [PynamoDB][pynamodb].
1+
# zeroae/terraform-registry
2+
Zero A.E.'s [12-Factor][12-factor] codebase of the [Terraform Registry API][registry-api] implemented using [Chalice][chalice] and [PynamoDB][pynamodb].
33

44
## Similar projects (and likely more complete), in alphabetical order
5-
- [apparentlymart/terraform-simple-registry](https://github.com/apparentlymart/terraform-simple-registry)
65
- [apparentlymart/terraform-aws-tf-registry](https://github.com/apparentlymart/terraform-aws-tf-registry)
6+
- [apparentlymart/terraform-simple-registry](https://github.com/apparentlymart/terraform-simple-registry)
77
- [dflook/terraform-registry](https://github.com/dflook/terraform-registry)
88
- [outsideris/citizen](https://github.com/outsideris/citizen)
99
- [rmb938/tf-registry](https://github.com/rmb938/tf-registry)
1010

11-
## Deployment on AWS
11+
## Local Deployment
12+
1. Requirements:
13+
- conda
14+
- docker-compose
15+
- keybase
1216

17+
1. Clone the repository
18+
```shell script
19+
git clone https://github.com/zeroae/terraform-registry.git
20+
cd terraform-registry
21+
```
22+
23+
1. Clone the secrets (submodules did not work)
24+
```shell script
25+
git clone keybase://team/zeroae/terraform-registry-secrets secrets
26+
```
27+
28+
1. Create conda environment
29+
```shell script
30+
conda env create
31+
conda activate terraform-registry
32+
````
33+
34+
1. Start the app on local mode
35+
```shell script
36+
docker-compose up -d
37+
```
38+
39+
1. Attach to the Management container
40+
```shell script
41+
docker attach terraform-registry_management_1
42+
conda activate terraform-registry
43+
./manage.py --help
44+
```
45+
46+
1. Initialize the Database
47+
```shell script
48+
./manage.py db init
49+
```
50+
1. (Optional) Restore the initial "local.ddb"
51+
```shell script
52+
./manage.py db restore tests/integration/local.ddb
53+
```
54+
1. (Optional) Verify Terraform CLI can reach the local server
55+
```shell script
56+
cd tests/integration/tf.local.zeroae.net
57+
rm -rf .terraform
58+
terraform init
59+
```
60+
1. Detach from the container
61+
```shell script
62+
Ctrl-P + Ctrl-Q
63+
```
64+
65+
1. (Optional) Verify Terraform CLI can reach the local registry (outside management)
66+
```shell script
67+
cd tests/integration/tf.local.zeroae.net
68+
rm -rf .terraform
69+
terraform init
70+
```
1371

1472
---
73+
[12-factor]: https://www.12factor.net
1574
[chalice]: https://github.com/aws/chalice
1675
[pynamodb]: https://github.com/pynamodb/PynamoDB
1776
[registry-api]: https://www.terraform.io/docs/registry/api.html

app.Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM python:3.7-alpine
2+
3+
RUN apk add curl
4+
5+
ARG CHALICE_VERSION
6+
VOLUME /opt/chalice
7+
WORKDIR /opt/chalice
8+
EXPOSE 8000
9+
RUN pip install chalice==$CHALICE_VERSION
10+
11+
ENTRYPOINT [ "chalice", "--project-dir=/opt/chalice" ]
12+
CMD ["local", "--host=0.0.0.0", "--stage=local"]
13+
14+
# Candidate for ON-BUILD
15+
COPY requirements.txt .
16+
RUN pip install -r requirements.txt

docker-compose.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
version: '3.4'
2+
3+
networks:
4+
default:
5+
6+
services:
7+
app:
8+
build:
9+
context: .
10+
dockerfile: app.Dockerfile
11+
args:
12+
CHALICE_VERSION: 1.12
13+
image: zeroae/terraform-registry-app:local
14+
healthcheck:
15+
test: "curl --fail -s http://localhost:8000/.well-known/terraform.json"
16+
labels:
17+
- traefik.http.routers.app.rule=Host(`tf.$ACME_DNS_SUFFIX`)
18+
- traefik.http.routers.app.tls.certresolver=default
19+
expose:
20+
- 8000
21+
volumes:
22+
- ./:/opt/chalice:ro
23+
24+
backend:
25+
image: amazon/dynamodb-local:1.12.0
26+
command: -jar DynamoDBLocal.jar -dbPath ./data
27+
healthcheck:
28+
test: "curl -s -I http://localhost:8000 | grep -q 'HTTP/1.1 400 Bad Request'"
29+
expose:
30+
- 8000
31+
volumes:
32+
- ./.ddb:/home/dynamodblocal/data
33+
34+
manage:
35+
build:
36+
context: .
37+
dockerfile: manage.Dockerfile
38+
image: zeroae/terraform-registry-manage:local
39+
links:
40+
- reverse-proxy:tf.$ACME_DNS_SUFFIX
41+
stdin_open: true
42+
tty: true
43+
volumes:
44+
- ./:/opt/chalice
45+
46+
47+
reverse-proxy:
48+
# The official v2 Traefik docker image
49+
image: traefik:v2.1
50+
# Enables the web UI and tells Traefik to listen to docker
51+
command:
52+
- --api.insecure=true
53+
- --providers.docker
54+
- --entryPoints.web.address=:80
55+
- --entryPoints.websecure.address=:443
56+
- --certificatesResolvers.default.acme.storage=/etc/traefik/acme/acme.json
57+
- --certificatesResolvers.default.acme.dnsChallenge.provider=$ACME_DNS_PROVIDER
58+
ports:
59+
# The HTTP(s) port
60+
- "80:80"
61+
- "443:443"
62+
# The Web UI (enabled by --api.insecure=true)
63+
- "8080:8080"
64+
volumes:
65+
# So that Traefik can listen to Docker events
66+
- /var/run/docker.sock:/var/run/docker.sock:ro
67+
- ./secrets/$ACME_DNS_SUFFIX/acme:/etc/traefik/acme
68+
- ./secrets/aws:/root/.aws/:ro

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ dependencies:
1313
- python 3.7
1414
- pre-commit
1515
- requests
16-
# - ngrok, open an account at ngrok.com
1716

1817
# Runtime Dependencies (must match requirements.txt)
1918
- environs
@@ -25,3 +24,4 @@ dependencies:
2524
- coverage
2625
- pytest
2726
- pytest-chalice
27+
- terraform

manage.Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM continuumio/miniconda3:4.8.2-alpine AS management
2+
3+
VOLUME /opt/chalice
4+
WORKDIR /opt/chalice
5+
6+
COPY environment.yml .
7+
RUN /opt/conda/bin/conda env create -n chalice && \
8+
/opt/conda/bin/conda clean --all --yes && \
9+
/opt/conda/bin/conda remove -n chalice liquidprompt && \
10+
sed -i 's/activate base/activate chalice/' /home/anaconda/.profile

tests/integration/local.ddb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[["plus3it/file-cache/external", {"range_key": "1.2.0", "attributes": {"description": {"S": "Terraform module to retrieve and cache files"}, "downloads": {"N": "0"}, "getter_url": {"S": "https://api.github.com/repos/plus3it/terraform-external-file-cache/tarball/1.3.1//*?archive=tar.gz"}, "owner": {"S": "lorengordon"}, "published_at": {"S": "2019-09-05T14:10:59.548658+0000"}, "source": {"S": "https://github.com/plus3it/terraform-external-file-cache"}, "verified": {"BOOL": false}}}], ["plus3it/file-cache/external", {"range_key": "1.2.1", "attributes": {"description": {"S": "Terraform module to retrieve and cache files"}, "downloads": {"N": "0"}, "getter_url": {"S": "https://api.github.com/repos/plus3it/terraform-external-file-cache/tarball/1.3.1//*?archive=tar.gz"}, "owner": {"S": "lorengordon"}, "published_at": {"S": "2019-09-05T14:10:59.548658+0000"}, "source": {"S": "https://github.com/plus3it/terraform-external-file-cache"}, "verified": {"BOOL": false}}}], ["plus3it/file-cache/external", {"range_key": "1.2.2", "attributes": {"description": {"S": "Terraform module to retrieve and cache files"}, "downloads": {"N": "0"}, "getter_url": {"S": "https://api.github.com/repos/plus3it/terraform-external-file-cache/tarball/1.3.1//*?archive=tar.gz"}, "owner": {"S": "lorengordon"}, "published_at": {"S": "2019-09-05T14:10:59.548658+0000"}, "source": {"S": "https://github.com/plus3it/terraform-external-file-cache"}, "verified": {"BOOL": false}}}], ["plus3it/file-cache/external", {"range_key": "1.2.3", "attributes": {"description": {"S": "Terraform module to retrieve and cache files"}, "downloads": {"N": "0"}, "getter_url": {"S": "https://api.github.com/repos/plus3it/terraform-external-file-cache/tarball/1.3.1//*?archive=tar.gz"}, "owner": {"S": "lorengordon"}, "published_at": {"S": "2019-09-05T14:10:59.548658+0000"}, "source": {"S": "https://github.com/plus3it/terraform-external-file-cache"}, "verified": {"BOOL": false}}}], ["plus3it/file-cache/external", {"range_key": "1.2.4", "attributes": {"description": {"S": "Terraform module to retrieve and cache files"}, "downloads": {"N": "0"}, "getter_url": {"S": "https://api.github.com/repos/plus3it/terraform-external-file-cache/tarball/1.3.1//*?archive=tar.gz"}, "owner": {"S": "lorengordon"}, "published_at": {"S": "2019-09-05T14:10:59.548658+0000"}, "source": {"S": "https://github.com/plus3it/terraform-external-file-cache"}, "verified": {"BOOL": false}}}], ["plus3it/file-cache/external", {"range_key": "1.3.0", "attributes": {"description": {"S": "Terraform module to retrieve and cache files"}, "downloads": {"N": "0"}, "getter_url": {"S": "https://api.github.com/repos/plus3it/terraform-external-file-cache/tarball/1.3.1//*?archive=tar.gz"}, "owner": {"S": "lorengordon"}, "published_at": {"S": "2019-09-05T14:10:59.548658+0000"}, "source": {"S": "https://github.com/plus3it/terraform-external-file-cache"}, "verified": {"BOOL": false}}}], ["plus3it/file-cache/external", {"range_key": "1.3.1", "attributes": {"description": {"S": "Terraform module to retrieve and cache files"}, "downloads": {"N": "0"}, "getter_url": {"S": "https://api.github.com/repos/plus3it/terraform-external-file-cache/tarball/1.3.1//*?archive=tar.gz"}, "owner": {"S": "lorengordon"}, "published_at": {"S": "2019-09-05T14:10:59.548658+0000"}, "source": {"S": "https://github.com/plus3it/terraform-external-file-cache"}, "verified": {"BOOL": false}}}], ["terraform-aws-modules/vpc/aws", {"range_key": "2.29.0", "attributes": {"description": {"S": "Terraform module which creates VPC resources on AWS"}, "downloads": {"N": "0"}, "getter_url": {"S": "https://api.github.com/repos/terraform-aws-modules/terraform-aws-vpc/tarball/v2.29.0//*?archive=tar.gz"}, "owner": {"S": "antonbabenko"}, "published_at": {"S": "2020-03-13T09:35:24.502364+0000"}, "source": {"S": "https://github.com/terraform-aws-modules/terraform-aws-vpc"}, "verified": {"BOOL": true}}}]]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module "file-cache" {
2+
source = "tf.local.zeroae.net/plus3it/file-cache/external"
3+
version = "1.2.0"
4+
}
5+
6+
module "file-cache-latest" {
7+
source = "tf.local.zeroae.net/plus3it/file-cache/external"
8+
# version = "1.3.1"
9+
}
10+
11+
module "file-cache-ranged" {
12+
source = "tf.local.zeroae.net/plus3it/file-cache/external"
13+
version = ">=1.3.0"
14+
}
15+
16+
module "file-cache-older" {
17+
source = "tf.local.zeroae.net/plus3it/file-cache/external"
18+
version = "~>1.2.0"
19+
}

0 commit comments

Comments
 (0)