-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMakefile
More file actions
177 lines (139 loc) · 6.39 KB
/
Copy pathMakefile
File metadata and controls
177 lines (139 loc) · 6.39 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
include .env
-include .envrc
export
SHELL := $(shell which bash)
# Docker command to use when running as a dependency (shallow clone)
DOCKER_RUN=COMPOSE_FILE=${COMPOSE_FILE_RUN} docker
# Initialises Playwright for tests. Note this requires sudo access
# Not currently using webkit as it fails intermittently
init:
npm ci
npx playwright install --with-deps chromium firefox
install:
mvn clean install
build_languages:
node build-scripts/build_languages.mjs
pre_build: build_languages
# Generate a unique id for the build
cp -rf /proc/sys/kernel/random/uuid runtime-scripts/image_id
build: pre_build
docker compose build
build_test: build
dev: init run_deps build
# Need a long wait timeout in case full migrations are running
_up:
docker compose up --wait --wait-timeout 120
up: create_user _up
build_testcontainer: pre_build
docker build --progress=plain --target=testcontainer --tag=ghcr.io/openfoodfacts/openfoodfacts-auth:testcontainer .
# Minimal container used by other projects for integration tests. Make target here is just to test it can start
integration_test_target:
@echo ******************************************************************************************
@echo * Check the docker logs for any errors. You can test the client on http://localhost:5606 *
@echo * Use Ctrl+C to exit and delete the container *
@echo ******************************************************************************************
docker run --rm -p 5606:8080 ghcr.io/openfoodfacts/openfoodfacts-auth:testcontainer
show_keycloak_logs:
docker compose logs keycloak
down:
docker compose down --remove-orphans
hdown:
docker compose down -v --remove-orphans
prune:
docker system prune -af
create_externals:
docker volume create ${COMPOSE_PROJECT_NAME}_pgdata
create_common_net:
docker network create --driver=bridge --subnet="172.30.0.0/16" ${COMMON_NET_NAME} \
|| echo "network already exists"
remove_externals:
docker volume rm ${COMPOSE_PROJECT_NAME}_pgdata
test: up
npx playwright test ${args}
# Update expected screen shots. Need to be able to run this from CI in order to get a consistent environment
update_screenshots: up
npx playwright test --update-snapshots changed screenshots.spec.ts
# We keep a copy of the Keycloak themes in our own source control so that we can easily see diffs after keycloak upgrades.
# These themese aren't actually used in the deployment, they are just for reference
# Usage: make refresh_themes KEYCLOAK_VERSION=...
refresh_themes:
rm -rf theme/theme
mkdir theme/theme
wget https://github.com/keycloak/keycloak/releases/download/${KEYCLOAK_VERSION}/keycloak-${KEYCLOAK_VERSION}.tar.gz
tar -xzvf keycloak-${KEYCLOAK_VERSION}.tar.gz keycloak-${KEYCLOAK_VERSION}/lib/lib/main/org.keycloak.keycloak-themes-${KEYCLOAK_VERSION}.jar --strip-components=4
unzip org.keycloak.keycloak-themes-${KEYCLOAK_VERSION}.jar \
theme/base/account/messages/* \
theme/base/admin/messages/* \
theme/base/email/messages/* \
theme/base/login/messages/* \
theme/base/email/html/template.ftl \
theme/keycloak.v2/login/user-profile-commons.ftl \
-d theme
rm org.keycloak.keycloak-themes-${KEYCLOAK_VERSION}.jar
tar -xzvf keycloak-${KEYCLOAK_VERSION}.tar.gz keycloak-${KEYCLOAK_VERSION}/lib/lib/main/org.keycloak.keycloak-account-ui-${KEYCLOAK_VERSION}.jar --strip-components=4
unzip org.keycloak.keycloak-account-ui-${KEYCLOAK_VERSION}.jar \
theme/keycloak.v3/account/index.ftl \
theme/keycloak.v3/account/messages/* \
theme/keycloak.v3/account/resources/content.json \
-d theme
rm org.keycloak.keycloak-account-ui-${KEYCLOAK_VERSION}.jar
rm keycloak-${KEYCLOAK_VERSION}.tar.gz
$(MAKE) refresh_messages
# Updates the Keycloak version in the pom.xml file as using ${env.KEYCLOAK_VERSION} can be tricky
# with IDE's like VSCode that load Maven before the .env file has been evaluated
update_keycloak_version:
@node build-scripts/update_keycloak_version.mjs
# This will find any existing Keycloak translations for messages defined in the messages_en file
# It also downloads the current languages and countries taxonomies from openfoodfacts-server and
# adds any new languages or countries to the keycloak configuration.
refresh_messages:
node build-scripts/refresh_messages.mjs
# Creates the keycloak user in the shared-services postgresql database
create_user: run_deps
cd ${DEPS_DIR}/openfoodfacts-shared-services && $(MAKE) create_user username=${KC_DB_USERNAME} password=${KC_DB_PASSWORD}
# Create user / database in production PostgreSQL instance
create_user_prod:
@docker run --rm --entrypoint bin/bash postgres:16-alpine \
-c "PGPASSWORD=${PG_BOOTSTRAP_PASSWORD} psql -h ${KC_DB_URL_HOST} -d postgres -U ${PG_BOOTSTRAP_USERNAME} -c \"create role ${KC_DB_USERNAME} with password '${KC_DB_PASSWORD}' login createdb\"; \
PGPASSWORD=${KC_DB_PASSWORD} psql -h ${KC_DB_URL_HOST} -d postgres -U ${KC_DB_USERNAME} -c \"create database ${KC_DB_USERNAME}\" || true "
build_asyncapi:
npm install
cd docs/events && npx asyncapi generate fromTemplate openfoodfacts-auth.yaml @asyncapi/html-template@3.0.0 --use-new-generator --param singleFile=true outFilename=openfoodfacts-auth.html --force-write --output=.
# Called by other projects to start this project as a dependency
# Use docker compose pull to ensure we get the latest keycloak image (unless we are using the dev image)
run: create_user
if [ "${KEYCLOAK_TAG}" != "dev" ]; then \
${DOCKER_RUN} compose pull keycloak; fi && \
if ! ${DOCKER_RUN} compose up --wait --wait-timeout 120; then \
${DOCKER_RUN} compose logs && exit 1; fi
stop:
${DOCKER_RUN} compose stop
$(MAKE) stop_deps
# Space delimited list of dependant projects
DEPS=openfoodfacts-shared-services
# Set the DEPS_DIR if it hasn't been set already
ifeq (${DEPS_DIR},)
export DEPS_DIR=${PWD}/deps
endif
# Run dependent projects
run_deps: create_externals clone_deps
@for dep in ${DEPS} ; do \
cd ${DEPS_DIR}/$$dep && $(MAKE) run; \
done
# Stop dependent projects
stop_deps:
@for dep in ${DEPS} ; do \
cd ${DEPS_DIR}/$$dep && ( $(MAKE) stop || env -i docker compose stop ) ; \
done
# Clone dependent projects without running them (used to pull in yml for tests)
clone_deps:
@mkdir -p ${DEPS_DIR}; \
for dep in ${DEPS} ; do \
echo $$dep; \
if [ ! -d ${DEPS_DIR}/$$dep ]; then \
git clone --filter=blob:none --sparse \
https://github.com/openfoodfacts/$$dep.git ${DEPS_DIR}/$$dep; \
else \
cd ${DEPS_DIR}/$$dep && git pull; \
fi; \
done