Skip to content

Commit ae6ad01

Browse files
authored
Merge pull request #519 from getwud/feature/#501_multiple_custom_registries
⭐ [REGISTRY] - Add support for multiple registries of the same type
2 parents 505ab4a + 38f0ed6 commit ae6ad01

File tree

159 files changed

+15395
-14385
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

159 files changed

+15395
-14385
lines changed

.travis.yml

+26-27
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ os: linux
44

55
env:
66
global:
7-
- NODE_VERSION=18
87
- CC_TEST_REPORTER_ID=46ef31dae5b656e0f4be410a86bd83bdcf73e7d27ab33a704c197e6fe4bf02a0
8+
- DOCKER_PLATFORMS=linux/arm/v7,linux/arm64/v8,linux/amd64
9+
- IMAGE_NAME=wud
10+
- NODE_VERSION=23
911

1012
before_install:
1113

@@ -19,6 +21,7 @@ before_install:
1921
- echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
2022
- sudo apt-get update
2123
- sudo apt-get install -y docker-buildx-plugin
24+
- docker version
2225

2326
# Install Nodejs
2427
- nvm install $NODE_VERSION
@@ -94,7 +97,7 @@ script:
9497

9598
# Pull vaultwarden
9699
- docker pull vaultwarden/server
97-
- docker pull vaultwarden/server:1.32.6-alpine
100+
- docker pull vaultwarden/server:1.32.7-alpine
98101

99102
# Pull youtubedl
100103
- docker pull jeeaaasustest/youtube-dl
@@ -141,7 +144,7 @@ script:
141144
- docker run -d --name hub_traefik_245 --label 'wud.watch=true' --label 'wud.tag.include=^\d+\.\d+.\d+$' traefik:2.4.5
142145
- docker run -d --name hub_traefik_latest --label 'wud.watch=true' --label 'wud.watch.digest=true' --label 'wud.tag.include=^latest$' traefik
143146

144-
- docker run -d --name hub_vaultwarden_1222 --label 'wud.watch=true' --label 'wud.tag.include=^\d+\.\d+.\d+-alpine$' -e I_REALLY_WANT_VOLATILE_STORAGE=true vaultwarden/server:1.32.6-alpine
147+
- docker run -d --name hub_vaultwarden_1222 --label 'wud.watch=true' --label 'wud.tag.include=^\d+\.\d+.\d+-alpine$' -e I_REALLY_WANT_VOLATILE_STORAGE=true vaultwarden/server:1.32.7-alpine
145148
- docker run -d --name hub_vaultwarden_latest --label 'wud.watch=true' --label 'wud.watch.digest=true' --label 'wud.tag.include=^latest$' -e I_REALLY_WANT_VOLATILE_STORAGE=true vaultwarden/server
146149

