Skip to content

Commit f62a466

Browse files
committed
TG-940 Add local MinIO service
1 parent 069f2c9 commit f62a466

File tree

13 files changed

+166
-31
lines changed

13 files changed

+166
-31
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ python3 -m pip install -r requirements/common.txt
3333

3434
The `terraform` cli package is required, unless you want to generate a project only locally. To install it we suggest to use the official [install guide](https://learn.hashicorp.com/tutorials/terraform/install-cli).
3535

36+
Should you opt for an S3-like object storage, you must install and launch MinIO Server's `mc` package as outlined in this [install guide](https://min.io/docs/minio/linux/index.html).
37+
3638
## 🔑 Credentials (optional)
3739

3840
### 🦊 GitLab
@@ -202,6 +204,18 @@ If you don't want DigitalOcean DNS configuration the following args are required
202204
| local | Docker Volume are used to store media | `--media-storage=local` |
203205
| none | Project have no media | `--media-storage=none` |
204206

207+
#### Local S3 storage
208+
209+
For enabling a local S3-like object storage the following argument is needed:
210+
211+
For enabling redis integration the following arguments are needed:
212+
213+
`--local-s3-storage`
214+
215+
Disabled arg:
216+
217+
`--no-local-s3-storage`
218+
205219
#### Redis
206220

207221
For enabling redis integration the following arguments are needed:

bootstrap/collector.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class Collector:
6161
sentry_org: str | None = None
6262
sentry_url: str | None = None
6363
media_storage: str | None = None
64+
local_s3_storage: bool | None = None
6465
gitlab_url: str | None = None
6566
gitlab_token: str | None = None
6667
gitlab_namespace_path: str | None = None
@@ -89,6 +90,7 @@ def collect(self):
8990
self.set_sentry()
9091
self.set_gitlab()
9192
self.set_media_storage()
93+
self.set_local_s3_storage()
9294

9395
def set_project_slug(self):
9496
"""Set the project slug option."""
@@ -286,6 +288,13 @@ def set_media_storage(self):
286288
type=click.Choice(MEDIA_STORAGE_CHOICES, case_sensitive=False),
287289
).lower()
288290

291+
def set_local_s3_storage(self):
292+
"""Set the local S3 storage option."""
293+
if "s3" in self.media_storage and self.local_s3_storage is None:
294+
self.local_s3_storage = click.confirm(
295+
warning("Do you want to use the local S3 storage?"), default=False
296+
)
297+
289298
def get_runner(self):
290299
"""Get the bootstrap runner instance."""
291300
return Runner(
@@ -315,6 +324,7 @@ def get_runner(self):
315324
sentry_org=self.sentry_org,
316325
sentry_url=self.sentry_url,
317326
media_storage=self.media_storage,
327+
local_s3_storage=self.local_s3_storage,
318328
use_redis=self.use_redis,
319329
gitlab_url=self.gitlab_url,
320330
gitlab_token=self.gitlab_token,

bootstrap/runner.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class Runner:
7373
sentry_url: str | None = None
7474
media_storage: str
7575
use_redis: bool = False
76+
local_s3_storage: bool = False
7677
gitlab_url: str | None = None
7778
gitlab_namespace_path: str | None = None
7879
gitlab_token: str | None = None
@@ -251,6 +252,7 @@ def init_service(self):
251252
"terraform_cloud_organization": self.terraform_cloud_organization,
252253
"tfvars": self.tfvars,
253254
"use_redis": self.use_redis and "true" or "false",
255+
"local_s3_storage": self.local_s3_storage and "true" or "false",
254256
"use_vault": self.vault_url and "true" or "false",
255257
},
256258
output_dir=self.output_dir,

cookiecutter.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"terraform_cloud_organization": "",
1111
"media_storage": ["digitalocean-s3", "other-s3", "local", "none"],
1212
"use_redis": "false",
13+
"local_s3_storage": "false",
1314
"use_vault": "false",
1415
"environments_distribution": "1",
1516
"resources": {

start.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"--media-storage",
6363
type=click.Choice(MEDIA_STORAGE_CHOICES, case_sensitive=False),
6464
)
65+
@click.option("--local-s3-storage/--no-local-s3-storage", is_flag=True, default=None)
6566
@click.option("--use-redis/--no-redis", is_flag=True, default=None)
6667
@click.option("--gitlab-url")
6768
@click.option("--gitlab-token", envvar=GITLAB_TOKEN_ENV_VAR)

{{cookiecutter.project_dirname}}/.env_template

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ CACHE_URL=locmem://
33
COMPOSE_FILE=docker-compose.yaml
44
DATABASE_URL=postgres://postgres:postgres@postgres:5432/{{ cookiecutter.project_slug }}
55
DJANGO_ADMINS=admin,[email protected]
6-
DJANGO_ALLOWED_HOSTS=localhost,{{ cookiecutter.service_slug }}
6+
DJANGO_ALLOWED_HOSTS=localhost,{{ cookiecutter.service_slug }}{% if cookiecutter.local_s3_storage == "true" %}
7+
DJANGO_AWS_S3_URL=http://minio-admin:[email protected]:9000/{{ cookiecutter.project_slug }}{% endif %}
78
DJANGO_CONFIGURATION=Local
89
DJANGO_DEBUG=True
910

