Skip to content
This repository was archived by the owner on Jun 28, 2025. It is now read-only.

Commit f8db32b

Browse files
committed
feat: add makefile to simplify setup and replace init-env.js script
1 parent 5cebd59 commit f8db32b

File tree

6 files changed

+119
-21
lines changed

6 files changed

+119
-21
lines changed

.development.docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: "3"
22
services:
33
web:
4-
container_name: app
4+
container_name: web
55
env_file:
66
- web/.env
77
environment:

cms/init-env.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

cms/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
"develop": "strapi develop",
88
"start": "strapi start",
99
"build": "strapi build",
10-
"strapi": "strapi",
11-
"init-env": "node init-env.js"
10+
"strapi": "strapi"
1211
},
1312
"dependencies": {
1413
"@strapi/plugin-i18n": "4.14.5",

makefile

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
.PHONY: clean build run logsmake
2+
3+
DC=docker compose -f .development.docker-compose.yml
4+
5+
default: help
6+
init: init-env check-env install
7+
8+
help:
9+
@echo "USAGE:"
10+
@echo " make [TARGET]"
11+
@echo
12+
@echo "EXAMPLES:"
13+
@echo " Build and start stack for local development with logs:"
14+
@echo " make build dev logs"
15+
@echo
16+
@echo "TARGETS:"
17+
@echo " init: initialize project"
18+
@echo
19+
@echo " // For local development"
20+
@echo " dev: start local development"
21+
@echo " dev-all: start all dev containers"
22+
@echo " dev-web: start dev web image"
23+
@echo " dev-cms: start dev cms image"
24+
@echo " dev-db: start dev db image"
25+
@echo
26+
@echo " // For building containers"
27+
@echo " build: build all"
28+
@echo " build-web: build web image"
29+
@echo " build-cms: build cms image"
30+
@echo
31+
@echo " // Utilities"
32+
@echo " install: install dependencies for all services"
33+
@echo " init-env: initialize .env files"
34+
@echo " check-env: compare keys in .env files with .env.example files"
35+
@echo " logs: show logs for all containers"
36+
@echo " clean: clean up workspace"
37+
@echo " stop: stop all containers"
38+
39+
## GENERAL
40+
41+
install:
42+
@echo "Installing web dependencies"
43+
@cd web && npm install
44+
@echo "Installing cms dependencies"
45+
@cd cms && npm install
46+
47+
init-env:
48+
test -f .env || cp .env.example .env
49+
test -f web/.env || cp .env.example web/.env
50+
cd cms/ && ( test -f .env || cp .env.example .env )
51+
@echo '-----------------------------------------------------'
52+
@echo 'please update the .env files with the missing secrets'
53+
54+
check-env:
55+
./scripts/check-env.sh .env.example .env
56+
./scripts/check-env.sh .env.example web/.env
57+
./scripts/check-env.sh cms/.env.example cms/.env
58+
59+
logs:
60+
$(DC) logs -t -f web db cms
61+
62+
clean:
63+
$(DC) down
64+
$(DC) down --volumes
65+
66+
stop:
67+
$(DC) stop
68+
69+
## DOCKER DEVELOPMENT
70+
dev: init dev-all
71+
72+
dev-all:
73+
$(DC) up -d
74+
75+
dev-web:
76+
$(DC) up -d web
77+
78+
dev-cms:
79+
$(DC) up -d cms
80+
81+
dev-database:
82+
$(DC) up -d db
83+
84+
## DOCKER BUILD
85+
build: init
86+
$(DC) build
87+
88+
build-web:
89+
$(DC) build web
90+
91+
build-backend:
92+
$(DC) build cms

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"description": "Next generation of Vim Landing Page",
55
"scripts": {
66
"dev": "docker compose -f .development.docker-compose.yml up -d --build",
7-
"setup": "node ./cms/init-env.js"
87
},
98
"author": "",
109
"license": "ISC"

scripts/check-env.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/sh
2+
3+
# USAGE: compare two .env files and check if keys are missing in the first.
4+
# keys are in the format of "KEY=VALUE"
5+
#
6+
# ARG 1: file which contains required keys
7+
# ARG 2: file to check for missing keys
8+
9+
die() {
10+
echo "error: $*"
11+
exit 1
12+
}
13+
14+
file="$1"
15+
ref_file="$2"
16+
17+
[ -f "$file" ] || die "missing arg: .env file to compare"
18+
[ -f "$ref_file" ] || die "missing arg: reference .env file"
19+
20+
echo "comparing '$file' to '$ref_file'"
21+
grep -v "^#" "$file" |
22+
while read -r line; do
23+
key=$(echo "$line" | cut -d'=' -f 1)
24+
grep -q "$key" "$ref_file" || die "key '$key' missing in '$ref_file'"
25+
done

0 commit comments

Comments
 (0)