147150
- docker run -d --name hub_youtubedb_latest --label 'wud.watch=true' --label 'wud.watch.digest=true' --label 'wud.tag.include=^latest$' jeeaaasustest/youtube-dl
@@ -160,45 +163,41 @@ script:
160163
--volume /var/run/docker.sock:/var/run/docker.sock
161164
--env WUD_TRIGGER_MOCK_EXAMPLE_MOCK=mock
162165
--env WUD_WATCHER_LOCAL_WATCHBYDEFAULT=false
163-
--env WUD_REGISTRY_ACR_CLIENTID="$ACR_CLIENT_ID"
164-
--env WUD_REGISTRY_ACR_CLIENTSECRET="$ACR_CLIENT_SECRET"
165-
--env WUD_REGISTRY_ECR_ACCESSKEYID="$AWS_ACCESSKEY_ID"
166-
--env WUD_REGISTRY_ECR_SECRETACCESSKEY="$AWS_SECRET_ACCESSKEY"
167-
--env WUD_REGISTRY_ECR_REGION=eu-west-1
168-
--env WUD_REGISTRY_GCR_CLIENTEMAIL="$GCR_CLIENT_EMAIL"
169-
--env WUD_REGISTRY_GCR_PRIVATEKEY="$GCR_PRIVATE_KEY"
170-
--env WUD_REGISTRY_GHCR_USERNAME="$GITHUB_USERNAME"
171-
--env WUD_REGISTRY_GHCR_TOKEN="$GITHUB_TOKEN"
172-
--env WUD_REGISTRY_GITLAB_TOKEN="$GITLAB_TOKEN"
173-
--env WUD_REGISTRY_LSCR_USERNAME="$GITHUB_USERNAME"
174-
--env WUD_REGISTRY_LSCR_TOKEN="$GITHUB_TOKEN"
166+
--env WUD_REGISTRY_ACR_PRIVATE_CLIENTID="$ACR_CLIENT_ID"
167+
--env WUD_REGISTRY_ACR_PRIVATE_CLIENTSECRET="$ACR_CLIENT_SECRET"
168+
--env WUD_REGISTRY_ECR_PRIVATE_ACCESSKEYID="$AWS_ACCESSKEY_ID"
169+
--env WUD_REGISTRY_ECR_PRIVATE_SECRETACCESSKEY="$AWS_SECRET_ACCESSKEY"
170+
--env WUD_REGISTRY_ECR_PRIVATE_REGION=eu-west-1
171+
--env WUD_REGISTRY_GCR_PRIVATE_CLIENTEMAIL="$GCR_CLIENT_EMAIL"
172+
--env WUD_REGISTRY_GCR_PRIVATE_PRIVATEKEY="$GCR_PRIVATE_KEY"
173+
--env WUD_REGISTRY_GHCR_PRIVATE_USERNAME="$GITHUB_USERNAME"
174+
--env WUD_REGISTRY_GHCR_PRIVATE_TOKEN="$GITHUB_TOKEN"
175+
--env WUD_REGISTRY_GITLAB_PRIVATE_TOKEN="$GITLAB_TOKEN"
176+
--env WUD_REGISTRY_LSCR_PRIVATE_USERNAME="$GITHUB_USERNAME"
177+
--env WUD_REGISTRY_LSCR_PRIVATE_TOKEN="$GITHUB_TOKEN"
175178
--env WUD_AUTH_BASIC_JOHN_USER="john"
176179
--env WUD_AUTH_BASIC_JOHN_HASH='$apr1$8zDVtSAY$62WBh9DspNbUKMZXYRsjS/'
177180
wud
178181
179-
# --env WUD_REGISTRY_HUB_LOGIN="$DOCKER_USERNAME"
180-
# --env WUD_REGISTRY_HUB_TOKEN="$DOCKER_PASSWORD"
181-
182182
# Give wud a little time to fetch all available updates
183183
- sleep 20
184184

185185
# Run E2E Tests
186186
- (cd e2e && npm run cucumber)
187187

188-
after_success:
189-
190188
# Report to Code Climate
191189
- (cd app && ./cc-test-reporter after-build -t lcov --debug --exit-code $TRAVIS_TEST_RESULT)
192190

193-
# Override image version with latest if main branch
194-
- if [ "$TRAVIS_BRANCH" == "main" ] ; then export IMAGE_VERSION=latest; fi
195-
196191
# Override image version with tag name if any
197-
- if [ ! -z "$TRAVIS_TAG" ] ; then export IMAGE_VERSION=$TRAVIS_TAG; fi
192+
- export DOCKER_TAGS="-t ${DOCKER_USERNAME}/${IMAGE_NAME}:${IMAGE_VERSION} -t ghcr.io/${GITHUB_USERNAME}/${IMAGE_NAME}:${IMAGE_VERSION}"
193+
- |
194+
if [ ! -z "$TRAVIS_TAG" ]
195+
then
196+
export DOCKER_TAGS="${DOCKER_TAGS} -t ${DOCKER_USERNAME}/${IMAGE_NAME}:latest -t ghcr.io/${GITHUB_USERNAME}/${IMAGE_NAME}:latest"
197+
fi
198198
199199
# Build & push image
200200
- docker login -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWORD"
201201
- docker login ghcr.io -u "$GITHUB_USERNAME" -p "$GITHUB_TOKEN"
202-
- docker version
203-
- make prepare
204-
- make build IMAGE_NAME=wud IMAGE_VERSION=$IMAGE_VERSION PLATFORMS=linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/amd64 DOCKER_USERNAME=$DOCKER_USERNAME GITHUB_USERNAME=$GITHUB_USERNAME
202+
- docker buildx create --use
203+
- docker buildx build --push --platform ${DOCKER_PLATFORMS} --build-arg WUD_VERSION=${IMAGE_VERSION} ${DOCKER_TAGS} .

Docker.entrypoint.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/usr/bin/env bash
22
set -e
33

44
if [ $1 == "node" ] && [ $2 == "index" ] && [ ${WUD_LOG_FORMAT} != "json" ]; then

Dockerfile

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Common Stage
2-
FROM node:18-alpine as base
2+
FROM node:23-slim as base
33

44
LABEL maintainer="fmartinou"
55
EXPOSE 3000
@@ -15,9 +15,9 @@ WORKDIR /home/node/app
1515
RUN mkdir /store
1616