{{cookiecutter.project_dirname}}/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,11 @@ RUN apt-get update \
6969
make \
7070
openssh-client \
7171
postgresql-client
72+
RUN curl https://dl.min.io/client/mc/release/linux-amd64/mc > /usr/bin/minio-client
7273
USER $APPUSER
7374
COPY --chown=$APPUSER ./requirements/local.txt requirements/local.txt
7475
RUN python3 -m pip install --user --no-cache-dir -r requirements/local.txt
7576
COPY --chown=$APPUSER . .
7677
RUN DJANGO_SECRET_KEY=build python3 -m manage collectstatic --clear --link --noinput
77-
ENTRYPOINT ["./scripts/entrypoint.sh"]
78+
ENTRYPOINT ["./scripts/entrypoint_local.sh"]
7879
CMD python3 -m manage runserver 0.0.0.0:${INTERNAL_SERVICE_PORT}

{{cookiecutter.project_dirname}}/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ compilemessages: ## Django compilemessages
2020
coverage: ## Run coverage
2121
./scripts/coverage.sh
2222

23+
.PHONY: createbucket
24+
createbucket: ## Create MinIO bucket
25+
minio-client mb --quiet minio/{{ cookiecutter.project_slug }};
26+
minio-client anonymous set public minio/{{ cookiecutter.project_slug }};
27+
2328
.PHONY: createsuperuser
2429
createsuperuser: ## Django createsuperuser
2530
python3 -m manage createsuperuser --noinput

{{cookiecutter.project_dirname}}/docker-compose.yaml

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@ services:
1010
image: ${{ "{" }}{{ cookiecutter.service_slug|upper }}_IMAGE_NAME:-{{ cookiecutter.project_slug }}_{{ cookiecutter.service_slug }}}:${{ "{" }}{{ cookiecutter.service_slug|upper }}_IMAGE_TAG:-latest}
1111
depends_on:
1212
postgres:
13-
condition: service_healthy
13+
condition: service_healthy{% if cookiecutter.local_s3_storage == "true" %}
14+
minio:
15+
condition: service_healthy{% endif %}
1416
environment:
1517
- CACHE_URL
1618
- DATABASE_URL=${DATABASE_URL:-postgres://postgres:postgres@postgres:5432/{{ cookiecutter.project_slug }}}
1719
- DJANGO_ADMINS
1820
- DJANGO_ALLOWED_HOSTS
21+
- DJANGO_AWS_S3_URL
1922
- DJANGO_CONFIGURATION=${DJANGO_CONFIGURATION:-Testing}
2023
- DJANGO_DEBUG
2124
- DJANGO_DEFAULT_FROM_EMAIL
@@ -32,7 +35,10 @@ services:
3235
- PYTHONBREAKPOINT
3336
ports:
3437
- "${{ '{' }}{{ cookiecutter.service_slug|upper }}_PORT:-{{ cookiecutter.internal_service_port }}{{ '}' }}:${INTERNAL_SERVICE_PORT:-{{ cookiecutter.internal_service_port }}{{ '}' }}"
35-
user: ${USER:-appuser}
38+
user: ${USER:-appuser}{% if "s3" in cookiecutter.media_storage %}
39+
networks:
40+
custom:
41+
ipv4_address: 172.20.0.10{% endif %}
3642

3743
postgres:
3844
environment:
@@ -46,7 +52,39 @@ services:
4652
retries: 30
4753
image: postgres:14-bullseye
4854
volumes:
49-
- pg_data:/var/lib/postgresql/data
55+
- pg_data:/var/lib/postgresql/data{% if cookiecutter.local_s3_storage == "true" %}
56+
networks:
57+
custom:
58+
ipv4_address: 172.20.0.11
59+
60+
minio:
61+
command: minio server /var/lib/minio/data --console-address ":9001"
62+
environment:
63+
- MINIO_ENDPOINT=http://minio:9000
64+
- MINIO_BUCKET_NAME={{ cookiecutter.project_slug }}
65+
- MINIO_ROOT_USER=minio-admin
66+
- MINIO_ROOT_PASSWORD=minio-admin
67+
healthcheck:
68+
test: ["CMD", "mc", "ready", "local"]
69+
interval: 3s
70+
timeout: 3s
71+
retries: 30
72+
image: minio/minio:latest
73+
ports:
74+
- 9000:9000
75+
- 9001:9001
76+
volumes:
77+
- minio_data:/var/lib/minio/data
78+
networks:
79+
custom:
80+
ipv4_address: 172.20.0.13{% endif %}
5081

5182
volumes:
52-
pg_data: {}
83+
pg_data: {}{% if cookiecutter.local_s3_storage == "true" %}
84+
minio_data: {}
85+
86+
networks:
87+
custom:
88+
ipam:
89+
config:
90+
- subnet: 172.20.0.0/16{% endif %}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
-r base.in
22
django-configurations[cache,database,email]~=2.5.0
3-
django~=5.0.0
3+
{% if "s3" in cookiecutter.media_storage %}django-storages[boto3]~=1.14.0
4+
{% endif %}django~=5.0.0

0 commit comments

Comments
 (0)