-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
108 lines (84 loc) · 2.95 KB
/
Makefile
File metadata and controls
108 lines (84 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
SHELL := /bin/bash
COMPOSE ?= docker compose
APP_CONTAINER ?= aws-uploader
LOCALSTACK_CONTAINER ?= localstack
LS_ENDPOINT ?= http://localstack:4566
S3_BUCKET ?= meu-bucket
PYTHON ?= python
SCRIPT ?= upload_and_move.py
S3_PREFIX ?= uploads/
SOURCE_DIR ?= .
.PHONY: help build up down restart logs ps shell localstack \
init wait-localstack create-bucket list-buckets list-objects \
py-version run run-dry clean-bucket clean
help:
@echo "Targets:"
@echo " build Build images"
@echo " up Start environment (detached)"
@echo " down Stop environment"
@echo " restart Restart environment"
@echo " logs Follow docker compose logs"
@echo " ps List containers"
@echo " shell Open a shell in the app container"
@echo " localstack Open a shell in the LocalStack container"
@echo " wait-localstack Wait until LocalStack is healthy"
@echo " init Start and initialize (wait + create-bucket)"
@echo " create-bucket Create the S3 bucket (LocalStack)"
@echo " list-buckets List buckets"
@echo " list-objects List objects in the bucket (S3_BUCKET=...)"
@echo " py-version Show the Python version inside the app container"
@echo " run Run uploader using container Python (S3_BUCKET=..., S3_PREFIX=..., SOURCE_DIR=...)"
@echo " run-dry Dry-run uploader (no upload)"
@echo " clean-bucket Delete all objects from the bucket (S3_BUCKET=...)"
@echo " clean Stop and remove environment + volumes"
build:
$(COMPOSE) build
up:
$(COMPOSE) up -d
down:
$(COMPOSE) down
restart: down up
logs:
$(COMPOSE) logs -f --tail=200
ps:
$(COMPOSE) ps
shell:
docker exec -it $(APP_CONTAINER) bash
localstack:
docker exec -it $(LOCALSTACK_CONTAINER) bash
wait-localstack:
@echo "Waiting for LocalStack..."
@until curl -s $(LS_ENDPOINT)/_localstack/health | grep -q '"s3":'; do \
sleep 1; \
done
@echo "LocalStack OK"
init: up wait-localstack create-bucket
create-bucket:
docker exec -it $(APP_CONTAINER) bash -lc 'awslocal --endpoint-url=$(LS_ENDPOINT) s3 mb s3://$(S3_BUCKET) || true'
list-buckets:
docker exec -it $(APP_CONTAINER) bash -lc 'awslocal --endpoint-url=$(LS_ENDPOINT) s3 ls'
list-objects:
docker exec -it $(APP_CONTAINER) bash -lc 'awslocal --endpoint-url=$(LS_ENDPOINT) s3 ls s3://$(S3_BUCKET) --recursive || true'
py-version:
docker exec -it $(APP_CONTAINER) $(PYTHON) --version
run:
docker exec -it $(APP_CONTAINER) bash -lc '\
$(PYTHON) $(SCRIPT) \
--bucket $(S3_BUCKET) \
--prefix $(S3_PREFIX) \
--source-dir $(SOURCE_DIR) \
'
run-dry:
docker exec -it $(APP_CONTAINER) bash -lc '\
$(PYTHON) $(SCRIPT) \
--bucket $(S3_BUCKET) \
--prefix $(S3_PREFIX) \
--source-dir $(SOURCE_DIR) \
--dry-run \
'
clean-bucket:
docker exec -it $(APP_CONTAINER) bash -lc '\
aws --endpoint-url=$(LS_ENDPOINT) s3 rm s3://$(S3_BUCKET) --recursive || true \
'
clean:
$(COMPOSE) down -v