1717
# Add TZDATA to allow easy local time configuration
18-
RUN apk update \
19-
&& apk add --no-cache tzdata openssl \
20-
&& rm -rf /var/cache/apk/*
18+
RUN apt update \
19+
&& apt install tzdata openssl \
20+
&& rm -rf /var/cache/apt/*
2121

2222
# Dependencies stage
2323
FROM base as dependencies

Makefile

-17
This file was deleted.

app/.babelrc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"plugins": ["babel-plugin-rewire"]
3-
}
2+
"plugins": ["babel-plugin-rewire"]
3+
}

app/.eslintrc

-11
This file was deleted.

app/.prettierrc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"singleQuote": true,
3+
"tabWidth": 4
4+
}

app/api/auth.js

+32-23
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,24 @@ function useStrategy(authentication, app) {
5454
passport.use(authentication.getId(), strategy);
5555
STRATEGY_IDS.push(authentication.getId());
5656
} catch (e) {
57-
log.warn(`Unable to apply authentication ${authentication.getId()} (${e.message})`);
57+
log.warn(
58+
`Unable to apply authentication ${authentication.getId()} (${e.message})`,
59+
);
5860
}
5961
}
6062

6163
function getUniqueStrategies() {
62-
const strategies = Object.values(registry.getState().authentication)
63-
.map((authentication) => authentication.getStrategyDescription());
64+
const strategies = Object.values(registry.getState().authentication).map(
65+
(authentication) => authentication.getStrategyDescription(),
66+
);
6467
const uniqueStrategies = [];
6568
strategies.forEach((strategy) => {
66-
if (!(uniqueStrategies
67-
.find(
68-
(item) => item.type === strategy.type
69-
&& item.name === strategy.name,
70-
))) {
69+
if (
70+
!uniqueStrategies.find(
71+
(item) =>
72+
item.type === strategy.type && item.name === strategy.name,
73+
)
74+
) {
7175
uniqueStrategies.push(strategy);
7276
}
7377
});
@@ -84,7 +88,9 @@ function getStrategies(req, res) {
8488
}
8589

8690
function getLogoutRedirectUrl() {
87-
const strategyWithRedirectUrl = getUniqueStrategies().find((strategy) => strategy.logoutUrl);
91+
const strategyWithRedirectUrl = getUniqueStrategies().find(
92+
(strategy) => strategy.logoutUrl,
93+
);
8894
if (strategyWithRedirectUrl) {
8995
return strategyWithRedirectUrl.logoutUrl;
9096
}
@@ -128,27 +134,30 @@ function logout(req, res) {
128134
*/
129135
function init(app) {
130136
// Init express session
131-
app.use(session({
132-
store: new LokiStore({
133-
path: `${store.getConfiguration().path}/${store.getConfiguration().file}`,
134-
ttl: 604800, // 7 days
137+
app.use(
138+
session({
139+
store: new LokiStore({
140+
path: `${store.getConfiguration().path}/${store.getConfiguration().file}`,
141+
ttl: 604800, // 7 days
142+
}),
143+
secret: getSessionSecretKey(),
144+
resave: false,
145+
saveUninitialized: false,
146+
cookie: {
147+
httpOnly: true,
148+
maxAge: getCookieMaxAge(7),
149+
},
135150
}),
136-
secret: getSessionSecretKey(),
137-
resave: false,
138-
saveUninitialized: false,
139-
cookie: {
140-
httpOnly: true,
141-
maxAge: getCookieMaxAge(7),
142-
},
143-
}));
151+
);
144152

145153
// Init passport middleware
146154
app.use(passport.initialize());
147155
app.use(passport.session());
148156

149157
// Register all authentications
150-
Object.values(registry.getState().authentication)
151-
.forEach((authentication) => useStrategy(authentication, app));
158+
Object.values(registry.getState().authentication).forEach(
159+
(authentication) => useStrategy(authentication, app),
160+
);
152161

153162
passport.serializeUser((user, done) => {
154163
done(null, JSON.stringify(user));

app/api/component.js

+7-10
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ function mapComponentToItem(key, component) {
2727
function mapComponentsToList(components) {
2828
return Object.keys(components)
2929
.map((key) => mapComponentToItem(key, components[key]))
30-
.sort(byValues([
31-
[(x) => x.type, byString()],
32-
[(x) => x.name, byString()],
33-
]));
30+
.sort(
31+
byValues([
32+
[(x) => x.type, byString()],
33+
[(x) => x.name, byString()],
34+
]),
35+
);
3436
}
3537

3638
/**
@@ -50,12 +52,7 @@ function getAll(req, res, kind) {
5052
*/
5153
function getById(req, res, kind) {
5254
const { type, name } = req.params;
53-
let id = `${kind}.${type}.${name}`;
54-
55-
// Hack for registries because id and name are equivalent
56-
if (kind === 'registry') {
57-
id = `${name}`;
58-
}
55+
const id = `${type}.${name}`;
5956
const component = registry.getState()[kind][id];
6057
if (component) {
6158
res.status(200).json(mapComponentToItem(id, component));

app/api/container.js

+38-11
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ function deleteContainer(req, res) {
8888
*/
8989
async function watchContainers(req, res) {
9090
try {
91-
await Promise.all(Object.values(getWatchers()).map((watcher) => watcher.watch()));
91+
await Promise.all(
92+
Object.values(getWatchers()).map((watcher) => watcher.watch()),
93+
);
9294
getContainers(req, res);
9395
} catch (e) {
9496
res.status(500).json({
@@ -103,22 +105,45 @@ async function getContainerTriggers(req, res) {
103105
const container = storeContainer.getContainer(id);
104106
if (container) {
105107
const allTriggers = mapComponentsToList(getTriggers());
106-
const includedTriggers = container.triggerInclude ? container.triggerInclude.split(/\s*,\s*/).map((includedTrigger) => Trigger.parseIncludeOrIncludeTriggerString(includedTrigger)) : undefined;
107-
const excludedTriggers = container.triggerExclude ? container.triggerExclude.split(/\s*,\s*/).map((excludedTrigger) => Trigger.parseIncludeOrIncludeTriggerString(excludedTrigger)) : undefined;
108+
const includedTriggers = container.triggerInclude
109+
? container.triggerInclude
110+
.split(/\s*,\s*/)
111+
.map((includedTrigger) =>
112+
Trigger.parseIncludeOrIncludeTriggerString(
113+
includedTrigger,
114+
),
115+
)
116+
: undefined;
117+
const excludedTriggers = container.triggerExclude
118+
? container.triggerExclude
119+
.split(/\s*,\s*/)
120+
.map((excludedTrigger) =>
121+
Trigger.parseIncludeOrIncludeTriggerString(
122+
excludedTrigger,
123+
),
124+
)
125+
: undefined;
108126
const associatedTriggers = [];
109127
allTriggers.forEach((trigger) => {
110128
const triggerToAssociate = { ...trigger };
111129
let associated = true;
112130
if (includedTriggers) {
113-
const includedTrigger = includedTriggers.find((tr) => tr.id === trigger.id);
131+
const includedTrigger = includedTriggers.find(
132+
(tr) => tr.id === trigger.id,
133+
);
114134
if (includedTrigger) {
115-
triggerToAssociate.configuration.threshold = includedTrigger.threshold;
135+
triggerToAssociate.configuration.threshold =
136+
includedTrigger.threshold;
116137
} else {
117138
associated = false;
118139
}
119140
}
120-
if (excludedTriggers && excludedTriggers
121-
.map((excludedTrigger) => excludedTrigger.id).includes(trigger.id)) {
141+
if (
142+
excludedTriggers &&
143+
excludedTriggers
144+
.map((excludedTrigger) => excludedTrigger.id)
145+
.includes(trigger.id)
146+
) {
122147
associated = false;
123148
}
124149
if (associated) {
@@ -142,7 +167,7 @@ async function watchContainer(req, res) {
142167

143168
const container = storeContainer.getContainer(id);
144169
if (container) {
145-
const watcher = getWatchers()[`watcher.docker.${container.watcher}`];
170+
const watcher = getWatchers()[`docker.${container.watcher}`];
146171
if (!watcher) {
147172
res.status(500).json({
148173
error: `No provider found for container ${id} and provider ${container.watcher}`,
@@ -152,14 +177,16 @@ async function watchContainer(req, res) {
152177
// Ensure container is still in store
153178
// (for cases where it has been removed before running an new watchAll)
154179
const containers = await watcher.getContainers();
155-
const containerFound = containers
156-
.find((containerInList) => containerInList.id === container.id);
180+
const containerFound = containers.find(
181+
(containerInList) => containerInList.id === container.id,
182+
);
157183

158184
if (!containerFound) {
159185
res.status(404).send();
160186
} else {
161187
// Run watchContainer from the Provider
162-
const containerReport = await watcher.watchContainer(container);
188+
const containerReport =
189+
await watcher.watchContainer(container);
163190
res.status(200).json(containerReport.container);
164191
}
165192
} catch (e) {

0 commit comments

Comments
 (0)