Skip to content

Commit

Permalink
Add local S3 option to wizard
Browse files Browse the repository at this point in the history
  • Loading branch information
niccolomineo committed Jan 15, 2024
1 parent 8589a77 commit 1e08887
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 5 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,18 @@ If you don't want DigitalOcean DNS configuration the following args are required
| local | Docker Volume are used to store media | `--media-storage=local` |
| none | Project have no media | `--media-storage=none` |

#### Local S3 storage

For enabling a local S3-like object storage the following argument is needed:

For enabling redis integration the following arguments are needed:

`--local-s3-storage`

Disabled arg:

`--no-local-s3-storage`

#### Redis

For enabling redis integration the following arguments are needed:
Expand Down
10 changes: 10 additions & 0 deletions bootstrap/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class Collector:
sentry_org: str | None = None
sentry_url: str | None = None
media_storage: str | None = None
local_s3_storage: bool | None = None
gitlab_url: str | None = None
gitlab_token: str | None = None
gitlab_namespace_path: str | None = None
Expand Down Expand Up @@ -89,6 +90,7 @@ def collect(self):
self.set_sentry()
self.set_gitlab()
self.set_media_storage()
self.set_local_s3_storage()

def set_project_slug(self):
"""Set the project slug option."""
Expand Down Expand Up @@ -286,6 +288,13 @@ def set_media_storage(self):
type=click.Choice(MEDIA_STORAGE_CHOICES, case_sensitive=False),
).lower()

def set_local_s3_storage(self):
"""Set the local S3 storage option."""
if "s3" in self.media_storage and self.local_s3_storage is None:
self.local_s3_storage = click.confirm(
warning("Do you want to use the local S3 storage?"), default=False
)

def get_runner(self):
"""Get the bootstrap runner instance."""
return Runner(
Expand Down Expand Up @@ -315,6 +324,7 @@ def get_runner(self):
sentry_org=self.sentry_org,
sentry_url=self.sentry_url,
media_storage=self.media_storage,
local_s3_storage=self.local_s3_storage,
use_redis=self.use_redis,
gitlab_url=self.gitlab_url,
gitlab_token=self.gitlab_token,
Expand Down
2 changes: 2 additions & 0 deletions bootstrap/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class Runner:
sentry_url: str | None = None
media_storage: str
use_redis: bool = False
local_s3_storage: bool = False
gitlab_url: str | None = None
gitlab_namespace_path: str | None = None
gitlab_token: str | None = None
Expand Down Expand Up @@ -251,6 +252,7 @@ def init_service(self):
"terraform_cloud_organization": self.terraform_cloud_organization,
"tfvars": self.tfvars,
"use_redis": self.use_redis and "true" or "false",
"local_s3_storage": self.local_s3_storage and "true" or "false",
"use_vault": self.vault_url and "true" or "false",
},
output_dir=self.output_dir,
Expand Down
1 change: 1 addition & 0 deletions cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"terraform_cloud_organization": "",
"media_storage": ["digitalocean-s3", "other-s3", "local", "none"],
"use_redis": "false",
"local_s3_storage": "false",
"use_vault": "false",
"environments_distribution": "1",
"resources": {
Expand Down
1 change: 1 addition & 0 deletions start.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"--media-storage",
type=click.Choice(MEDIA_STORAGE_CHOICES, case_sensitive=False),
)
@click.option("--local-s3-storage/--no-local-s3-storage", is_flag=True, default=None)
@click.option("--use-redis/--no-redis", is_flag=True, default=None)
@click.option("--gitlab-url")
@click.option("--gitlab-token", envvar=GITLAB_TOKEN_ENV_VAR)
Expand Down
4 changes: 2 additions & 2 deletions {{cookiecutter.project_dirname}}/.env_template
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ CACHE_URL=locmem://
COMPOSE_FILE=docker-compose.yaml
DATABASE_URL=postgres://postgres:postgres@postgres:5432/{{ cookiecutter.project_slug }}
DJANGO_ADMINS=admin,[email protected]
DJANGO_ALLOWED_HOSTS=localhost,{{ cookiecutter.service_slug }}
DJANGO_AWS_S3_URL=http://minio-admin:[email protected]:9000/{{ cookiecutter.project_slug }}
DJANGO_ALLOWED_HOSTS=localhost,{{ cookiecutter.service_slug }}{% if cookiecutter.local_s3_storage == "true" %}
DJANGO_AWS_S3_URL=http://minio-admin:[email protected]:9000/{{ cookiecutter.project_slug }}{% endif %}
DJANGO_CONFIGURATION=Local
DJANGO_DEBUG=True
[email protected]
Expand Down
6 changes: 3 additions & 3 deletions {{cookiecutter.project_dirname}}/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ services:
image: ${{ "{" }}{{ cookiecutter.service_slug|upper }}_IMAGE_NAME:-{{ cookiecutter.project_slug }}_{{ cookiecutter.service_slug }}}:${{ "{" }}{{ cookiecutter.service_slug|upper }}_IMAGE_TAG:-latest}
depends_on:
postgres:
condition: service_healthy{% if "s3" in cookiecutter.media_storage %}
condition: service_healthy{% if cookiecutter.local_s3_storage == "true" %}
minio:
condition: service_healthy{% endif %}
environment:
Expand Down Expand Up @@ -52,7 +52,7 @@ services:
retries: 30
image: postgres:14-bullseye
volumes:
- pg_data:/var/lib/postgresql/data{% if "s3" in cookiecutter.media_storage %}
- pg_data:/var/lib/postgresql/data{% if cookiecutter.local_s3_storage == "true" %}
networks:
{{ cookiecutter.project_slug }}_network:
ipv4_address: 172.20.0.11
Expand Down Expand Up @@ -80,7 +80,7 @@ services:
ipv4_address: 172.20.0.13{% endif %}

volumes:
pg_data: {}{% if "s3" in cookiecutter.media_storage %}
pg_data: {}{% if cookiecutter.local_s3_storage == "true" %}
minio_data: {}

networks:
Expand Down

0 comments on commit 1e08887

Please sign in to comment.