Migrated from GitHub
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- data/.dockerignore +5 -0
- data/.nvmrc +1 -0
- data/CONTRIBUTING.md +179 -0
- data/Dockerfile +66 -0
- data/Dockerfile.cloud +61 -0
- data/Dockerfile.monitoring +41 -0
- data/Dockerfile.schedule +36 -0
- data/Dockerfile.server +36 -0
- data/GUIDES.md +49 -0
- data/LICENSE.MD +26 -0
- data/SECURITY.md +28 -0
- data/TERMS_AND_CONDITIONS.md +22 -0
- data/apps/api/.env.example +2 -0
- data/apps/api/package.json +33 -0
- data/apps/api/src/index.ts +61 -0
- data/apps/api/src/logger.ts +10 -0
- data/apps/api/src/schema.ts +34 -0
- data/apps/api/src/utils.ts +82 -0
- data/apps/api/tsconfig.json +18 -0
- data/apps/dokploy/.dockerignore +5 -0
- data/apps/dokploy/.env.example +3 -0
- data/apps/dokploy/.env.production.example +3 -0
- data/apps/dokploy/.nvmrc +1 -0
- data/apps/dokploy/LICENSE.MD +26 -0
- data/apps/dokploy/__test__/compose/compose.test.ts +476 -0
- data/apps/dokploy/__test__/compose/config/config-root.test.ts +178 -0
- data/apps/dokploy/__test__/compose/config/config-service.test.ts +197 -0
- data/apps/dokploy/__test__/compose/config/config.test.ts +246 -0
- data/apps/dokploy/__test__/compose/domain/labels.test.ts +109 -0
- data/apps/dokploy/__test__/compose/domain/network-root.test.ts +29 -0
- data/apps/dokploy/__test__/compose/domain/network-service.test.ts +24 -0
- data/apps/dokploy/__test__/compose/network/network-root.test.ts +310 -0
- data/apps/dokploy/__test__/compose/network/network-service.test.ts +273 -0
- data/apps/dokploy/__test__/compose/network/network.test.ts +334 -0
- data/apps/dokploy/__test__/compose/secrets/secret-root.test.ts +103 -0
- data/apps/dokploy/__test__/compose/secrets/secret-services.test.ts +113 -0
- data/apps/dokploy/__test__/compose/secrets/secret.test.ts +159 -0
- data/apps/dokploy/__test__/compose/service/service-container-name.test.ts +59 -0
- data/apps/dokploy/__test__/compose/service/service-depends-on.test.ts +150 -0
- data/apps/dokploy/__test__/compose/service/service-extends.test.ts +131 -0
- data/apps/dokploy/__test__/compose/service/service-links.test.ts +76 -0
- data/apps/dokploy/__test__/compose/service/service-names.test.ts +49 -0
- data/apps/dokploy/__test__/compose/service/service.test.ts +375 -0
- data/apps/dokploy/__test__/compose/service/sevice-volumes-from.test.ts +78 -0
- data/apps/dokploy/__test__/compose/volume/volume-2.test.ts +1174 -0
- data/apps/dokploy/__test__/compose/volume/volume-root.test.ts +195 -0
- data/apps/dokploy/__test__/compose/volume/volume-services.test.ts +81 -0
- data/apps/dokploy/__test__/compose/volume/volume.test.ts +284 -0
- data/apps/dokploy/__test__/deploy/github.test.ts +98 -0
- data/apps/dokploy/__test__/drop/drop.test.test.ts +217 -0
data/.dockerignore
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
node_modules
|
| 2 |
+
.git
|
| 3 |
+
.gitignore
|
| 4 |
+
*.md
|
| 5 |
+
dist
|
data/.nvmrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
20.16.0
|
data/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Contributing
|
| 2 |
+
|
| 3 |
+
Hey, thanks for your interest in contributing to Dokploy! We appreciate your help and taking your time to contribute.
|
| 4 |
+
|
| 5 |
+
Before you start, please first discuss the feature/bug you want to add with the owners and comunity via github issues.
|
| 6 |
+
|
| 7 |
+
We have a few guidelines to follow when contributing to this project:
|
| 8 |
+
|
| 9 |
+
- [Commit Convention](#commit-convention)
|
| 10 |
+
- [Setup](#setup)
|
| 11 |
+
- [Development](#development)
|
| 12 |
+
- [Build](#build)
|
| 13 |
+
- [Pull Request](#pull-request)
|
| 14 |
+
|
| 15 |
+
## Commit Convention
|
| 16 |
+
|
| 17 |
+
Before you create a Pull Request, please make sure your commit message follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) specification.
|
| 18 |
+
|
| 19 |
+
### Commit Message Format
|
| 20 |
+
|
| 21 |
+
```
|
| 22 |
+
<type>[optional scope]: <description>
|
| 23 |
+
|
| 24 |
+
[optional body]
|
| 25 |
+
|
| 26 |
+
[optional footer(s)]
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
#### Type
|
| 30 |
+
|
| 31 |
+
Must be one of the following:
|
| 32 |
+
|
| 33 |
+
- **feat**: A new feature
|
| 34 |
+
- **fix**: A bug fix
|
| 35 |
+
- **docs**: Documentation only changes
|
| 36 |
+
- **style**: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
|
| 37 |
+
- **refactor**: A code change that neither fixes a bug nor adds a feature
|
| 38 |
+
- **perf**: A code change that improves performance
|
| 39 |
+
- **test**: Adding missing tests or correcting existing tests
|
| 40 |
+
- **build**: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
|
| 41 |
+
- **ci**: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
|
| 42 |
+
- **chore**: Other changes that don't modify `src` or `test` files
|
| 43 |
+
- **revert**: Reverts a previous commit
|
| 44 |
+
|
| 45 |
+
Example:
|
| 46 |
+
|
| 47 |
+
```
|
| 48 |
+
feat: add new feature
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
## Setup
|
| 52 |
+
|
| 53 |
+
Before you start, please make the clone based on the `canary` branch, since the `main` branch is the source of truth and should always reflect the latest stable release, also the PRs will be merged to the `canary` branch.
|
| 54 |
+
|
| 55 |
+
We use Node v20.16.0 and recommend this specific version. If you have nvm installed, you can run `nvm install 20.16.0 && nvm use` in the root directory.
|
| 56 |
+
|
| 57 |
+
```bash
|
| 58 |
+
git clone https://github.com/dokploy/dokploy.git
|
| 59 |
+
cd dokploy
|
| 60 |
+
pnpm install
|
| 61 |
+
cp apps/dokploy/.env.example apps/dokploy/.env
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
## Requirements
|
| 65 |
+
|
| 66 |
+
- [Docker](/GUIDES.md#docker)
|
| 67 |
+
|
| 68 |
+
### Setup
|
| 69 |
+
|
| 70 |
+
Run the command that will spin up all the required services and files.
|
| 71 |
+
|
| 72 |
+
```bash
|
| 73 |
+
pnpm run dokploy:setup
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
Run this script
|
| 77 |
+
|
| 78 |
+
```bash
|
| 79 |
+
pnpm run server:script
|
| 80 |
+
```
|
| 81 |
+
|
| 82 |
+
Now run the development server.
|
| 83 |
+
|
| 84 |
+
```bash
|
| 85 |
+
pnpm run dokploy:dev
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
Go to http://localhost:3000 to see the development server
|
| 89 |
+
|
| 90 |
+
Note: this project uses Biome. If your editor is configured to use another formatter such as Prettier, it's recommended to either change it to use Biome or turn it off.
|
| 91 |
+
|
| 92 |
+
## Build
|
| 93 |
+
|
| 94 |
+
```bash
|
| 95 |
+
pnpm run dokploy:build
|
| 96 |
+
```
|
| 97 |
+
|
| 98 |
+
## Docker
|
| 99 |
+
|
| 100 |
+
To build the docker image
|
| 101 |
+
|
| 102 |
+
```bash
|
| 103 |
+
pnpm run docker:build
|
| 104 |
+
```
|
| 105 |
+
|
| 106 |
+
To push the docker image
|
| 107 |
+
|
| 108 |
+
```bash
|
| 109 |
+
pnpm run docker:push
|
| 110 |
+
```
|
| 111 |
+
|
| 112 |
+
## Password Reset
|
| 113 |
+
|
| 114 |
+
In the case you lost your password, you can reset it using the following command
|
| 115 |
+
|
| 116 |
+
```bash
|
| 117 |
+
pnpm run reset-password
|
| 118 |
+
```
|
| 119 |
+
|
| 120 |
+
If you want to test the webhooks on development mode using localtunnel, make sure to install `localtunnel`
|
| 121 |
+
|
| 122 |
+
```bash
|
| 123 |
+
bunx lt --port 3000
|
| 124 |
+
```
|
| 125 |
+
|
| 126 |
+
If you run into permission issues of docker run the following command
|
| 127 |
+
|
| 128 |
+
```bash
|
| 129 |
+
sudo chown -R USERNAME dokploy or sudo chown -R $(whoami) ~/.docker
|
| 130 |
+
```
|
| 131 |
+
|
| 132 |
+
## Application deploy
|
| 133 |
+
|
| 134 |
+
In case you want to deploy the application on your machine and you selected nixpacks or buildpacks, you need to install first.
|
| 135 |
+
|
| 136 |
+
```bash
|
| 137 |
+
# Install Nixpacks
|
| 138 |
+
curl -sSL https://nixpacks.com/install.sh -o install.sh \
|
| 139 |
+
&& chmod +x install.sh \
|
| 140 |
+
&& ./install.sh
|
| 141 |
+
```
|
| 142 |
+
|
| 143 |
+
```bash
|
| 144 |
+
# Install Railpack
|
| 145 |
+
curl -sSL https://railpack.com/install.sh | sh
|
| 146 |
+
```
|
| 147 |
+
|
| 148 |
+
```bash
|
| 149 |
+
# Install Buildpacks
|
| 150 |
+
curl -sSL "https://github.com/buildpacks/pack/releases/download/v0.35.0/pack-v0.35.0-linux.tgz" | tar -C /usr/local/bin/ --no-same-owner -xzv pack
|
| 151 |
+
```
|
| 152 |
+
|
| 153 |
+
## Pull Request
|
| 154 |
+
|
| 155 |
+
- The `main` branch is the source of truth and should always reflect the latest stable release.
|
| 156 |
+
- Create a new branch for each feature or bug fix.
|
| 157 |
+
- Make sure to add tests for your changes.
|
| 158 |
+
- Make sure to update the documentation for any changes Go to the [docs.dokploy.com](https://docs.dokploy.com) website to see the changes.
|
| 159 |
+
- When creating a pull request, please provide a clear and concise description of the changes made.
|
| 160 |
+
- If you include a video or screenshot, would be awesome so we can see the changes in action.
|
| 161 |
+
- If your pull request fixes an open issue, please reference the issue in the pull request description.
|
| 162 |
+
- Once your pull request is merged, you will be automatically added as a contributor to the project.
|
| 163 |
+
|
| 164 |
+
Thank you for your contribution!
|
| 165 |
+
|
| 166 |
+
## Templates
|
| 167 |
+
|
| 168 |
+
To add a new template, go to `https://github.com/Dokploy/templates` repository and read the README.md file.
|
| 169 |
+
|
| 170 |
+
### Recommendations
|
| 171 |
+
|
| 172 |
+
- Use the same name of the folder as the id of the template.
|
| 173 |
+
- The logo should be in the public folder.
|
| 174 |
+
- If you want to show a domain in the UI, please add the `_HOST` suffix at the end of the variable name.
|
| 175 |
+
- Test first on a vps or a server to make sure the template works.
|
| 176 |
+
|
| 177 |
+
## Docs & Website
|
| 178 |
+
|
| 179 |
+
To contribute to the Dokploy docs or website, please go to this [repository](https://github.com/Dokploy/website).
|
data/Dockerfile
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM node:20.9-slim AS base
|
| 2 |
+
ENV PNPM_HOME="/pnpm"
|
| 3 |
+
ENV PATH="$PNPM_HOME:$PATH"
|
| 4 |
+
RUN corepack enable
|
| 5 |
+
|
| 6 |
+
FROM base AS build
|
| 7 |
+
COPY . /usr/src/app
|
| 8 |
+
WORKDIR /usr/src/app
|
| 9 |
+
|
| 10 |
+
RUN apt-get update && apt-get install -y python3 make g++ git python3-pip pkg-config libsecret-1-dev && rm -rf /var/lib/apt/lists/*
|
| 11 |
+
|
| 12 |
+
# Install dependencies
|
| 13 |
+
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
|
| 14 |
+
|
| 15 |
+
# Deploy only the dokploy app
|
| 16 |
+
|
| 17 |
+
ENV NODE_ENV=production
|
| 18 |
+
RUN pnpm --filter=@dokploy/server build
|
| 19 |
+
RUN pnpm --filter=./apps/dokploy run build
|
| 20 |
+
|
| 21 |
+
RUN pnpm --filter=./apps/dokploy --prod deploy /prod/dokploy
|
| 22 |
+
|
| 23 |
+
RUN cp -R /usr/src/app/apps/dokploy/.next /prod/dokploy/.next
|
| 24 |
+
RUN cp -R /usr/src/app/apps/dokploy/dist /prod/dokploy/dist
|
| 25 |
+
|
| 26 |
+
FROM base AS dokploy
|
| 27 |
+
WORKDIR /app
|
| 28 |
+
|
| 29 |
+
# Set production
|
| 30 |
+
ENV NODE_ENV=production
|
| 31 |
+
|
| 32 |
+
RUN apt-get update && apt-get install -y curl unzip zip apache2-utils iproute2 rsync git-lfs && git lfs install && rm -rf /var/lib/apt/lists/*
|
| 33 |
+
|
| 34 |
+
# Copy only the necessary files
|
| 35 |
+
COPY --from=build /prod/dokploy/.next ./.next
|
| 36 |
+
COPY --from=build /prod/dokploy/dist ./dist
|
| 37 |
+
COPY --from=build /prod/dokploy/next.config.mjs ./next.config.mjs
|
| 38 |
+
COPY --from=build /prod/dokploy/public ./public
|
| 39 |
+
COPY --from=build /prod/dokploy/package.json ./package.json
|
| 40 |
+
COPY --from=build /prod/dokploy/drizzle ./drizzle
|
| 41 |
+
COPY .env.production ./.env
|
| 42 |
+
COPY --from=build /prod/dokploy/components.json ./components.json
|
| 43 |
+
COPY --from=build /prod/dokploy/node_modules ./node_modules
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
# Install docker
|
| 47 |
+
RUN curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh && rm get-docker.sh && curl https://rclone.org/install.sh | bash
|
| 48 |
+
|
| 49 |
+
# Install Nixpacks and tsx
|
| 50 |
+
# | VERBOSE=1 VERSION=1.21.0 bash
|
| 51 |
+
|
| 52 |
+
ARG NIXPACKS_VERSION=1.39.0
|
| 53 |
+
RUN curl -sSL https://nixpacks.com/install.sh -o install.sh \
|
| 54 |
+
&& chmod +x install.sh \
|
| 55 |
+
&& ./install.sh \
|
| 56 |
+
&& pnpm install -g tsx
|
| 57 |
+
|
| 58 |
+
# Install Railpack
|
| 59 |
+
ARG RAILPACK_VERSION=0.0.64
|
| 60 |
+
RUN curl -sSL https://railpack.com/install.sh | bash
|
| 61 |
+
|
| 62 |
+
# Install buildpacks
|
| 63 |
+
COPY --from=buildpacksio/pack:0.35.0 /usr/local/bin/pack /usr/local/bin/pack
|
| 64 |
+
|
| 65 |
+
EXPOSE 3000
|
| 66 |
+
CMD [ "pnpm", "start" ]
|
data/Dockerfile.cloud
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM node:20.9-slim AS base
|
| 2 |
+
ENV PNPM_HOME="/pnpm"
|
| 3 |
+
ENV PATH="$PNPM_HOME:$PATH"
|
| 4 |
+
RUN corepack enable
|
| 5 |
+
|
| 6 |
+
FROM base AS build
|
| 7 |
+
COPY . /usr/src/app
|
| 8 |
+
WORKDIR /usr/src/app
|
| 9 |
+
|
| 10 |
+
RUN apt-get update && apt-get install -y python3 make g++ git python3-pip pkg-config libsecret-1-dev && rm -rf /var/lib/apt/lists/*
|
| 11 |
+
|
| 12 |
+
# Install dependencies
|
| 13 |
+
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm --filter=@dokploy/server --filter=./apps/dokploy install --frozen-lockfile
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
# Deploy only the dokploy app
|
| 17 |
+
ARG NEXT_PUBLIC_UMAMI_HOST
|
| 18 |
+
ENV NEXT_PUBLIC_UMAMI_HOST=$NEXT_PUBLIC_UMAMI_HOST
|
| 19 |
+
|
| 20 |
+
ARG NEXT_PUBLIC_UMAMI_WEBSITE_ID
|
| 21 |
+
ENV NEXT_PUBLIC_UMAMI_WEBSITE_ID=$NEXT_PUBLIC_UMAMI_WEBSITE_ID
|
| 22 |
+
|
| 23 |
+
ARG NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY
|
| 24 |
+
ENV NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=$NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY
|
| 25 |
+
|
| 26 |
+
ENV NODE_ENV=production
|
| 27 |
+
RUN pnpm --filter=@dokploy/server build
|
| 28 |
+
RUN pnpm --filter=./apps/dokploy run build
|
| 29 |
+
|
| 30 |
+
RUN pnpm --filter=./apps/dokploy --prod deploy /prod/dokploy
|
| 31 |
+
|
| 32 |
+
RUN cp -R /usr/src/app/apps/dokploy/.next /prod/dokploy/.next
|
| 33 |
+
RUN cp -R /usr/src/app/apps/dokploy/dist /prod/dokploy/dist
|
| 34 |
+
|
| 35 |
+
FROM base AS dokploy
|
| 36 |
+
WORKDIR /app
|
| 37 |
+
|
| 38 |
+
# Set production
|
| 39 |
+
ENV NODE_ENV=production
|
| 40 |
+
|
| 41 |
+
RUN apt-get update && apt-get install -y curl unzip apache2-utils && rm -rf /var/lib/apt/lists/*
|
| 42 |
+
|
| 43 |
+
# Copy only the necessary files
|
| 44 |
+
COPY --from=build /prod/dokploy/.next ./.next
|
| 45 |
+
COPY --from=build /prod/dokploy/dist ./dist
|
| 46 |
+
COPY --from=build /prod/dokploy/next.config.mjs ./next.config.mjs
|
| 47 |
+
COPY --from=build /prod/dokploy/public ./public
|
| 48 |
+
COPY --from=build /prod/dokploy/package.json ./package.json
|
| 49 |
+
COPY --from=build /prod/dokploy/drizzle ./drizzle
|
| 50 |
+
COPY --from=build /prod/dokploy/components.json ./components.json
|
| 51 |
+
COPY --from=build /prod/dokploy/node_modules ./node_modules
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
# Install RCLONE
|
| 55 |
+
RUN curl https://rclone.org/install.sh | bash
|
| 56 |
+
|
| 57 |
+
# tsx
|
| 58 |
+
RUN pnpm install -g tsx
|
| 59 |
+
|
| 60 |
+
EXPOSE 3000
|
| 61 |
+
CMD [ "pnpm", "start" ]
|
data/Dockerfile.monitoring
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Build stage
|
| 2 |
+
FROM golang:1.21-alpine3.19 AS builder
|
| 3 |
+
|
| 4 |
+
# Instalar dependencias necesarias
|
| 5 |
+
RUN apk add --no-cache gcc musl-dev sqlite-dev
|
| 6 |
+
|
| 7 |
+
# Establecer el directorio de trabajo
|
| 8 |
+
WORKDIR /app
|
| 9 |
+
|
| 10 |
+
# Copiar todo el código fuente primero
|
| 11 |
+
COPY . .
|
| 12 |
+
|
| 13 |
+
# Movernos al directorio de la aplicación golang
|
| 14 |
+
WORKDIR /app/apps/monitoring
|
| 15 |
+
|
| 16 |
+
# Descargar dependencias
|
| 17 |
+
RUN go mod download
|
| 18 |
+
|
| 19 |
+
# Compilar la aplicación
|
| 20 |
+
RUN CGO_ENABLED=1 GOOS=linux go build -o main main.go
|
| 21 |
+
|
| 22 |
+
# Etapa final
|
| 23 |
+
FROM alpine:3.19
|
| 24 |
+
|
| 25 |
+
# Instalar SQLite y otras dependencias necesarias
|
| 26 |
+
RUN apk add --no-cache sqlite-libs docker-cli
|
| 27 |
+
|
| 28 |
+
WORKDIR /app
|
| 29 |
+
|
| 30 |
+
# Copiar el binario compilado y el archivo monitor.go
|
| 31 |
+
COPY --from=builder /app/apps/monitoring/main ./main
|
| 32 |
+
COPY --from=builder /app/apps/monitoring/main.go ./monitor.go
|
| 33 |
+
|
| 34 |
+
# COPY --from=builder /app/apps/golang/.env ./.env
|
| 35 |
+
|
| 36 |
+
# Exponer el puerto
|
| 37 |
+
ENV PORT=3001
|
| 38 |
+
EXPOSE 3001
|
| 39 |
+
|
| 40 |
+
# Ejecutar la aplicación
|
| 41 |
+
CMD ["./main"]
|
data/Dockerfile.schedule
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM node:20.9-slim AS base
|
| 2 |
+
ENV PNPM_HOME="/pnpm"
|
| 3 |
+
ENV PATH="$PNPM_HOME:$PATH"
|
| 4 |
+
RUN corepack enable
|
| 5 |
+
|
| 6 |
+
FROM base AS build
|
| 7 |
+
COPY . /usr/src/app
|
| 8 |
+
WORKDIR /usr/src/app
|
| 9 |
+
|
| 10 |
+
RUN apt-get update && apt-get install -y python3 make g++ git python3-pip pkg-config libsecret-1-dev && rm -rf /var/lib/apt/lists/*
|
| 11 |
+
|
| 12 |
+
# Install dependencies
|
| 13 |
+
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm --filter=@dokploy/server --filter=./apps/schedules install --frozen-lockfile
|
| 14 |
+
|
| 15 |
+
# Deploy only the dokploy app
|
| 16 |
+
|
| 17 |
+
ENV NODE_ENV=production
|
| 18 |
+
RUN pnpm --filter=@dokploy/server build
|
| 19 |
+
RUN pnpm --filter=./apps/schedules run build
|
| 20 |
+
|
| 21 |
+
RUN pnpm --filter=./apps/schedules --prod deploy /prod/schedules
|
| 22 |
+
|
| 23 |
+
RUN cp -R /usr/src/app/apps/schedules/dist /prod/schedules/dist
|
| 24 |
+
|
| 25 |
+
FROM base AS dokploy
|
| 26 |
+
WORKDIR /app
|
| 27 |
+
|
| 28 |
+
# Set production
|
| 29 |
+
ENV NODE_ENV=production
|
| 30 |
+
|
| 31 |
+
# Copy only the necessary files
|
| 32 |
+
COPY --from=build /prod/schedules/dist ./dist
|
| 33 |
+
COPY --from=build /prod/schedules/package.json ./package.json
|
| 34 |
+
COPY --from=build /prod/schedules/node_modules ./node_modules
|
| 35 |
+
|
| 36 |
+
CMD HOSTNAME=0.0.0.0 && pnpm start
|
data/Dockerfile.server
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM node:20.9-slim AS base
|
| 2 |
+
ENV PNPM_HOME="/pnpm"
|
| 3 |
+
ENV PATH="$PNPM_HOME:$PATH"
|
| 4 |
+
RUN corepack enable
|
| 5 |
+
|
| 6 |
+
FROM base AS build
|
| 7 |
+
COPY . /usr/src/app
|
| 8 |
+
WORKDIR /usr/src/app
|
| 9 |
+
|
| 10 |
+
RUN apt-get update && apt-get install -y python3 make g++ git python3-pip pkg-config libsecret-1-dev && rm -rf /var/lib/apt/lists/*
|
| 11 |
+
|
| 12 |
+
# Install dependencies
|
| 13 |
+
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm --filter=@dokploy/server --filter=./apps/api install --frozen-lockfile
|
| 14 |
+
|
| 15 |
+
# Deploy only the dokploy app
|
| 16 |
+
|
| 17 |
+
ENV NODE_ENV=production
|
| 18 |
+
RUN pnpm --filter=@dokploy/server build
|
| 19 |
+
RUN pnpm --filter=./apps/api run build
|
| 20 |
+
|
| 21 |
+
RUN pnpm --filter=./apps/api --prod deploy /prod/api
|
| 22 |
+
|
| 23 |
+
RUN cp -R /usr/src/app/apps/api/dist /prod/api/dist
|
| 24 |
+
|
| 25 |
+
FROM base AS dokploy
|
| 26 |
+
WORKDIR /app
|
| 27 |
+
|
| 28 |
+
# Set production
|
| 29 |
+
ENV NODE_ENV=production
|
| 30 |
+
|
| 31 |
+
# Copy only the necessary files
|
| 32 |
+
COPY --from=build /prod/api/dist ./dist
|
| 33 |
+
COPY --from=build /prod/api/package.json ./package.json
|
| 34 |
+
COPY --from=build /prod/api/node_modules ./node_modules
|
| 35 |
+
|
| 36 |
+
CMD HOSTNAME=0.0.0.0 && pnpm start
|
data/GUIDES.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Docker
|
| 2 |
+
|
| 3 |
+
Here's how to install docker on different operating systems:
|
| 4 |
+
|
| 5 |
+
## macOS
|
| 6 |
+
|
| 7 |
+
1. Visit [Docker Desktop for Mac](https://www.docker.com/products/docker-desktop)
|
| 8 |
+
2. Download the Docker Desktop installer
|
| 9 |
+
3. Double-click the downloaded `.dmg` file
|
| 10 |
+
4. Drag Docker to your Applications folder
|
| 11 |
+
5. Open Docker Desktop from Applications
|
| 12 |
+
6. Follow the onboarding tutorial if desired
|
| 13 |
+
|
| 14 |
+
## Linux
|
| 15 |
+
|
| 16 |
+
### Ubuntu
|
| 17 |
+
|
| 18 |
+
```bash
|
| 19 |
+
# Update package index
|
| 20 |
+
sudo apt-get update
|
| 21 |
+
|
| 22 |
+
# Install prerequisites
|
| 23 |
+
sudo apt-get install \
|
| 24 |
+
apt-transport-https \
|
| 25 |
+
ca-certificates \
|
| 26 |
+
curl \
|
| 27 |
+
gnupg \
|
| 28 |
+
lsb-release
|
| 29 |
+
|
| 30 |
+
# Add Docker's official GPG key
|
| 31 |
+
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
|
| 32 |
+
|
| 33 |
+
# Set up stable repository
|
| 34 |
+
echo \
|
| 35 |
+
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
|
| 36 |
+
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
|
| 37 |
+
|
| 38 |
+
# Install Docker Engine
|
| 39 |
+
sudo apt-get update
|
| 40 |
+
sudo apt-get install docker-ce docker-ce-cli containerd.io
|
| 41 |
+
```
|
| 42 |
+
|
| 43 |
+
## Windows
|
| 44 |
+
|
| 45 |
+
1. Enable WSL2 if not already enabled
|
| 46 |
+
2. Visit [Docker Desktop for Windows](https://www.docker.com/products/docker-desktop)
|
| 47 |
+
3. Download the installer
|
| 48 |
+
4. Run the installer and follow the prompts
|
| 49 |
+
5. Start Docker Desktop from the Start menu
|
data/LICENSE.MD
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# License
|
| 2 |
+
|
| 3 |
+
## Core License (Apache License 2.0)
|
| 4 |
+
|
| 5 |
+
Copyright 2024 Mauricio Siu.
|
| 6 |
+
|
| 7 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 8 |
+
you may not use this file except in compliance with the License.
|
| 9 |
+
You may obtain a copy of the License at
|
| 10 |
+
|
| 11 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
|
| 13 |
+
Unless required by applicable law or agreed to in writing, software
|
| 14 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 |
+
See the License for the specific language governing permissions and limitations under the License.
|
| 17 |
+
|
| 18 |
+
## Additional Terms for Specific Features
|
| 19 |
+
|
| 20 |
+
The following additional terms apply to the multi-node support, Docker Compose file, Preview Deployments and Multi Server features of Dokploy. In the event of a conflict, these provisions shall take precedence over those in the Apache License:
|
| 21 |
+
|
| 22 |
+
- **Self-Hosted Version Free**: All features of Dokploy, including multi-node support, Docker Compose file support, Schedules, Preview Deployments and Multi Server, will always be free to use in the self-hosted version.
|
| 23 |
+
- **Restriction on Resale**: The multi-node support, Docker Compose file support, Schedules, Preview Deployments and Multi Server features cannot be sold or offered as a service by any party other than the copyright holder without prior written consent.
|
| 24 |
+
- **Modification Distribution**: Any modifications to the multi-node support, Docker Compose file support, Schedules, Preview Deployments and Multi Server features must be distributed freely and cannot be sold or offered as a service.
|
| 25 |
+
|
| 26 |
+
For further inquiries or permissions, please contact us directly.
|
data/SECURITY.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Dokploy Security Policy
|
| 2 |
+
|
| 3 |
+
At Dokploy, security is a top priority. We appreciate the help of security researchers and the community in identifying and reporting vulnerabilities.
|
| 4 |
+
|
| 5 |
+
## How to Report a Vulnerability
|
| 6 |
+
|
| 7 |
+
If you have discovered a security vulnerability in Dokploy, we ask that you report it responsibly by following these guidelines:
|
| 8 |
+
|
| 9 |
+
1. **Contact us:** Send an email to [contact@dokploy.com](mailto:contact@dokploy.com).
|
| 10 |
+
2. **Provide clear details:** Include as much information as possible to help us understand and reproduce the vulnerability. This should include:
|
| 11 |
+
* A clear description of the vulnerability.
|
| 12 |
+
* Steps to reproduce the vulnerability.
|
| 13 |
+
* Any sample code, screenshots, or videos that might be helpful.
|
| 14 |
+
* The potential impact of the vulnerability.
|
| 15 |
+
3. **Do not make the vulnerability public:** Please refrain from publicly disclosing the vulnerability until we have had the opportunity to investigate and address it. This is crucial for protecting our users.
|
| 16 |
+
4. **Allow us time:** We will endeavor to acknowledge receipt of your report as soon as possible and keep you informed of our progress. The time to resolve the vulnerability may vary depending on its complexity and severity.
|
| 17 |
+
|
| 18 |
+
## What We Expect From You
|
| 19 |
+
|
| 20 |
+
* Do not access user data or systems beyond what is necessary to demonstrate the vulnerability.
|
| 21 |
+
* Do not perform denial-of-service (DoS) attacks, spamming, or social engineering.
|
| 22 |
+
* Do not modify or destroy data that does not belong to you.
|
| 23 |
+
|
| 24 |
+
## Our Commitment
|
| 25 |
+
|
| 26 |
+
We are committed to working with you quickly and responsibly to address any legitimate security vulnerability.
|
| 27 |
+
|
| 28 |
+
Thank you for helping us keep Dokploy secure for everyone.
|
data/TERMS_AND_CONDITIONS.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Terms & Conditions
|
| 2 |
+
|
| 3 |
+
**Dokploy core** is a free and open-source solution intended as an alternative to established cloud platforms like Vercel and Netlify.
|
| 4 |
+
|
| 5 |
+
The Dokploy team endeavors to mitigate potential defects and issues through stringent testing and adherence to principles of clean coding. Dokploy is provided "AS IS" without any warranties, express or implied. Refer to the [License](https://github.com/Dokploy/Dokploy/blob/main/LICENSE) for details on permissions and restrictions.
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
### Description of Service:
|
| 9 |
+
|
| 10 |
+
**Dokploy core** is an open-source tool designed to simplify the deployment of applications for both personal and business use. Users are permitted to install, modify, and operate Dokploy independently or within their organizations to improve their development and deployment operations. It is important to note that any commercial resale or redistribution of Dokploy as a service is strictly forbidden without explicit consent. This prohibition ensures the preservation of Dokploy's open-source character for the benefit of the entire community.
|
| 11 |
+
|
| 12 |
+
### Our Responsibility
|
| 13 |
+
|
| 14 |
+
The Dokploy development team commits to maintaining the functionality of the software and addressing major issues promptly. While we welcome suggestions for new features, the decision to include them rests solely with the core developers of Dokploy.
|
| 15 |
+
|
| 16 |
+
### Usage Data
|
| 17 |
+
|
| 18 |
+
**Dokploy** does not collect any user data. It is distributed as a free and open-source tool under the terms of "AS IS", without any implied warranties or conditions.
|
| 19 |
+
|
| 20 |
+
### Future Changes
|
| 21 |
+
|
| 22 |
+
The Terms of Service and Terms & Conditions are subject to change without prior notice.
|
data/apps/api/.env.example
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
LEMON_SQUEEZY_API_KEY=""
|
| 2 |
+
LEMON_SQUEEZY_STORE_ID=""
|
data/apps/api/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "@dokploy/api",
|
| 3 |
+
"version": "0.0.1",
|
| 4 |
+
"type": "module",
|
| 5 |
+
"scripts": {
|
| 6 |
+
"dev": "PORT=4000 tsx watch src/index.ts",
|
| 7 |
+
"build": "tsc --project tsconfig.json",
|
| 8 |
+
"start": "node dist/index.js",
|
| 9 |
+
"typecheck": "tsc --noEmit"
|
| 10 |
+
},
|
| 11 |
+
"dependencies": {
|
| 12 |
+
"pino": "9.4.0",
|
| 13 |
+
"pino-pretty": "11.2.2",
|
| 14 |
+
"@hono/zod-validator": "0.3.0",
|
| 15 |
+
"zod": "^3.23.4",
|
| 16 |
+
"react": "18.2.0",
|
| 17 |
+
"react-dom": "18.2.0",
|
| 18 |
+
"@dokploy/server": "workspace:*",
|
| 19 |
+
"@hono/node-server": "^1.12.1",
|
| 20 |
+
"hono": "^4.5.8",
|
| 21 |
+
"dotenv": "^16.3.1",
|
| 22 |
+
"redis": "4.7.0",
|
| 23 |
+
"@nerimity/mimiqueue": "1.2.3"
|
| 24 |
+
},
|
| 25 |
+
"devDependencies": {
|
| 26 |
+
"typescript": "^5.4.2",
|
| 27 |
+
"@types/react": "^18.2.37",
|
| 28 |
+
"@types/react-dom": "^18.2.15",
|
| 29 |
+
"@types/node": "^20.11.17",
|
| 30 |
+
"tsx": "^4.7.1"
|
| 31 |
+
},
|
| 32 |
+
"packageManager": "pnpm@9.5.0"
|
| 33 |
+
}
|
data/apps/api/src/index.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { serve } from "@hono/node-server";
|
| 2 |
+
import { Hono } from "hono";
|
| 3 |
+
import "dotenv/config";
|
| 4 |
+
import { zValidator } from "@hono/zod-validator";
|
| 5 |
+
import { Queue } from "@nerimity/mimiqueue";
|
| 6 |
+
import { createClient } from "redis";
|
| 7 |
+
import { logger } from "./logger.js";
|
| 8 |
+
import { type DeployJob, deployJobSchema } from "./schema.js";
|
| 9 |
+
import { deploy } from "./utils.js";
|
| 10 |
+
|
| 11 |
+
const app = new Hono();
|
| 12 |
+
const redisClient = createClient({
|
| 13 |
+
url: process.env.REDIS_URL,
|
| 14 |
+
});
|
| 15 |
+
|
| 16 |
+
app.use(async (c, next) => {
|
| 17 |
+
if (c.req.path === "/health") {
|
| 18 |
+
return next();
|
| 19 |
+
}
|
| 20 |
+
const authHeader = c.req.header("X-API-Key");
|
| 21 |
+
|
| 22 |
+
if (process.env.API_KEY !== authHeader) {
|
| 23 |
+
return c.json({ message: "Invalid API Key" }, 403);
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
return next();
|
| 27 |
+
});
|
| 28 |
+
|
| 29 |
+
app.post("/deploy", zValidator("json", deployJobSchema), (c) => {
|
| 30 |
+
const data = c.req.valid("json");
|
| 31 |
+
queue.add(data, { groupName: data.serverId });
|
| 32 |
+
return c.json(
|
| 33 |
+
{
|
| 34 |
+
message: "Deployment Added",
|
| 35 |
+
},
|
| 36 |
+
200,
|
| 37 |
+
);
|
| 38 |
+
});
|
| 39 |
+
|
| 40 |
+
app.get("/health", async (c) => {
|
| 41 |
+
return c.json({ status: "ok" });
|
| 42 |
+
});
|
| 43 |
+
|
| 44 |
+
const queue = new Queue({
|
| 45 |
+
name: "deployments",
|
| 46 |
+
process: async (job: DeployJob) => {
|
| 47 |
+
logger.info("Deploying job", job);
|
| 48 |
+
return await deploy(job);
|
| 49 |
+
},
|
| 50 |
+
redisClient,
|
| 51 |
+
});
|
| 52 |
+
|
| 53 |
+
(async () => {
|
| 54 |
+
await redisClient.connect();
|
| 55 |
+
await redisClient.flushAll();
|
| 56 |
+
logger.info("Redis Cleaned");
|
| 57 |
+
})();
|
| 58 |
+
|
| 59 |
+
const port = Number.parseInt(process.env.PORT || "3000");
|
| 60 |
+
logger.info("Starting Deployments Server ✅", port);
|
| 61 |
+
serve({ fetch: app.fetch, port });
|
data/apps/api/src/logger.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pino from "pino";
|
| 2 |
+
|
| 3 |
+
export const logger = pino({
|
| 4 |
+
transport: {
|
| 5 |
+
target: "pino-pretty",
|
| 6 |
+
options: {
|
| 7 |
+
colorize: true,
|
| 8 |
+
},
|
| 9 |
+
},
|
| 10 |
+
});
|
data/apps/api/src/schema.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { z } from "zod";
|
| 2 |
+
|
| 3 |
+
export const deployJobSchema = z.discriminatedUnion("applicationType", [
|
| 4 |
+
z.object({
|
| 5 |
+
applicationId: z.string(),
|
| 6 |
+
titleLog: z.string(),
|
| 7 |
+
descriptionLog: z.string(),
|
| 8 |
+
server: z.boolean().optional(),
|
| 9 |
+
type: z.enum(["deploy", "redeploy"]),
|
| 10 |
+
applicationType: z.literal("application"),
|
| 11 |
+
serverId: z.string().min(1),
|
| 12 |
+
}),
|
| 13 |
+
z.object({
|
| 14 |
+
composeId: z.string(),
|
| 15 |
+
titleLog: z.string(),
|
| 16 |
+
descriptionLog: z.string(),
|
| 17 |
+
server: z.boolean().optional(),
|
| 18 |
+
type: z.enum(["deploy", "redeploy"]),
|
| 19 |
+
applicationType: z.literal("compose"),
|
| 20 |
+
serverId: z.string().min(1),
|
| 21 |
+
}),
|
| 22 |
+
z.object({
|
| 23 |
+
applicationId: z.string(),
|
| 24 |
+
previewDeploymentId: z.string(),
|
| 25 |
+
titleLog: z.string(),
|
| 26 |
+
descriptionLog: z.string(),
|
| 27 |
+
server: z.boolean().optional(),
|
| 28 |
+
type: z.enum(["deploy"]),
|
| 29 |
+
applicationType: z.literal("application-preview"),
|
| 30 |
+
serverId: z.string().min(1),
|
| 31 |
+
}),
|
| 32 |
+
]);
|
| 33 |
+
|
| 34 |
+
export type DeployJob = z.infer<typeof deployJobSchema>;
|
data/apps/api/src/utils.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {
|
| 2 |
+
deployRemoteApplication,
|
| 3 |
+
deployRemoteCompose,
|
| 4 |
+
deployRemotePreviewApplication,
|
| 5 |
+
rebuildRemoteApplication,
|
| 6 |
+
rebuildRemoteCompose,
|
| 7 |
+
updateApplicationStatus,
|
| 8 |
+
updateCompose,
|
| 9 |
+
updatePreviewDeployment,
|
| 10 |
+
} from "@dokploy/server";
|
| 11 |
+
import type { DeployJob } from "./schema";
|
| 12 |
+
|
| 13 |
+
export const deploy = async (job: DeployJob) => {
|
| 14 |
+
try {
|
| 15 |
+
if (job.applicationType === "application") {
|
| 16 |
+
await updateApplicationStatus(job.applicationId, "running");
|
| 17 |
+
if (job.server) {
|
| 18 |
+
if (job.type === "redeploy") {
|
| 19 |
+
await rebuildRemoteApplication({
|
| 20 |
+
applicationId: job.applicationId,
|
| 21 |
+
titleLog: job.titleLog,
|
| 22 |
+
descriptionLog: job.descriptionLog,
|
| 23 |
+
});
|
| 24 |
+
} else if (job.type === "deploy") {
|
| 25 |
+
await deployRemoteApplication({
|
| 26 |
+
applicationId: job.applicationId,
|
| 27 |
+
titleLog: job.titleLog,
|
| 28 |
+
descriptionLog: job.descriptionLog,
|
| 29 |
+
});
|
| 30 |
+
}
|
| 31 |
+
}
|
| 32 |
+
} else if (job.applicationType === "compose") {
|
| 33 |
+
await updateCompose(job.composeId, {
|
| 34 |
+
composeStatus: "running",
|
| 35 |
+
});
|
| 36 |
+
|
| 37 |
+
if (job.server) {
|
| 38 |
+
if (job.type === "redeploy") {
|
| 39 |
+
await rebuildRemoteCompose({
|
| 40 |
+
composeId: job.composeId,
|
| 41 |
+
titleLog: job.titleLog,
|
| 42 |
+
descriptionLog: job.descriptionLog,
|
| 43 |
+
});
|
| 44 |
+
} else if (job.type === "deploy") {
|
| 45 |
+
await deployRemoteCompose({
|
| 46 |
+
composeId: job.composeId,
|
| 47 |
+
titleLog: job.titleLog,
|
| 48 |
+
descriptionLog: job.descriptionLog,
|
| 49 |
+
});
|
| 50 |
+
}
|
| 51 |
+
}
|
| 52 |
+
} else if (job.applicationType === "application-preview") {
|
| 53 |
+
await updatePreviewDeployment(job.previewDeploymentId, {
|
| 54 |
+
previewStatus: "running",
|
| 55 |
+
});
|
| 56 |
+
if (job.server) {
|
| 57 |
+
if (job.type === "deploy") {
|
| 58 |
+
await deployRemotePreviewApplication({
|
| 59 |
+
applicationId: job.applicationId,
|
| 60 |
+
titleLog: job.titleLog,
|
| 61 |
+
descriptionLog: job.descriptionLog,
|
| 62 |
+
previewDeploymentId: job.previewDeploymentId,
|
| 63 |
+
});
|
| 64 |
+
}
|
| 65 |
+
}
|
| 66 |
+
}
|
| 67 |
+
} catch (_) {
|
| 68 |
+
if (job.applicationType === "application") {
|
| 69 |
+
await updateApplicationStatus(job.applicationId, "error");
|
| 70 |
+
} else if (job.applicationType === "compose") {
|
| 71 |
+
await updateCompose(job.composeId, {
|
| 72 |
+
composeStatus: "error",
|
| 73 |
+
});
|
| 74 |
+
} else if (job.applicationType === "application-preview") {
|
| 75 |
+
await updatePreviewDeployment(job.previewDeploymentId, {
|
| 76 |
+
previewStatus: "error",
|
| 77 |
+
});
|
| 78 |
+
}
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
return true;
|
| 82 |
+
};
|
data/apps/api/tsconfig.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"compilerOptions": {
|
| 3 |
+
"target": "ESNext",
|
| 4 |
+
"module": "ESNext",
|
| 5 |
+
"moduleResolution": "Node",
|
| 6 |
+
"strict": true,
|
| 7 |
+
"skipLibCheck": true,
|
| 8 |
+
"outDir": "dist",
|
| 9 |
+
"jsx": "react-jsx",
|
| 10 |
+
"jsxImportSource": "hono/jsx",
|
| 11 |
+
"baseUrl": ".",
|
| 12 |
+
"paths": {
|
| 13 |
+
"@/*": ["./*"],
|
| 14 |
+
"@dokploy/server/*": ["../../packages/server/src/*"]
|
| 15 |
+
}
|
| 16 |
+
},
|
| 17 |
+
"exclude": ["node_modules", "dist"]
|
| 18 |
+
}
|
data/apps/dokploy/.dockerignore
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
node_modules
|
| 2 |
+
.git
|
| 3 |
+
.gitignore
|
| 4 |
+
*.md
|
| 5 |
+
dist
|
data/apps/dokploy/.env.example
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
DATABASE_URL="postgres://dokploy:amukds4wi9001583845717ad2@localhost:5432/dokploy"
|
| 2 |
+
PORT=3000
|
| 3 |
+
NODE_ENV=development
|
data/apps/dokploy/.env.production.example
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
DATABASE_URL="postgres://dokploy:amukds4wi9001583845717ad2@dokploy-postgres:5432/dokploy"
|
| 2 |
+
PORT=3000
|
| 3 |
+
NODE_ENV=production
|
data/apps/dokploy/.nvmrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
20.16.0
|
data/apps/dokploy/LICENSE.MD
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# License
|
| 2 |
+
|
| 3 |
+
## Core License (Apache License 2.0)
|
| 4 |
+
|
| 5 |
+
Copyright 2024 Mauricio Siu.
|
| 6 |
+
|
| 7 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 8 |
+
you may not use this file except in compliance with the License.
|
| 9 |
+
You may obtain a copy of the License at
|
| 10 |
+
|
| 11 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
|
| 13 |
+
Unless required by applicable law or agreed to in writing, software
|
| 14 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 |
+
See the License for the specific language governing permissions and limitations under the License.
|
| 17 |
+
|
| 18 |
+
## Additional Terms for Specific Features
|
| 19 |
+
|
| 20 |
+
The following additional terms apply to the multi-node support, Docker Compose file, Preview Deployments and Multi Server features of Dokploy. In the event of a conflict, these provisions shall take precedence over those in the Apache License:
|
| 21 |
+
|
| 22 |
+
- **Self-Hosted Version Free**: All features of Dokploy, including multi-node support, Docker Compose file support, Preview Deployments and Multi Server, will always be free to use in the self-hosted version.
|
| 23 |
+
- **Restriction on Resale**: The multi-node support, Docker Compose file support, Preview Deployments and Multi Server features cannot be sold or offered as a service by any party other than the copyright holder without prior written consent.
|
| 24 |
+
- **Modification Distribution**: Any modifications to the multi-node support, Docker Compose file support, Preview Deployments and Multi Server features must be distributed freely and cannot be sold or offered as a service.
|
| 25 |
+
|
| 26 |
+
For further inquiries or permissions, please contact us directly.
|
data/apps/dokploy/__test__/compose/compose.test.ts
ADDED
|
@@ -0,0 +1,476 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { addSuffixToAllProperties } from "@dokploy/server";
|
| 2 |
+
import type { ComposeSpecification } from "@dokploy/server";
|
| 3 |
+
import { load } from "js-yaml";
|
| 4 |
+
import { expect, test } from "vitest";
|
| 5 |
+
|
| 6 |
+
const composeFile1 = `
|
| 7 |
+
version: "3.8"
|
| 8 |
+
|
| 9 |
+
services:
|
| 10 |
+
web:
|
| 11 |
+
image: nginx:latest
|
| 12 |
+
container_name: web_container
|
| 13 |
+
depends_on:
|
| 14 |
+
- app
|
| 15 |
+
networks:
|
| 16 |
+
- frontend
|
| 17 |
+
volumes_from:
|
| 18 |
+
- data
|
| 19 |
+
links:
|
| 20 |
+
- db
|
| 21 |
+
extends:
|
| 22 |
+
service: base_service
|
| 23 |
+
configs:
|
| 24 |
+
- source: web_config
|
| 25 |
+
|
| 26 |
+
app:
|
| 27 |
+
image: node:14
|
| 28 |
+
networks:
|
| 29 |
+
- backend
|
| 30 |
+
- frontend
|
| 31 |
+
|
| 32 |
+
db:
|
| 33 |
+
image: postgres:13
|
| 34 |
+
networks:
|
| 35 |
+
- backend
|
| 36 |
+
|
| 37 |
+
data:
|
| 38 |
+
image: busybox
|
| 39 |
+
volumes:
|
| 40 |
+
- /data
|
| 41 |
+
|
| 42 |
+
base_service:
|
| 43 |
+
image: base:latest
|
| 44 |
+
|
| 45 |
+
networks:
|
| 46 |
+
frontend:
|
| 47 |
+
driver: bridge
|
| 48 |
+
backend:
|
| 49 |
+
driver: bridge
|
| 50 |
+
|
| 51 |
+
volumes:
|
| 52 |
+
web_data:
|
| 53 |
+
driver: local
|
| 54 |
+
|
| 55 |
+
configs:
|
| 56 |
+
web_config:
|
| 57 |
+
file: ./web_config.yml
|
| 58 |
+
|
| 59 |
+
secrets:
|
| 60 |
+
db_password:
|
| 61 |
+
file: ./db_password.txt
|
| 62 |
+
`;
|
| 63 |
+
|
| 64 |
+
const expectedComposeFile1 = load(`
|
| 65 |
+
version: "3.8"
|
| 66 |
+
|
| 67 |
+
services:
|
| 68 |
+
web-testhash:
|
| 69 |
+
image: nginx:latest
|
| 70 |
+
container_name: web_container-testhash
|
| 71 |
+
depends_on:
|
| 72 |
+
- app-testhash
|
| 73 |
+
networks:
|
| 74 |
+
- frontend-testhash
|
| 75 |
+
volumes_from:
|
| 76 |
+
- data-testhash
|
| 77 |
+
links:
|
| 78 |
+
- db-testhash
|
| 79 |
+
extends:
|
| 80 |
+
service: base_service-testhash
|
| 81 |
+
configs:
|
| 82 |
+
- source: web_config-testhash
|
| 83 |
+
|
| 84 |
+
app-testhash:
|
| 85 |
+
image: node:14
|
| 86 |
+
networks:
|
| 87 |
+
- backend-testhash
|
| 88 |
+
- frontend-testhash
|
| 89 |
+
|
| 90 |
+
db-testhash:
|
| 91 |
+
image: postgres:13
|
| 92 |
+
networks:
|
| 93 |
+
- backend-testhash
|
| 94 |
+
|
| 95 |
+
data-testhash:
|
| 96 |
+
image: busybox
|
| 97 |
+
volumes:
|
| 98 |
+
- /data
|
| 99 |
+
|
| 100 |
+
base_service-testhash:
|
| 101 |
+
image: base:latest
|
| 102 |
+
|
| 103 |
+
networks:
|
| 104 |
+
frontend-testhash:
|
| 105 |
+
driver: bridge
|
| 106 |
+
backend-testhash:
|
| 107 |
+
driver: bridge
|
| 108 |
+
|
| 109 |
+
volumes:
|
| 110 |
+
web_data-testhash:
|
| 111 |
+
driver: local
|
| 112 |
+
|
| 113 |
+
configs:
|
| 114 |
+
web_config-testhash:
|
| 115 |
+
file: ./web_config.yml
|
| 116 |
+
|
| 117 |
+
secrets:
|
| 118 |
+
db_password-testhash:
|
| 119 |
+
file: ./db_password.txt
|
| 120 |
+
`) as ComposeSpecification;
|
| 121 |
+
|
| 122 |
+
test("Add suffix to all properties in compose file 1", () => {
|
| 123 |
+
const composeData = load(composeFile1) as ComposeSpecification;
|
| 124 |
+
const suffix = "testhash";
|
| 125 |
+
|
| 126 |
+
const updatedComposeData = addSuffixToAllProperties(composeData, suffix);
|
| 127 |
+
|
| 128 |
+
expect(updatedComposeData).toEqual(expectedComposeFile1);
|
| 129 |
+
});
|
| 130 |
+
|
| 131 |
+
const composeFile2 = `
|
| 132 |
+
version: "3.8"
|
| 133 |
+
|
| 134 |
+
services:
|
| 135 |
+
frontend:
|
| 136 |
+
image: nginx:latest
|
| 137 |
+
depends_on:
|
| 138 |
+
- backend
|
| 139 |
+
networks:
|
| 140 |
+
- public
|
| 141 |
+
volumes_from:
|
| 142 |
+
- logs
|
| 143 |
+
links:
|
| 144 |
+
- cache
|
| 145 |
+
extends:
|
| 146 |
+
service: shared_service
|
| 147 |
+
secrets:
|
| 148 |
+
- db_password
|
| 149 |
+
|
| 150 |
+
backend:
|
| 151 |
+
image: node:14
|
| 152 |
+
networks:
|
| 153 |
+
- private
|
| 154 |
+
- public
|
| 155 |
+
|
| 156 |
+
cache:
|
| 157 |
+
image: redis:latest
|
| 158 |
+
networks:
|
| 159 |
+
- private
|
| 160 |
+
|
| 161 |
+
logs:
|
| 162 |
+
image: busybox
|
| 163 |
+
volumes:
|
| 164 |
+
- /logs
|
| 165 |
+
|
| 166 |
+
shared_service:
|
| 167 |
+
image: shared:latest
|
| 168 |
+
|
| 169 |
+
networks:
|
| 170 |
+
public:
|
| 171 |
+
driver: bridge
|
| 172 |
+
private:
|
| 173 |
+
driver: bridge
|
| 174 |
+
|
| 175 |
+
volumes:
|
| 176 |
+
logs:
|
| 177 |
+
driver: local
|
| 178 |
+
|
| 179 |
+
configs:
|
| 180 |
+
app_config:
|
| 181 |
+
file: ./app_config.yml
|
| 182 |
+
|
| 183 |
+
secrets:
|
| 184 |
+
db_password:
|
| 185 |
+
file: ./db_password.txt
|
| 186 |
+
`;
|
| 187 |
+
|
| 188 |
+
const expectedComposeFile2 = load(`
|
| 189 |
+
version: "3.8"
|
| 190 |
+
|
| 191 |
+
services:
|
| 192 |
+
frontend-testhash:
|
| 193 |
+
image: nginx:latest
|
| 194 |
+
depends_on:
|
| 195 |
+
- backend-testhash
|
| 196 |
+
networks:
|
| 197 |
+
- public-testhash
|
| 198 |
+
volumes_from:
|
| 199 |
+
- logs-testhash
|
| 200 |
+
links:
|
| 201 |
+
- cache-testhash
|
| 202 |
+
extends:
|
| 203 |
+
service: shared_service-testhash
|
| 204 |
+
secrets:
|
| 205 |
+
- db_password-testhash
|
| 206 |
+
|
| 207 |
+
backend-testhash:
|
| 208 |
+
image: node:14
|
| 209 |
+
networks:
|
| 210 |
+
- private-testhash
|
| 211 |
+
- public-testhash
|
| 212 |
+
|
| 213 |
+
cache-testhash:
|
| 214 |
+
image: redis:latest
|
| 215 |
+
networks:
|
| 216 |
+
- private-testhash
|
| 217 |
+
|
| 218 |
+
logs-testhash:
|
| 219 |
+
image: busybox
|
| 220 |
+
volumes:
|
| 221 |
+
- /logs
|
| 222 |
+
|
| 223 |
+
shared_service-testhash:
|
| 224 |
+
image: shared:latest
|
| 225 |
+
|
| 226 |
+
networks:
|
| 227 |
+
public-testhash:
|
| 228 |
+
driver: bridge
|
| 229 |
+
private-testhash:
|
| 230 |
+
driver: bridge
|
| 231 |
+
|
| 232 |
+
volumes:
|
| 233 |
+
logs-testhash:
|
| 234 |
+
driver: local
|
| 235 |
+
|
| 236 |
+
configs:
|
| 237 |
+
app_config-testhash:
|
| 238 |
+
file: ./app_config.yml
|
| 239 |
+
|
| 240 |
+
secrets:
|
| 241 |
+
db_password-testhash:
|
| 242 |
+
file: ./db_password.txt
|
| 243 |
+
`) as ComposeSpecification;
|
| 244 |
+
|
| 245 |
+
test("Add suffix to all properties in compose file 2", () => {
|
| 246 |
+
const composeData = load(composeFile2) as ComposeSpecification;
|
| 247 |
+
const suffix = "testhash";
|
| 248 |
+
|
| 249 |
+
const updatedComposeData = addSuffixToAllProperties(composeData, suffix);
|
| 250 |
+
|
| 251 |
+
expect(updatedComposeData).toEqual(expectedComposeFile2);
|
| 252 |
+
});
|
| 253 |
+
|
| 254 |
+
const composeFile3 = `
|
| 255 |
+
version: "3.8"
|
| 256 |
+
|
| 257 |
+
services:
|
| 258 |
+
service_a:
|
| 259 |
+
image: service_a:latest
|
| 260 |
+
depends_on:
|
| 261 |
+
- service_b
|
| 262 |
+
networks:
|
| 263 |
+
- net_a
|
| 264 |
+
volumes_from:
|
| 265 |
+
- data_volume
|
| 266 |
+
links:
|
| 267 |
+
- service_c
|
| 268 |
+
extends:
|
| 269 |
+
service: common_service
|
| 270 |
+
configs:
|
| 271 |
+
- source: service_a_config
|
| 272 |
+
|
| 273 |
+
service_b:
|
| 274 |
+
image: service_b:latest
|
| 275 |
+
networks:
|
| 276 |
+
- net_b
|
| 277 |
+
- net_a
|
| 278 |
+
|
| 279 |
+
service_c:
|
| 280 |
+
image: service_c:latest
|
| 281 |
+
networks:
|
| 282 |
+
- net_b
|
| 283 |
+
|
| 284 |
+
data_volume:
|
| 285 |
+
image: busybox
|
| 286 |
+
volumes:
|
| 287 |
+
- /data
|
| 288 |
+
|
| 289 |
+
common_service:
|
| 290 |
+
image: common:latest
|
| 291 |
+
|
| 292 |
+
networks:
|
| 293 |
+
net_a:
|
| 294 |
+
driver: bridge
|
| 295 |
+
net_b:
|
| 296 |
+
driver: bridge
|
| 297 |
+
|
| 298 |
+
volumes:
|
| 299 |
+
data_volume:
|
| 300 |
+
driver: local
|
| 301 |
+
|
| 302 |
+
configs:
|
| 303 |
+
service_a_config:
|
| 304 |
+
file: ./service_a_config.yml
|
| 305 |
+
|
| 306 |
+
secrets:
|
| 307 |
+
service_secret:
|
| 308 |
+
file: ./service_secret.txt
|
| 309 |
+
`;
|
| 310 |
+
|
| 311 |
+
const expectedComposeFile3 = load(`
|
| 312 |
+
version: "3.8"
|
| 313 |
+
|
| 314 |
+
services:
|
| 315 |
+
service_a-testhash:
|
| 316 |
+
image: service_a:latest
|
| 317 |
+
depends_on:
|
| 318 |
+
- service_b-testhash
|
| 319 |
+
networks:
|
| 320 |
+
- net_a-testhash
|
| 321 |
+
volumes_from:
|
| 322 |
+
- data_volume-testhash
|
| 323 |
+
links:
|
| 324 |
+
- service_c-testhash
|
| 325 |
+
extends:
|
| 326 |
+
service: common_service-testhash
|
| 327 |
+
configs:
|
| 328 |
+
- source: service_a_config-testhash
|
| 329 |
+
|
| 330 |
+
service_b-testhash:
|
| 331 |
+
image: service_b:latest
|
| 332 |
+
networks:
|
| 333 |
+
- net_b-testhash
|
| 334 |
+
- net_a-testhash
|
| 335 |
+
|
| 336 |
+
service_c-testhash:
|
| 337 |
+
image: service_c:latest
|
| 338 |
+
networks:
|
| 339 |
+
- net_b-testhash
|
| 340 |
+
|
| 341 |
+
data_volume-testhash:
|
| 342 |
+
image: busybox
|
| 343 |
+
volumes:
|
| 344 |
+
- /data
|
| 345 |
+
|
| 346 |
+
common_service-testhash:
|
| 347 |
+
image: common:latest
|
| 348 |
+
|
| 349 |
+
networks:
|
| 350 |
+
net_a-testhash:
|
| 351 |
+
driver: bridge
|
| 352 |
+
net_b-testhash:
|
| 353 |
+
driver: bridge
|
| 354 |
+
|
| 355 |
+
volumes:
|
| 356 |
+
data_volume-testhash:
|
| 357 |
+
driver: local
|
| 358 |
+
|
| 359 |
+
configs:
|
| 360 |
+
service_a_config-testhash:
|
| 361 |
+
file: ./service_a_config.yml
|
| 362 |
+
|
| 363 |
+
secrets:
|
| 364 |
+
service_secret-testhash:
|
| 365 |
+
file: ./service_secret.txt
|
| 366 |
+
`) as ComposeSpecification;
|
| 367 |
+
|
| 368 |
+
test("Add suffix to all properties in compose file 3", () => {
|
| 369 |
+
const composeData = load(composeFile3) as ComposeSpecification;
|
| 370 |
+
const suffix = "testhash";
|
| 371 |
+
|
| 372 |
+
const updatedComposeData = addSuffixToAllProperties(composeData, suffix);
|
| 373 |
+
|
| 374 |
+
expect(updatedComposeData).toEqual(expectedComposeFile3);
|
| 375 |
+
});
|
| 376 |
+
|
| 377 |
+
const composeFile = `
|
| 378 |
+
version: "3.8"
|
| 379 |
+
|
| 380 |
+
services:
|
| 381 |
+
plausible_db:
|
| 382 |
+
image: postgres:16-alpine
|
| 383 |
+
restart: always
|
| 384 |
+
volumes:
|
| 385 |
+
- db-data:/var/lib/postgresql/data
|
| 386 |
+
environment:
|
| 387 |
+
- POSTGRES_PASSWORD=postgres
|
| 388 |
+
|
| 389 |
+
plausible_events_db:
|
| 390 |
+
image: clickhouse/clickhouse-server:24.3.3.102-alpine
|
| 391 |
+
restart: always
|
| 392 |
+
volumes:
|
| 393 |
+
- event-data:/var/lib/clickhouse
|
| 394 |
+
- event-logs:/var/log/clickhouse-server
|
| 395 |
+
- ./clickhouse/clickhouse-config.xml:/etc/clickhouse-server/config.d/logging.xml:ro
|
| 396 |
+
- ./clickhouse/clickhouse-user-config.xml:/etc/clickhouse-server/users.d/logging.xml:ro
|
| 397 |
+
ulimits:
|
| 398 |
+
nofile:
|
| 399 |
+
soft: 262144
|
| 400 |
+
hard: 262144
|
| 401 |
+
|
| 402 |
+
plausible:
|
| 403 |
+
image: ghcr.io/plausible/community-edition:v2.1.0
|
| 404 |
+
restart: always
|
| 405 |
+
command: sh -c "sleep 10 && /entrypoint.sh db createdb && /entrypoint.sh db migrate && /entrypoint.sh run"
|
| 406 |
+
depends_on:
|
| 407 |
+
- plausible_db
|
| 408 |
+
- plausible_events_db
|
| 409 |
+
ports:
|
| 410 |
+
- 127.0.0.1:8000:8000
|
| 411 |
+
env_file:
|
| 412 |
+
- plausible-conf.env
|
| 413 |
+
|
| 414 |
+
volumes:
|
| 415 |
+
db-data:
|
| 416 |
+
driver: local
|
| 417 |
+
event-data:
|
| 418 |
+
driver: local
|
| 419 |
+
event-logs:
|
| 420 |
+
driver: local
|
| 421 |
+
`;
|
| 422 |
+
|
| 423 |
+
const expectedComposeFile = load(`
|
| 424 |
+
version: "3.8"
|
| 425 |
+
|
| 426 |
+
services:
|
| 427 |
+
plausible_db-testhash:
|
| 428 |
+
image: postgres:16-alpine
|
| 429 |
+
restart: always
|
| 430 |
+
volumes:
|
| 431 |
+
- db-data-testhash:/var/lib/postgresql/data
|
| 432 |
+
environment:
|
| 433 |
+
- POSTGRES_PASSWORD=postgres
|
| 434 |
+
|
| 435 |
+
plausible_events_db-testhash:
|
| 436 |
+
image: clickhouse/clickhouse-server:24.3.3.102-alpine
|
| 437 |
+
restart: always
|
| 438 |
+
volumes:
|
| 439 |
+
- event-data-testhash:/var/lib/clickhouse
|
| 440 |
+
- event-logs-testhash:/var/log/clickhouse-server
|
| 441 |
+
- ./clickhouse/clickhouse-config.xml:/etc/clickhouse-server/config.d/logging.xml:ro
|
| 442 |
+
- ./clickhouse/clickhouse-user-config.xml:/etc/clickhouse-server/users.d/logging.xml:ro
|
| 443 |
+
ulimits:
|
| 444 |
+
nofile:
|
| 445 |
+
soft: 262144
|
| 446 |
+
hard: 262144
|
| 447 |
+
|
| 448 |
+
plausible-testhash:
|
| 449 |
+
image: ghcr.io/plausible/community-edition:v2.1.0
|
| 450 |
+
restart: always
|
| 451 |
+
command: sh -c "sleep 10 && /entrypoint.sh db createdb && /entrypoint.sh db migrate && /entrypoint.sh run"
|
| 452 |
+
depends_on:
|
| 453 |
+
- plausible_db-testhash
|
| 454 |
+
- plausible_events_db-testhash
|
| 455 |
+
ports:
|
| 456 |
+
- 127.0.0.1:8000:8000
|
| 457 |
+
env_file:
|
| 458 |
+
- plausible-conf.env
|
| 459 |
+
|
| 460 |
+
volumes:
|
| 461 |
+
db-data-testhash:
|
| 462 |
+
driver: local
|
| 463 |
+
event-data-testhash:
|
| 464 |
+
driver: local
|
| 465 |
+
event-logs-testhash:
|
| 466 |
+
driver: local
|
| 467 |
+
`) as ComposeSpecification;
|
| 468 |
+
|
| 469 |
+
test("Add suffix to all properties in Plausible compose file", () => {
|
| 470 |
+
const composeData = load(composeFile) as ComposeSpecification;
|
| 471 |
+
const suffix = "testhash";
|
| 472 |
+
|
| 473 |
+
const updatedComposeData = addSuffixToAllProperties(composeData, suffix);
|
| 474 |
+
|
| 475 |
+
expect(updatedComposeData).toEqual(expectedComposeFile);
|
| 476 |
+
});
|
data/apps/dokploy/__test__/compose/config/config-root.test.ts
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { generateRandomHash } from "@dokploy/server";
|
| 2 |
+
import { addSuffixToConfigsRoot } from "@dokploy/server";
|
| 3 |
+
import type { ComposeSpecification } from "@dokploy/server";
|
| 4 |
+
import { load } from "js-yaml";
|
| 5 |
+
import { expect, test } from "vitest";
|
| 6 |
+
|
| 7 |
+
test("Generate random hash with 8 characters", () => {
|
| 8 |
+
const hash = generateRandomHash();
|
| 9 |
+
|
| 10 |
+
expect(hash).toBeDefined();
|
| 11 |
+
expect(hash.length).toBe(8);
|
| 12 |
+
});
|
| 13 |
+
|
| 14 |
+
const composeFile = `
|
| 15 |
+
version: "3.8"
|
| 16 |
+
|
| 17 |
+
services:
|
| 18 |
+
web:
|
| 19 |
+
image: nginx:latest
|
| 20 |
+
|
| 21 |
+
configs:
|
| 22 |
+
web-config:
|
| 23 |
+
file: ./web-config.yml
|
| 24 |
+
`;
|
| 25 |
+
|
| 26 |
+
test("Add suffix to configs in root property", () => {
|
| 27 |
+
const composeData = load(composeFile) as ComposeSpecification;
|
| 28 |
+
|
| 29 |
+
const suffix = generateRandomHash();
|
| 30 |
+
|
| 31 |
+
if (!composeData?.configs) {
|
| 32 |
+
return;
|
| 33 |
+
}
|
| 34 |
+
const configs = addSuffixToConfigsRoot(composeData.configs, suffix);
|
| 35 |
+
|
| 36 |
+
expect(configs).toBeDefined();
|
| 37 |
+
for (const configKey of Object.keys(configs)) {
|
| 38 |
+
expect(configKey).toContain(`-${suffix}`);
|
| 39 |
+
expect(configs[configKey]).toBeDefined();
|
| 40 |
+
}
|
| 41 |
+
});
|
| 42 |
+
|
| 43 |
+
const composeFileMultipleConfigs = `
|
| 44 |
+
version: "3.8"
|
| 45 |
+
|
| 46 |
+
services:
|
| 47 |
+
web:
|
| 48 |
+
image: nginx:latest
|
| 49 |
+
configs:
|
| 50 |
+
- source: web-config
|
| 51 |
+
target: /etc/nginx/nginx.conf
|
| 52 |
+
- source: another-config
|
| 53 |
+
target: /etc/nginx/another.conf
|
| 54 |
+
|
| 55 |
+
configs:
|
| 56 |
+
web-config:
|
| 57 |
+
file: ./web-config.yml
|
| 58 |
+
another-config:
|
| 59 |
+
file: ./another-config.yml
|
| 60 |
+
`;
|
| 61 |
+
|
| 62 |
+
test("Add suffix to multiple configs in root property", () => {
|
| 63 |
+
const composeData = load(composeFileMultipleConfigs) as ComposeSpecification;
|
| 64 |
+
|
| 65 |
+
const suffix = generateRandomHash();
|
| 66 |
+
|
| 67 |
+
if (!composeData?.configs) {
|
| 68 |
+
return;
|
| 69 |
+
}
|
| 70 |
+
const configs = addSuffixToConfigsRoot(composeData.configs, suffix);
|
| 71 |
+
|
| 72 |
+
expect(configs).toBeDefined();
|
| 73 |
+
for (const configKey of Object.keys(configs)) {
|
| 74 |
+
expect(configKey).toContain(`-${suffix}`);
|
| 75 |
+
expect(configs[configKey]).toBeDefined();
|
| 76 |
+
}
|
| 77 |
+
expect(configs).toHaveProperty(`web-config-${suffix}`);
|
| 78 |
+
expect(configs).toHaveProperty(`another-config-${suffix}`);
|
| 79 |
+
});
|
| 80 |
+
|
| 81 |
+
const composeFileDifferentProperties = `
|
| 82 |
+
version: "3.8"
|
| 83 |
+
|
| 84 |
+
services:
|
| 85 |
+
web:
|
| 86 |
+
image: nginx:latest
|
| 87 |
+
|
| 88 |
+
configs:
|
| 89 |
+
web-config:
|
| 90 |
+
file: ./web-config.yml
|
| 91 |
+
special-config:
|
| 92 |
+
external: true
|
| 93 |
+
`;
|
| 94 |
+
|
| 95 |
+
test("Add suffix to configs with different properties in root property", () => {
|
| 96 |
+
const composeData = load(
|
| 97 |
+
composeFileDifferentProperties,
|
| 98 |
+
) as ComposeSpecification;
|
| 99 |
+
|
| 100 |
+
const suffix = generateRandomHash();
|
| 101 |
+
|
| 102 |
+
if (!composeData?.configs) {
|
| 103 |
+
return;
|
| 104 |
+
}
|
| 105 |
+
const configs = addSuffixToConfigsRoot(composeData.configs, suffix);
|
| 106 |
+
|
| 107 |
+
expect(configs).toBeDefined();
|
| 108 |
+
for (const configKey of Object.keys(configs)) {
|
| 109 |
+
expect(configKey).toContain(`-${suffix}`);
|
| 110 |
+
expect(configs[configKey]).toBeDefined();
|
| 111 |
+
}
|
| 112 |
+
expect(configs).toHaveProperty(`web-config-${suffix}`);
|
| 113 |
+
expect(configs).toHaveProperty(`special-config-${suffix}`);
|
| 114 |
+
});
|
| 115 |
+
|
| 116 |
+
const composeFileConfigRoot = `
|
| 117 |
+
version: "3.8"
|
| 118 |
+
|
| 119 |
+
services:
|
| 120 |
+
web:
|
| 121 |
+
image: nginx:latest
|
| 122 |
+
|
| 123 |
+
app:
|
| 124 |
+
image: node:latest
|
| 125 |
+
|
| 126 |
+
db:
|
| 127 |
+
image: postgres:latest
|
| 128 |
+
|
| 129 |
+
configs:
|
| 130 |
+
web_config:
|
| 131 |
+
file: ./web-config.yml
|
| 132 |
+
|
| 133 |
+
app_config:
|
| 134 |
+
file: ./app-config.json
|
| 135 |
+
|
| 136 |
+
db_config:
|
| 137 |
+
file: ./db-config.yml
|
| 138 |
+
`;
|
| 139 |
+
|
| 140 |
+
// Expected compose file con el prefijo `testhash`
|
| 141 |
+
const expectedComposeFileConfigRoot = load(`
|
| 142 |
+
version: "3.8"
|
| 143 |
+
|
| 144 |
+
services:
|
| 145 |
+
web:
|
| 146 |
+
image: nginx:latest
|
| 147 |
+
|
| 148 |
+
app:
|
| 149 |
+
image: node:latest
|
| 150 |
+
|
| 151 |
+
db:
|
| 152 |
+
image: postgres:latest
|
| 153 |
+
|
| 154 |
+
configs:
|
| 155 |
+
web_config-testhash:
|
| 156 |
+
file: ./web-config.yml
|
| 157 |
+
|
| 158 |
+
app_config-testhash:
|
| 159 |
+
file: ./app-config.json
|
| 160 |
+
|
| 161 |
+
db_config-testhash:
|
| 162 |
+
file: ./db-config.yml
|
| 163 |
+
`) as ComposeSpecification;
|
| 164 |
+
|
| 165 |
+
test("Add suffix to configs in root property", () => {
|
| 166 |
+
const composeData = load(composeFileConfigRoot) as ComposeSpecification;
|
| 167 |
+
|
| 168 |
+
const suffix = "testhash";
|
| 169 |
+
|
| 170 |
+
if (!composeData?.configs) {
|
| 171 |
+
return;
|
| 172 |
+
}
|
| 173 |
+
const configs = addSuffixToConfigsRoot(composeData.configs, suffix);
|
| 174 |
+
const updatedComposeData = { ...composeData, configs };
|
| 175 |
+
|
| 176 |
+
// Verificar que el resultado coincide con el archivo esperado
|
| 177 |
+
expect(updatedComposeData).toEqual(expectedComposeFileConfigRoot);
|
| 178 |
+
});
|
data/apps/dokploy/__test__/compose/config/config-service.test.ts
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { generateRandomHash } from "@dokploy/server";
|
| 2 |
+
import { addSuffixToConfigsInServices } from "@dokploy/server";
|
| 3 |
+
import type { ComposeSpecification } from "@dokploy/server";
|
| 4 |
+
import { load } from "js-yaml";
|
| 5 |
+
import { expect, test } from "vitest";
|
| 6 |
+
|
| 7 |
+
const composeFile = `
|
| 8 |
+
version: "3.8"
|
| 9 |
+
|
| 10 |
+
services:
|
| 11 |
+
web:
|
| 12 |
+
image: nginx:latest
|
| 13 |
+
configs:
|
| 14 |
+
- source: web-config
|
| 15 |
+
target: /etc/nginx/nginx.conf
|
| 16 |
+
|
| 17 |
+
configs:
|
| 18 |
+
web-config:
|
| 19 |
+
file: ./web-config.yml
|
| 20 |
+
`;
|
| 21 |
+
|
| 22 |
+
test("Add suffix to configs in services", () => {
|
| 23 |
+
const composeData = load(composeFile) as ComposeSpecification;
|
| 24 |
+
|
| 25 |
+
const suffix = generateRandomHash();
|
| 26 |
+
|
| 27 |
+
if (!composeData?.services) {
|
| 28 |
+
return;
|
| 29 |
+
}
|
| 30 |
+
const services = addSuffixToConfigsInServices(composeData.services, suffix);
|
| 31 |
+
const actualComposeData = { ...composeData, services };
|
| 32 |
+
|
| 33 |
+
expect(actualComposeData.services?.web?.configs).toContainEqual({
|
| 34 |
+
source: `web-config-${suffix}`,
|
| 35 |
+
target: "/etc/nginx/nginx.conf",
|
| 36 |
+
});
|
| 37 |
+
});
|
| 38 |
+
|
| 39 |
+
const composeFileSingleServiceConfig = `
|
| 40 |
+
version: "3.8"
|
| 41 |
+
|
| 42 |
+
services:
|
| 43 |
+
web:
|
| 44 |
+
image: nginx:latest
|
| 45 |
+
configs:
|
| 46 |
+
- source: web-config
|
| 47 |
+
target: /etc/nginx/nginx.conf
|
| 48 |
+
|
| 49 |
+
configs:
|
| 50 |
+
web-config:
|
| 51 |
+
file: ./web-config.yml
|
| 52 |
+
`;
|
| 53 |
+
|
| 54 |
+
test("Add suffix to configs in services with single config", () => {
|
| 55 |
+
const composeData = load(
|
| 56 |
+
composeFileSingleServiceConfig,
|
| 57 |
+
) as ComposeSpecification;
|
| 58 |
+
|
| 59 |
+
const suffix = generateRandomHash();
|
| 60 |
+
|
| 61 |
+
if (!composeData?.services) {
|
| 62 |
+
return;
|
| 63 |
+
}
|
| 64 |
+
const services = addSuffixToConfigsInServices(composeData.services, suffix);
|
| 65 |
+
|
| 66 |
+
expect(services).toBeDefined();
|
| 67 |
+
for (const serviceKey of Object.keys(services)) {
|
| 68 |
+
const serviceConfigs = services?.[serviceKey]?.configs;
|
| 69 |
+
if (serviceConfigs) {
|
| 70 |
+
for (const config of serviceConfigs) {
|
| 71 |
+
if (typeof config === "object") {
|
| 72 |
+
expect(config.source).toContain(`-${suffix}`);
|
| 73 |
+
}
|
| 74 |
+
}
|
| 75 |
+
}
|
| 76 |
+
}
|
| 77 |
+
});
|
| 78 |
+
|
| 79 |
+
const composeFileMultipleServicesConfigs = `
|
| 80 |
+
version: "3.8"
|
| 81 |
+
|
| 82 |
+
services:
|
| 83 |
+
web:
|
| 84 |
+
image: nginx:latest
|
| 85 |
+
configs:
|
| 86 |
+
- source: web-config
|
| 87 |
+
target: /etc/nginx/nginx.conf
|
| 88 |
+
- source: common-config
|
| 89 |
+
target: /etc/nginx/common.conf
|
| 90 |
+
|
| 91 |
+
app:
|
| 92 |
+
image: node:14
|
| 93 |
+
configs:
|
| 94 |
+
- source: app-config
|
| 95 |
+
target: /usr/src/app/config.json
|
| 96 |
+
- source: common-config
|
| 97 |
+
target: /usr/src/app/common.json
|
| 98 |
+
|
| 99 |
+
configs:
|
| 100 |
+
web-config:
|
| 101 |
+
file: ./web-config.yml
|
| 102 |
+
app-config:
|
| 103 |
+
file: ./app-config.json
|
| 104 |
+
common-config:
|
| 105 |
+
file: ./common-config.yml
|
| 106 |
+
`;
|
| 107 |
+
|
| 108 |
+
test("Add suffix to configs in services with multiple configs", () => {
|
| 109 |
+
const composeData = load(
|
| 110 |
+
composeFileMultipleServicesConfigs,
|
| 111 |
+
) as ComposeSpecification;
|
| 112 |
+
|
| 113 |
+
const suffix = generateRandomHash();
|
| 114 |
+
|
| 115 |
+
if (!composeData?.services) {
|
| 116 |
+
return;
|
| 117 |
+
}
|
| 118 |
+
const services = addSuffixToConfigsInServices(composeData.services, suffix);
|
| 119 |
+
|
| 120 |
+
expect(services).toBeDefined();
|
| 121 |
+
for (const serviceKey of Object.keys(services)) {
|
| 122 |
+
const serviceConfigs = services?.[serviceKey]?.configs;
|
| 123 |
+
if (serviceConfigs) {
|
| 124 |
+
for (const config of serviceConfigs) {
|
| 125 |
+
if (typeof config === "object") {
|
| 126 |
+
expect(config.source).toContain(`-${suffix}`);
|
| 127 |
+
}
|
| 128 |
+
}
|
| 129 |
+
}
|
| 130 |
+
}
|
| 131 |
+
});
|
| 132 |
+
|
| 133 |
+
const composeFileConfigServices = `
|
| 134 |
+
version: "3.8"
|
| 135 |
+
|
| 136 |
+
services:
|
| 137 |
+
web:
|
| 138 |
+
image: nginx:latest
|
| 139 |
+
configs:
|
| 140 |
+
- source: web_config
|
| 141 |
+
target: /etc/nginx/nginx.conf
|
| 142 |
+
|
| 143 |
+
app:
|
| 144 |
+
image: node:latest
|
| 145 |
+
configs:
|
| 146 |
+
- source: app_config
|
| 147 |
+
target: /usr/src/app/config.json
|
| 148 |
+
|
| 149 |
+
db:
|
| 150 |
+
image: postgres:latest
|
| 151 |
+
configs:
|
| 152 |
+
- source: db_config
|
| 153 |
+
target: /etc/postgresql/postgresql.conf
|
| 154 |
+
|
| 155 |
+
`;
|
| 156 |
+
|
| 157 |
+
// Expected compose file con el prefijo `testhash`
|
| 158 |
+
const expectedComposeFileConfigServices = load(`
|
| 159 |
+
version: "3.8"
|
| 160 |
+
|
| 161 |
+
services:
|
| 162 |
+
web:
|
| 163 |
+
image: nginx:latest
|
| 164 |
+
configs:
|
| 165 |
+
- source: web_config-testhash
|
| 166 |
+
target: /etc/nginx/nginx.conf
|
| 167 |
+
|
| 168 |
+
app:
|
| 169 |
+
image: node:latest
|
| 170 |
+
configs:
|
| 171 |
+
- source: app_config-testhash
|
| 172 |
+
target: /usr/src/app/config.json
|
| 173 |
+
|
| 174 |
+
db:
|
| 175 |
+
image: postgres:latest
|
| 176 |
+
configs:
|
| 177 |
+
- source: db_config-testhash
|
| 178 |
+
target: /etc/postgresql/postgresql.conf
|
| 179 |
+
|
| 180 |
+
`) as ComposeSpecification;
|
| 181 |
+
|
| 182 |
+
test("Add suffix to configs in services", () => {
|
| 183 |
+
const composeData = load(composeFileConfigServices) as ComposeSpecification;
|
| 184 |
+
|
| 185 |
+
const suffix = "testhash";
|
| 186 |
+
|
| 187 |
+
if (!composeData?.services) {
|
| 188 |
+
return;
|
| 189 |
+
}
|
| 190 |
+
const updatedComposeData = addSuffixToConfigsInServices(
|
| 191 |
+
composeData.services,
|
| 192 |
+
suffix,
|
| 193 |
+
);
|
| 194 |
+
const actualComposeData = { ...composeData, services: updatedComposeData };
|
| 195 |
+
|
| 196 |
+
expect(actualComposeData).toEqual(expectedComposeFileConfigServices);
|
| 197 |
+
});
|
data/apps/dokploy/__test__/compose/config/config.test.ts
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { generateRandomHash } from "@dokploy/server";
|
| 2 |
+
import { addSuffixToAllConfigs } from "@dokploy/server";
|
| 3 |
+
import type { ComposeSpecification } from "@dokploy/server";
|
| 4 |
+
import { load } from "js-yaml";
|
| 5 |
+
import { expect, test } from "vitest";
|
| 6 |
+
|
| 7 |
+
test("Generate random hash with 8 characters", () => {
|
| 8 |
+
const hash = generateRandomHash();
|
| 9 |
+
|
| 10 |
+
expect(hash).toBeDefined();
|
| 11 |
+
expect(hash.length).toBe(8);
|
| 12 |
+
});
|
| 13 |
+
|
| 14 |
+
const composeFileCombinedConfigs = `
|
| 15 |
+
version: "3.8"
|
| 16 |
+
|
| 17 |
+
services:
|
| 18 |
+
web:
|
| 19 |
+
image: nginx:latest
|
| 20 |
+
configs:
|
| 21 |
+
- source: web_config
|
| 22 |
+
target: /etc/nginx/nginx.conf
|
| 23 |
+
|
| 24 |
+
app:
|
| 25 |
+
image: node:14
|
| 26 |
+
configs:
|
| 27 |
+
- source: app_config
|
| 28 |
+
target: /usr/src/app/config.json
|
| 29 |
+
|
| 30 |
+
db:
|
| 31 |
+
image: postgres:13
|
| 32 |
+
configs:
|
| 33 |
+
- source: db_config
|
| 34 |
+
target: /etc/postgresql/postgresql.conf
|
| 35 |
+
|
| 36 |
+
configs:
|
| 37 |
+
web_config:
|
| 38 |
+
file: ./web-config.yml
|
| 39 |
+
|
| 40 |
+
app_config:
|
| 41 |
+
file: ./app-config.json
|
| 42 |
+
|
| 43 |
+
db_config:
|
| 44 |
+
file: ./db-config.yml
|
| 45 |
+
`;
|
| 46 |
+
|
| 47 |
+
const expectedComposeFileCombinedConfigs = load(`
|
| 48 |
+
version: "3.8"
|
| 49 |
+
|
| 50 |
+
services:
|
| 51 |
+
web:
|
| 52 |
+
image: nginx:latest
|
| 53 |
+
configs:
|
| 54 |
+
- source: web_config-testhash
|
| 55 |
+
target: /etc/nginx/nginx.conf
|
| 56 |
+
|
| 57 |
+
app:
|
| 58 |
+
image: node:14
|
| 59 |
+
configs:
|
| 60 |
+
- source: app_config-testhash
|
| 61 |
+
target: /usr/src/app/config.json
|
| 62 |
+
|
| 63 |
+
db:
|
| 64 |
+
image: postgres:13
|
| 65 |
+
configs:
|
| 66 |
+
- source: db_config-testhash
|
| 67 |
+
target: /etc/postgresql/postgresql.conf
|
| 68 |
+
|
| 69 |
+
configs:
|
| 70 |
+
web_config-testhash:
|
| 71 |
+
file: ./web-config.yml
|
| 72 |
+
|
| 73 |
+
app_config-testhash:
|
| 74 |
+
file: ./app-config.json
|
| 75 |
+
|
| 76 |
+
db_config-testhash:
|
| 77 |
+
file: ./db-config.yml
|
| 78 |
+
`) as ComposeSpecification;
|
| 79 |
+
|
| 80 |
+
test("Add suffix to all configs in root and services", () => {
|
| 81 |
+
const composeData = load(composeFileCombinedConfigs) as ComposeSpecification;
|
| 82 |
+
|
| 83 |
+
const suffix = "testhash";
|
| 84 |
+
|
| 85 |
+
const updatedComposeData = addSuffixToAllConfigs(composeData, suffix);
|
| 86 |
+
|
| 87 |
+
expect(updatedComposeData).toEqual(expectedComposeFileCombinedConfigs);
|
| 88 |
+
});
|
| 89 |
+
|
| 90 |
+
const composeFileWithEnvAndExternal = `
|
| 91 |
+
version: "3.8"
|
| 92 |
+
|
| 93 |
+
services:
|
| 94 |
+
web:
|
| 95 |
+
image: nginx:latest
|
| 96 |
+
configs:
|
| 97 |
+
- source: web_config
|
| 98 |
+
target: /etc/nginx/nginx.conf
|
| 99 |
+
environment:
|
| 100 |
+
- NGINX_CONFIG=/etc/nginx/nginx.conf
|
| 101 |
+
|
| 102 |
+
app:
|
| 103 |
+
image: node:14
|
| 104 |
+
configs:
|
| 105 |
+
- source: app_config
|
| 106 |
+
target: /usr/src/app/config.json
|
| 107 |
+
|
| 108 |
+
db:
|
| 109 |
+
image: postgres:13
|
| 110 |
+
configs:
|
| 111 |
+
- source: db_config
|
| 112 |
+
target: /etc/postgresql/postgresql.conf
|
| 113 |
+
|
| 114 |
+
configs:
|
| 115 |
+
web_config:
|
| 116 |
+
external: true
|
| 117 |
+
|
| 118 |
+
app_config:
|
| 119 |
+
file: ./app-config.json
|
| 120 |
+
|
| 121 |
+
db_config:
|
| 122 |
+
environment: dev
|
| 123 |
+
file: ./db-config.yml
|
| 124 |
+
`;
|
| 125 |
+
|
| 126 |
+
const expectedComposeFileWithEnvAndExternal = load(`
|
| 127 |
+
version: "3.8"
|
| 128 |
+
|
| 129 |
+
services:
|
| 130 |
+
web:
|
| 131 |
+
image: nginx:latest
|
| 132 |
+
configs:
|
| 133 |
+
- source: web_config-testhash
|
| 134 |
+
target: /etc/nginx/nginx.conf
|
| 135 |
+
environment:
|
| 136 |
+
- NGINX_CONFIG=/etc/nginx/nginx.conf
|
| 137 |
+
|
| 138 |
+
app:
|
| 139 |
+
image: node:14
|
| 140 |
+
configs:
|
| 141 |
+
- source: app_config-testhash
|
| 142 |
+
target: /usr/src/app/config.json
|
| 143 |
+
|
| 144 |
+
db:
|
| 145 |
+
image: postgres:13
|
| 146 |
+
configs:
|
| 147 |
+
- source: db_config-testhash
|
| 148 |
+
target: /etc/postgresql/postgresql.conf
|
| 149 |
+
|
| 150 |
+
configs:
|
| 151 |
+
web_config-testhash:
|
| 152 |
+
external: true
|
| 153 |
+
|
| 154 |
+
app_config-testhash:
|
| 155 |
+
file: ./app-config.json
|
| 156 |
+
|
| 157 |
+
db_config-testhash:
|
| 158 |
+
environment: dev
|
| 159 |
+
file: ./db-config.yml
|
| 160 |
+
`) as ComposeSpecification;
|
| 161 |
+
|
| 162 |
+
test("Add suffix to configs with environment and external", () => {
|
| 163 |
+
const composeData = load(
|
| 164 |
+
composeFileWithEnvAndExternal,
|
| 165 |
+
) as ComposeSpecification;
|
| 166 |
+
|
| 167 |
+
const suffix = "testhash";
|
| 168 |
+
|
| 169 |
+
const updatedComposeData = addSuffixToAllConfigs(composeData, suffix);
|
| 170 |
+
|
| 171 |
+
expect(updatedComposeData).toEqual(expectedComposeFileWithEnvAndExternal);
|
| 172 |
+
});
|
| 173 |
+
|
| 174 |
+
const composeFileWithTemplateDriverAndLabels = `
|
| 175 |
+
version: "3.8"
|
| 176 |
+
|
| 177 |
+
services:
|
| 178 |
+
web:
|
| 179 |
+
image: nginx:latest
|
| 180 |
+
configs:
|
| 181 |
+
- source: web_config
|
| 182 |
+
target: /etc/nginx/nginx.conf
|
| 183 |
+
|
| 184 |
+
app:
|
| 185 |
+
image: node:14
|
| 186 |
+
configs:
|
| 187 |
+
- source: app_config
|
| 188 |
+
target: /usr/src/app/config.json
|
| 189 |
+
|
| 190 |
+
configs:
|
| 191 |
+
web_config:
|
| 192 |
+
file: ./web-config.yml
|
| 193 |
+
template_driver: golang
|
| 194 |
+
|
| 195 |
+
app_config:
|
| 196 |
+
file: ./app-config.json
|
| 197 |
+
labels:
|
| 198 |
+
- app=frontend
|
| 199 |
+
|
| 200 |
+
db_config:
|
| 201 |
+
file: ./db-config.yml
|
| 202 |
+
`;
|
| 203 |
+
|
| 204 |
+
const expectedComposeFileWithTemplateDriverAndLabels = load(`
|
| 205 |
+
version: "3.8"
|
| 206 |
+
|
| 207 |
+
services:
|
| 208 |
+
web:
|
| 209 |
+
image: nginx:latest
|
| 210 |
+
configs:
|
| 211 |
+
- source: web_config-testhash
|
| 212 |
+
target: /etc/nginx/nginx.conf
|
| 213 |
+
|
| 214 |
+
app:
|
| 215 |
+
image: node:14
|
| 216 |
+
configs:
|
| 217 |
+
- source: app_config-testhash
|
| 218 |
+
target: /usr/src/app/config.json
|
| 219 |
+
|
| 220 |
+
configs:
|
| 221 |
+
web_config-testhash:
|
| 222 |
+
file: ./web-config.yml
|
| 223 |
+
template_driver: golang
|
| 224 |
+
|
| 225 |
+
app_config-testhash:
|
| 226 |
+
file: ./app-config.json
|
| 227 |
+
labels:
|
| 228 |
+
- app=frontend
|
| 229 |
+
|
| 230 |
+
db_config-testhash:
|
| 231 |
+
file: ./db-config.yml
|
| 232 |
+
`) as ComposeSpecification;
|
| 233 |
+
|
| 234 |
+
test("Add suffix to configs with template driver and labels", () => {
|
| 235 |
+
const composeData = load(
|
| 236 |
+
composeFileWithTemplateDriverAndLabels,
|
| 237 |
+
) as ComposeSpecification;
|
| 238 |
+
|
| 239 |
+
const suffix = "testhash";
|
| 240 |
+
|
| 241 |
+
const updatedComposeData = addSuffixToAllConfigs(composeData, suffix);
|
| 242 |
+
|
| 243 |
+
expect(updatedComposeData).toEqual(
|
| 244 |
+
expectedComposeFileWithTemplateDriverAndLabels,
|
| 245 |
+
);
|
| 246 |
+
});
|
data/apps/dokploy/__test__/compose/domain/labels.test.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { Domain } from "@dokploy/server";
|
| 2 |
+
import { createDomainLabels } from "@dokploy/server";
|
| 3 |
+
import { describe, expect, it } from "vitest";
|
| 4 |
+
|
| 5 |
+
describe("createDomainLabels", () => {
|
| 6 |
+
const appName = "test-app";
|
| 7 |
+
const baseDomain: Domain = {
|
| 8 |
+
host: "example.com",
|
| 9 |
+
port: 8080,
|
| 10 |
+
https: false,
|
| 11 |
+
uniqueConfigKey: 1,
|
| 12 |
+
customCertResolver: null,
|
| 13 |
+
certificateType: "none",
|
| 14 |
+
applicationId: "",
|
| 15 |
+
composeId: "",
|
| 16 |
+
domainType: "compose",
|
| 17 |
+
serviceName: "test-app",
|
| 18 |
+
domainId: "",
|
| 19 |
+
path: "/",
|
| 20 |
+
createdAt: "",
|
| 21 |
+
previewDeploymentId: "",
|
| 22 |
+
};
|
| 23 |
+
|
| 24 |
+
it("should create basic labels for web entrypoint", async () => {
|
| 25 |
+
const labels = await createDomainLabels(appName, baseDomain, "web");
|
| 26 |
+
expect(labels).toEqual([
|
| 27 |
+
"traefik.http.routers.test-app-1-web.rule=Host(`example.com`)",
|
| 28 |
+
"traefik.http.routers.test-app-1-web.entrypoints=web",
|
| 29 |
+
"traefik.http.services.test-app-1-web.loadbalancer.server.port=8080",
|
| 30 |
+
"traefik.http.routers.test-app-1-web.service=test-app-1-web",
|
| 31 |
+
]);
|
| 32 |
+
});
|
| 33 |
+
|
| 34 |
+
it("should create labels for websecure entrypoint", async () => {
|
| 35 |
+
const labels = await createDomainLabels(appName, baseDomain, "websecure");
|
| 36 |
+
expect(labels).toEqual([
|
| 37 |
+
"traefik.http.routers.test-app-1-websecure.rule=Host(`example.com`)",
|
| 38 |
+
"traefik.http.routers.test-app-1-websecure.entrypoints=websecure",
|
| 39 |
+
"traefik.http.services.test-app-1-websecure.loadbalancer.server.port=8080",
|
| 40 |
+
"traefik.http.routers.test-app-1-websecure.service=test-app-1-websecure",
|
| 41 |
+
]);
|
| 42 |
+
});
|
| 43 |
+
|
| 44 |
+
it("should add the path prefix if is different than / empty", async () => {
|
| 45 |
+
const labels = await createDomainLabels(
|
| 46 |
+
appName,
|
| 47 |
+
{
|
| 48 |
+
...baseDomain,
|
| 49 |
+
path: "/hello",
|
| 50 |
+
},
|
| 51 |
+
"websecure",
|
| 52 |
+
);
|
| 53 |
+
|
| 54 |
+
expect(labels).toEqual([
|
| 55 |
+
"traefik.http.routers.test-app-1-websecure.rule=Host(`example.com`) && PathPrefix(`/hello`)",
|
| 56 |
+
"traefik.http.routers.test-app-1-websecure.entrypoints=websecure",
|
| 57 |
+
"traefik.http.services.test-app-1-websecure.loadbalancer.server.port=8080",
|
| 58 |
+
"traefik.http.routers.test-app-1-websecure.service=test-app-1-websecure",
|
| 59 |
+
]);
|
| 60 |
+
});
|
| 61 |
+
|
| 62 |
+
it("should add redirect middleware for https on web entrypoint", async () => {
|
| 63 |
+
const httpsBaseDomain = { ...baseDomain, https: true };
|
| 64 |
+
const labels = await createDomainLabels(appName, httpsBaseDomain, "web");
|
| 65 |
+
expect(labels).toContain(
|
| 66 |
+
"traefik.http.routers.test-app-1-web.middlewares=redirect-to-https@file",
|
| 67 |
+
);
|
| 68 |
+
});
|
| 69 |
+
|
| 70 |
+
it("should add Let's Encrypt configuration for websecure with letsencrypt certificate", async () => {
|
| 71 |
+
const letsencryptDomain = {
|
| 72 |
+
...baseDomain,
|
| 73 |
+
https: true,
|
| 74 |
+
certificateType: "letsencrypt" as const,
|
| 75 |
+
};
|
| 76 |
+
const labels = await createDomainLabels(
|
| 77 |
+
appName,
|
| 78 |
+
letsencryptDomain,
|
| 79 |
+
"websecure",
|
| 80 |
+
);
|
| 81 |
+
expect(labels).toContain(
|
| 82 |
+
"traefik.http.routers.test-app-1-websecure.tls.certresolver=letsencrypt",
|
| 83 |
+
);
|
| 84 |
+
});
|
| 85 |
+
|
| 86 |
+
it("should not add Let's Encrypt configuration for non-letsencrypt certificate", async () => {
|
| 87 |
+
const nonLetsencryptDomain = {
|
| 88 |
+
...baseDomain,
|
| 89 |
+
https: true,
|
| 90 |
+
certificateType: "none" as const,
|
| 91 |
+
};
|
| 92 |
+
const labels = await createDomainLabels(
|
| 93 |
+
appName,
|
| 94 |
+
nonLetsencryptDomain,
|
| 95 |
+
"websecure",
|
| 96 |
+
);
|
| 97 |
+
expect(labels).not.toContain(
|
| 98 |
+
"traefik.http.routers.test-app-1-websecure.tls.certresolver=letsencrypt",
|
| 99 |
+
);
|
| 100 |
+
});
|
| 101 |
+
|
| 102 |
+
it("should handle different ports correctly", async () => {
|
| 103 |
+
const customPortDomain = { ...baseDomain, port: 3000 };
|
| 104 |
+
const labels = await createDomainLabels(appName, customPortDomain, "web");
|
| 105 |
+
expect(labels).toContain(
|
| 106 |
+
"traefik.http.services.test-app-1-web.loadbalancer.server.port=3000",
|
| 107 |
+
);
|
| 108 |
+
});
|
| 109 |
+
});
|
data/apps/dokploy/__test__/compose/domain/network-root.test.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { addDokployNetworkToRoot } from "@dokploy/server";
|
| 2 |
+
import { describe, expect, it } from "vitest";
|
| 3 |
+
|
| 4 |
+
describe("addDokployNetworkToRoot", () => {
|
| 5 |
+
it("should create network object if networks is undefined", () => {
|
| 6 |
+
const result = addDokployNetworkToRoot(undefined);
|
| 7 |
+
expect(result).toEqual({ "dokploy-network": { external: true } });
|
| 8 |
+
});
|
| 9 |
+
|
| 10 |
+
it("should add network to an empty object", () => {
|
| 11 |
+
const result = addDokployNetworkToRoot({});
|
| 12 |
+
expect(result).toEqual({ "dokploy-network": { external: true } });
|
| 13 |
+
});
|
| 14 |
+
|
| 15 |
+
it("should not modify existing network configuration", () => {
|
| 16 |
+
const existing = { "dokploy-network": { external: false } };
|
| 17 |
+
const result = addDokployNetworkToRoot(existing);
|
| 18 |
+
expect(result).toEqual({ "dokploy-network": { external: true } });
|
| 19 |
+
});
|
| 20 |
+
|
| 21 |
+
it("should add network alongside existing networks", () => {
|
| 22 |
+
const existing = { "other-network": { external: true } };
|
| 23 |
+
const result = addDokployNetworkToRoot(existing);
|
| 24 |
+
expect(result).toEqual({
|
| 25 |
+
"other-network": { external: true },
|
| 26 |
+
"dokploy-network": { external: true },
|
| 27 |
+
});
|
| 28 |
+
});
|
| 29 |
+
});
|
data/apps/dokploy/__test__/compose/domain/network-service.test.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { addDokployNetworkToService } from "@dokploy/server";
|
| 2 |
+
import { describe, expect, it } from "vitest";
|
| 3 |
+
|
| 4 |
+
describe("addDokployNetworkToService", () => {
|
| 5 |
+
it("should add network to an empty array", () => {
|
| 6 |
+
const result = addDokployNetworkToService([]);
|
| 7 |
+
expect(result).toEqual(["dokploy-network"]);
|
| 8 |
+
});
|
| 9 |
+
|
| 10 |
+
it("should not add duplicate network to an array", () => {
|
| 11 |
+
const result = addDokployNetworkToService(["dokploy-network"]);
|
| 12 |
+
expect(result).toEqual(["dokploy-network"]);
|
| 13 |
+
});
|
| 14 |
+
|
| 15 |
+
it("should add network to an existing array with other networks", () => {
|
| 16 |
+
const result = addDokployNetworkToService(["other-network"]);
|
| 17 |
+
expect(result).toEqual(["other-network", "dokploy-network"]);
|
| 18 |
+
});
|
| 19 |
+
|
| 20 |
+
it("should add network to an object if networks is an object", () => {
|
| 21 |
+
const result = addDokployNetworkToService({ "other-network": {} });
|
| 22 |
+
expect(result).toEqual({ "other-network": {}, "dokploy-network": {} });
|
| 23 |
+
});
|
| 24 |
+
});
|
data/apps/dokploy/__test__/compose/network/network-root.test.ts
ADDED
|
@@ -0,0 +1,310 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { generateRandomHash } from "@dokploy/server";
|
| 2 |
+
import { addSuffixToNetworksRoot } from "@dokploy/server";
|
| 3 |
+
import type { ComposeSpecification } from "@dokploy/server";
|
| 4 |
+
import { load } from "js-yaml";
|
| 5 |
+
import { expect, test } from "vitest";
|
| 6 |
+
|
| 7 |
+
const composeFile = `
|
| 8 |
+
version: "3.8"
|
| 9 |
+
|
| 10 |
+
services:
|
| 11 |
+
web:
|
| 12 |
+
image: nginx:latest
|
| 13 |
+
networks:
|
| 14 |
+
- frontend
|
| 15 |
+
|
| 16 |
+
networks:
|
| 17 |
+
frontend:
|
| 18 |
+
driver: bridge
|
| 19 |
+
driver_opts:
|
| 20 |
+
com.docker.network.driver.mtu: 1200
|
| 21 |
+
|
| 22 |
+
backend:
|
| 23 |
+
driver: bridge
|
| 24 |
+
attachable: true
|
| 25 |
+
|
| 26 |
+
external_network:
|
| 27 |
+
external: true
|
| 28 |
+
|
| 29 |
+
`;
|
| 30 |
+
|
| 31 |
+
test("Generate random hash with 8 characters", () => {
|
| 32 |
+
const hash = generateRandomHash();
|
| 33 |
+
|
| 34 |
+
expect(hash).toBeDefined();
|
| 35 |
+
expect(hash.length).toBe(8);
|
| 36 |
+
});
|
| 37 |
+
|
| 38 |
+
test("Add suffix to networks root property", () => {
|
| 39 |
+
const composeData = load(composeFile) as ComposeSpecification;
|
| 40 |
+
|
| 41 |
+
const suffix = generateRandomHash();
|
| 42 |
+
|
| 43 |
+
if (!composeData?.networks) {
|
| 44 |
+
return;
|
| 45 |
+
}
|
| 46 |
+
const networks = addSuffixToNetworksRoot(composeData.networks, suffix);
|
| 47 |
+
|
| 48 |
+
expect(networks).toBeDefined();
|
| 49 |
+
for (const volumeKey of Object.keys(networks)) {
|
| 50 |
+
expect(volumeKey).toContain(`-${suffix}`);
|
| 51 |
+
}
|
| 52 |
+
});
|
| 53 |
+
|
| 54 |
+
const composeFile2 = `
|
| 55 |
+
version: "3.8"
|
| 56 |
+
|
| 57 |
+
services:
|
| 58 |
+
app:
|
| 59 |
+
image: myapp:latest
|
| 60 |
+
networks:
|
| 61 |
+
- app_net
|
| 62 |
+
|
| 63 |
+
networks:
|
| 64 |
+
app_net:
|
| 65 |
+
driver: bridge
|
| 66 |
+
driver_opts:
|
| 67 |
+
com.docker.network.driver.mtu: 1500
|
| 68 |
+
ipam:
|
| 69 |
+
driver: default
|
| 70 |
+
config:
|
| 71 |
+
- subnet: 172.20.0.0/16
|
| 72 |
+
|
| 73 |
+
database_net:
|
| 74 |
+
driver: overlay
|
| 75 |
+
attachable: true
|
| 76 |
+
|
| 77 |
+
monitoring_net:
|
| 78 |
+
driver: bridge
|
| 79 |
+
internal: true
|
| 80 |
+
`;
|
| 81 |
+
|
| 82 |
+
test("Add suffix to advanced networks root property (2 TRY)", () => {
|
| 83 |
+
const composeData = load(composeFile2) as ComposeSpecification;
|
| 84 |
+
|
| 85 |
+
const suffix = generateRandomHash();
|
| 86 |
+
|
| 87 |
+
if (!composeData?.networks) {
|
| 88 |
+
return;
|
| 89 |
+
}
|
| 90 |
+
const networks = addSuffixToNetworksRoot(composeData.networks, suffix);
|
| 91 |
+
|
| 92 |
+
expect(networks).toBeDefined();
|
| 93 |
+
for (const networkKey of Object.keys(networks)) {
|
| 94 |
+
expect(networkKey).toContain(`-${suffix}`);
|
| 95 |
+
}
|
| 96 |
+
});
|
| 97 |
+
|
| 98 |
+
const composeFile3 = `
|
| 99 |
+
version: "3.8"
|
| 100 |
+
|
| 101 |
+
services:
|
| 102 |
+
web:
|
| 103 |
+
image: nginx:latest
|
| 104 |
+
networks:
|
| 105 |
+
- frontend
|
| 106 |
+
- backend
|
| 107 |
+
|
| 108 |
+
networks:
|
| 109 |
+
frontend:
|
| 110 |
+
external:
|
| 111 |
+
name: my_external_network
|
| 112 |
+
|
| 113 |
+
backend:
|
| 114 |
+
driver: bridge
|
| 115 |
+
labels:
|
| 116 |
+
- "com.example.description=Backend network"
|
| 117 |
+
- "com.example.environment=production"
|
| 118 |
+
|
| 119 |
+
external_network:
|
| 120 |
+
external: true
|
| 121 |
+
`;
|
| 122 |
+
|
| 123 |
+
test("Add suffix to networks with external properties", () => {
|
| 124 |
+
const composeData = load(composeFile3) as ComposeSpecification;
|
| 125 |
+
|
| 126 |
+
const suffix = generateRandomHash();
|
| 127 |
+
|
| 128 |
+
if (!composeData?.networks) {
|
| 129 |
+
return;
|
| 130 |
+
}
|
| 131 |
+
const networks = addSuffixToNetworksRoot(composeData.networks, suffix);
|
| 132 |
+
|
| 133 |
+
expect(networks).toBeDefined();
|
| 134 |
+
for (const networkKey of Object.keys(networks)) {
|
| 135 |
+
expect(networkKey).toContain(`-${suffix}`);
|
| 136 |
+
}
|
| 137 |
+
});
|
| 138 |
+
|
| 139 |
+
const composeFile4 = `
|
| 140 |
+
version: "3.8"
|
| 141 |
+
|
| 142 |
+
services:
|
| 143 |
+
db:
|
| 144 |
+
image: postgres:13
|
| 145 |
+
networks:
|
| 146 |
+
- db_net
|
| 147 |
+
|
| 148 |
+
networks:
|
| 149 |
+
db_net:
|
| 150 |
+
driver: bridge
|
| 151 |
+
ipam:
|
| 152 |
+
config:
|
| 153 |
+
- subnet: 192.168.1.0/24
|
| 154 |
+
- gateway: 192.168.1.1
|
| 155 |
+
- aux_addresses:
|
| 156 |
+
host1: 192.168.1.2
|
| 157 |
+
host2: 192.168.1.3
|
| 158 |
+
|
| 159 |
+
external_network:
|
| 160 |
+
external: true
|
| 161 |
+
`;
|
| 162 |
+
|
| 163 |
+
test("Add suffix to networks with IPAM configurations", () => {
|
| 164 |
+
const composeData = load(composeFile4) as ComposeSpecification;
|
| 165 |
+
|
| 166 |
+
const suffix = generateRandomHash();
|
| 167 |
+
|
| 168 |
+
if (!composeData?.networks) {
|
| 169 |
+
return;
|
| 170 |
+
}
|
| 171 |
+
const networks = addSuffixToNetworksRoot(composeData.networks, suffix);
|
| 172 |
+
|
| 173 |
+
expect(networks).toBeDefined();
|
| 174 |
+
for (const networkKey of Object.keys(networks)) {
|
| 175 |
+
expect(networkKey).toContain(`-${suffix}`);
|
| 176 |
+
}
|
| 177 |
+
});
|
| 178 |
+
|
| 179 |
+
const composeFile5 = `
|
| 180 |
+
version: "3.8"
|
| 181 |
+
|
| 182 |
+
services:
|
| 183 |
+
api:
|
| 184 |
+
image: myapi:latest
|
| 185 |
+
networks:
|
| 186 |
+
- api_net
|
| 187 |
+
|
| 188 |
+
networks:
|
| 189 |
+
api_net:
|
| 190 |
+
driver: bridge
|
| 191 |
+
options:
|
| 192 |
+
com.docker.network.bridge.name: br0
|
| 193 |
+
enable_ipv6: true
|
| 194 |
+
ipam:
|
| 195 |
+
driver: default
|
| 196 |
+
config:
|
| 197 |
+
- subnet: "2001:db8:1::/64"
|
| 198 |
+
- gateway: "2001:db8:1::1"
|
| 199 |
+
|
| 200 |
+
external_network:
|
| 201 |
+
external: true
|
| 202 |
+
`;
|
| 203 |
+
|
| 204 |
+
test("Add suffix to networks with custom options", () => {
|
| 205 |
+
const composeData = load(composeFile5) as ComposeSpecification;
|
| 206 |
+
|
| 207 |
+
const suffix = generateRandomHash();
|
| 208 |
+
|
| 209 |
+
if (!composeData?.networks) {
|
| 210 |
+
return;
|
| 211 |
+
}
|
| 212 |
+
const networks = addSuffixToNetworksRoot(composeData.networks, suffix);
|
| 213 |
+
|
| 214 |
+
expect(networks).toBeDefined();
|
| 215 |
+
for (const networkKey of Object.keys(networks)) {
|
| 216 |
+
expect(networkKey).toContain(`-${suffix}`);
|
| 217 |
+
}
|
| 218 |
+
});
|
| 219 |
+
|
| 220 |
+
const composeFile6 = `
|
| 221 |
+
version: "3.8"
|
| 222 |
+
|
| 223 |
+
services:
|
| 224 |
+
web:
|
| 225 |
+
image: nginx:latest
|
| 226 |
+
networks:
|
| 227 |
+
- frontend
|
| 228 |
+
|
| 229 |
+
networks:
|
| 230 |
+
frontend:
|
| 231 |
+
driver: bridge
|
| 232 |
+
driver_opts:
|
| 233 |
+
com.docker.network.driver.mtu: 1200
|
| 234 |
+
|
| 235 |
+
backend:
|
| 236 |
+
driver: bridge
|
| 237 |
+
attachable: true
|
| 238 |
+
|
| 239 |
+
external_network:
|
| 240 |
+
external: true
|
| 241 |
+
`;
|
| 242 |
+
|
| 243 |
+
// Expected compose file with static suffix `testhash`
|
| 244 |
+
const expectedComposeFile6 = `
|
| 245 |
+
version: "3.8"
|
| 246 |
+
|
| 247 |
+
services:
|
| 248 |
+
web:
|
| 249 |
+
image: nginx:latest
|
| 250 |
+
networks:
|
| 251 |
+
- frontend-testhash
|
| 252 |
+
|
| 253 |
+
networks:
|
| 254 |
+
frontend-testhash:
|
| 255 |
+
driver: bridge
|
| 256 |
+
driver_opts:
|
| 257 |
+
com.docker.network.driver.mtu: 1200
|
| 258 |
+
|
| 259 |
+
backend-testhash:
|
| 260 |
+
driver: bridge
|
| 261 |
+
attachable: true
|
| 262 |
+
|
| 263 |
+
external_network-testhash:
|
| 264 |
+
external: true
|
| 265 |
+
`;
|
| 266 |
+
|
| 267 |
+
test("Add suffix to networks with static suffix", () => {
|
| 268 |
+
const composeData = load(composeFile6) as ComposeSpecification;
|
| 269 |
+
|
| 270 |
+
const suffix = "testhash";
|
| 271 |
+
|
| 272 |
+
if (!composeData?.networks) {
|
| 273 |
+
return;
|
| 274 |
+
}
|
| 275 |
+
const networks = addSuffixToNetworksRoot(composeData.networks, suffix);
|
| 276 |
+
|
| 277 |
+
const expectedComposeData = load(
|
| 278 |
+
expectedComposeFile6,
|
| 279 |
+
) as ComposeSpecification;
|
| 280 |
+
expect(networks).toStrictEqual(expectedComposeData.networks);
|
| 281 |
+
});
|
| 282 |
+
|
| 283 |
+
const composeFile7 = `
|
| 284 |
+
version: "3.8"
|
| 285 |
+
|
| 286 |
+
services:
|
| 287 |
+
web:
|
| 288 |
+
image: nginx:latest
|
| 289 |
+
networks:
|
| 290 |
+
- dokploy-network
|
| 291 |
+
|
| 292 |
+
networks:
|
| 293 |
+
dokploy-network:
|
| 294 |
+
`;
|
| 295 |
+
|
| 296 |
+
test("It shoudn't add suffix to dokploy-network", () => {
|
| 297 |
+
const composeData = load(composeFile7) as ComposeSpecification;
|
| 298 |
+
|
| 299 |
+
const suffix = generateRandomHash();
|
| 300 |
+
|
| 301 |
+
if (!composeData?.networks) {
|
| 302 |
+
return;
|
| 303 |
+
}
|
| 304 |
+
const networks = addSuffixToNetworksRoot(composeData.networks, suffix);
|
| 305 |
+
|
| 306 |
+
expect(networks).toBeDefined();
|
| 307 |
+
for (const networkKey of Object.keys(networks)) {
|
| 308 |
+
expect(networkKey).toContain("dokploy-network");
|
| 309 |
+
}
|
| 310 |
+
});
|
data/apps/dokploy/__test__/compose/network/network-service.test.ts
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { generateRandomHash } from "@dokploy/server";
|
| 2 |
+
import { addSuffixToServiceNetworks } from "@dokploy/server";
|
| 3 |
+
import type { ComposeSpecification } from "@dokploy/server";
|
| 4 |
+
import { load } from "js-yaml";
|
| 5 |
+
import { expect, test } from "vitest";
|
| 6 |
+
|
| 7 |
+
const composeFile = `
|
| 8 |
+
version: "3.8"
|
| 9 |
+
|
| 10 |
+
services:
|
| 11 |
+
web:
|
| 12 |
+
image: nginx:latest
|
| 13 |
+
networks:
|
| 14 |
+
- frontend
|
| 15 |
+
- backend
|
| 16 |
+
|
| 17 |
+
api:
|
| 18 |
+
image: myapi:latest
|
| 19 |
+
networks:
|
| 20 |
+
- backend
|
| 21 |
+
`;
|
| 22 |
+
|
| 23 |
+
test("Add suffix to networks in services", () => {
|
| 24 |
+
const composeData = load(composeFile) as ComposeSpecification;
|
| 25 |
+
|
| 26 |
+
const suffix = generateRandomHash();
|
| 27 |
+
|
| 28 |
+
if (!composeData?.services) {
|
| 29 |
+
return;
|
| 30 |
+
}
|
| 31 |
+
const services = addSuffixToServiceNetworks(composeData.services, suffix);
|
| 32 |
+
const actualComposeData = { ...composeData, services };
|
| 33 |
+
|
| 34 |
+
expect(actualComposeData?.services?.web?.networks).toContain(
|
| 35 |
+
`frontend-${suffix}`,
|
| 36 |
+
);
|
| 37 |
+
|
| 38 |
+
expect(actualComposeData?.services?.api?.networks).toContain(
|
| 39 |
+
`backend-${suffix}`,
|
| 40 |
+
);
|
| 41 |
+
|
| 42 |
+
const apiNetworks = actualComposeData?.services?.api?.networks;
|
| 43 |
+
|
| 44 |
+
expect(apiNetworks).toBeDefined();
|
| 45 |
+
expect(actualComposeData?.services?.api?.networks).toContain(
|
| 46 |
+
`backend-${suffix}`,
|
| 47 |
+
);
|
| 48 |
+
});
|
| 49 |
+
|
| 50 |
+
// Caso 2: Objeto con aliases
|
| 51 |
+
const composeFile2 = `
|
| 52 |
+
version: "3.8"
|
| 53 |
+
|
| 54 |
+
services:
|
| 55 |
+
api:
|
| 56 |
+
image: myapi:latest
|
| 57 |
+
networks:
|
| 58 |
+
frontend:
|
| 59 |
+
aliases:
|
| 60 |
+
- api
|
| 61 |
+
|
| 62 |
+
networks:
|
| 63 |
+
frontend:
|
| 64 |
+
driver: bridge
|
| 65 |
+
`;
|
| 66 |
+
|
| 67 |
+
test("Add suffix to networks in services with aliases", () => {
|
| 68 |
+
const composeData = load(composeFile2) as ComposeSpecification;
|
| 69 |
+
|
| 70 |
+
const suffix = generateRandomHash();
|
| 71 |
+
|
| 72 |
+
if (!composeData?.services) {
|
| 73 |
+
return;
|
| 74 |
+
}
|
| 75 |
+
const services = addSuffixToServiceNetworks(composeData.services, suffix);
|
| 76 |
+
const actualComposeData = { ...composeData, services };
|
| 77 |
+
|
| 78 |
+
expect(actualComposeData.services?.api?.networks).toHaveProperty(
|
| 79 |
+
`frontend-${suffix}`,
|
| 80 |
+
);
|
| 81 |
+
|
| 82 |
+
const networkConfig = actualComposeData?.services?.api?.networks as {
|
| 83 |
+
[key: string]: { aliases?: string[] };
|
| 84 |
+
};
|
| 85 |
+
expect(networkConfig[`frontend-${suffix}`]).toBeDefined();
|
| 86 |
+
expect(networkConfig[`frontend-${suffix}`]?.aliases).toContain("api");
|
| 87 |
+
|
| 88 |
+
expect(actualComposeData.services?.api?.networks).not.toHaveProperty(
|
| 89 |
+
"frontend-ash",
|
| 90 |
+
);
|
| 91 |
+
});
|
| 92 |
+
|
| 93 |
+
const composeFile3 = `
|
| 94 |
+
version: "3.8"
|
| 95 |
+
|
| 96 |
+
services:
|
| 97 |
+
redis:
|
| 98 |
+
image: redis:alpine
|
| 99 |
+
networks:
|
| 100 |
+
backend:
|
| 101 |
+
|
| 102 |
+
networks:
|
| 103 |
+
backend:
|
| 104 |
+
driver: bridge
|
| 105 |
+
`;
|
| 106 |
+
|
| 107 |
+
test("Add suffix to networks in services (Object with simple networks)", () => {
|
| 108 |
+
const composeData = load(composeFile3) as ComposeSpecification;
|
| 109 |
+
|
| 110 |
+
const suffix = generateRandomHash();
|
| 111 |
+
|
| 112 |
+
if (!composeData?.services) {
|
| 113 |
+
return;
|
| 114 |
+
}
|
| 115 |
+
const services = addSuffixToServiceNetworks(composeData.services, suffix);
|
| 116 |
+
const actualComposeData = { ...composeData, services };
|
| 117 |
+
|
| 118 |
+
expect(actualComposeData.services?.redis?.networks).toHaveProperty(
|
| 119 |
+
`backend-${suffix}`,
|
| 120 |
+
);
|
| 121 |
+
});
|
| 122 |
+
|
| 123 |
+
const composeFileCombined = `
|
| 124 |
+
version: "3.8"
|
| 125 |
+
|
| 126 |
+
services:
|
| 127 |
+
web:
|
| 128 |
+
image: nginx:latest
|
| 129 |
+
networks:
|
| 130 |
+
- frontend
|
| 131 |
+
- backend
|
| 132 |
+
|
| 133 |
+
api:
|
| 134 |
+
image: myapi:latest
|
| 135 |
+
networks:
|
| 136 |
+
frontend:
|
| 137 |
+
aliases:
|
| 138 |
+
- api
|
| 139 |
+
|
| 140 |
+
redis:
|
| 141 |
+
image: redis:alpine
|
| 142 |
+
networks:
|
| 143 |
+
backend:
|
| 144 |
+
|
| 145 |
+
networks:
|
| 146 |
+
frontend:
|
| 147 |
+
driver: bridge
|
| 148 |
+
|
| 149 |
+
backend:
|
| 150 |
+
driver: bridge
|
| 151 |
+
`;
|
| 152 |
+
|
| 153 |
+
test("Add suffix to networks in services (combined case)", () => {
|
| 154 |
+
const composeData = load(composeFileCombined) as ComposeSpecification;
|
| 155 |
+
|
| 156 |
+
const suffix = generateRandomHash();
|
| 157 |
+
|
| 158 |
+
if (!composeData?.services) {
|
| 159 |
+
return;
|
| 160 |
+
}
|
| 161 |
+
const services = addSuffixToServiceNetworks(composeData.services, suffix);
|
| 162 |
+
const actualComposeData = { ...composeData, services };
|
| 163 |
+
|
| 164 |
+
// Caso 1: ListOfStrings
|
| 165 |
+
expect(actualComposeData.services?.web?.networks).toContain(
|
| 166 |
+
`frontend-${suffix}`,
|
| 167 |
+
);
|
| 168 |
+
expect(actualComposeData.services?.web?.networks).toContain(
|
| 169 |
+
`backend-${suffix}`,
|
| 170 |
+
);
|
| 171 |
+
|
| 172 |
+
// Caso 2: Objeto con aliases
|
| 173 |
+
const apiNetworks = actualComposeData.services?.api?.networks as {
|
| 174 |
+
[key: string]: unknown;
|
| 175 |
+
};
|
| 176 |
+
expect(apiNetworks).toHaveProperty(`frontend-${suffix}`);
|
| 177 |
+
expect(apiNetworks[`frontend-${suffix}`]).toBeDefined();
|
| 178 |
+
expect(apiNetworks).not.toHaveProperty("frontend");
|
| 179 |
+
|
| 180 |
+
// Caso 3: Objeto con redes simples
|
| 181 |
+
const redisNetworks = actualComposeData.services?.redis?.networks;
|
| 182 |
+
expect(redisNetworks).toHaveProperty(`backend-${suffix}`);
|
| 183 |
+
expect(redisNetworks).not.toHaveProperty("backend");
|
| 184 |
+
});
|
| 185 |
+
|
| 186 |
+
const composeFile7 = `
|
| 187 |
+
version: "3.8"
|
| 188 |
+
|
| 189 |
+
services:
|
| 190 |
+
web:
|
| 191 |
+
image: nginx:latest
|
| 192 |
+
networks:
|
| 193 |
+
- dokploy-network
|
| 194 |
+
`;
|
| 195 |
+
|
| 196 |
+
test("It shoudn't add suffix to dokploy-network in services", () => {
|
| 197 |
+
const composeData = load(composeFile7) as ComposeSpecification;
|
| 198 |
+
|
| 199 |
+
const suffix = generateRandomHash();
|
| 200 |
+
|
| 201 |
+
if (!composeData?.services) {
|
| 202 |
+
return;
|
| 203 |
+
}
|
| 204 |
+
const networks = addSuffixToServiceNetworks(composeData.services, suffix);
|
| 205 |
+
const service = networks.web;
|
| 206 |
+
|
| 207 |
+
expect(service).toBeDefined();
|
| 208 |
+
expect(service?.networks).toContain("dokploy-network");
|
| 209 |
+
});
|
| 210 |
+
|
| 211 |
+
const composeFile8 = `
|
| 212 |
+
version: "3.8"
|
| 213 |
+
|
| 214 |
+
services:
|
| 215 |
+
web:
|
| 216 |
+
image: nginx:latest
|
| 217 |
+
networks:
|
| 218 |
+
- frontend
|
| 219 |
+
- backend
|
| 220 |
+
- dokploy-network
|
| 221 |
+
|
| 222 |
+
|
| 223 |
+
api:
|
| 224 |
+
image: myapi:latest
|
| 225 |
+
networks:
|
| 226 |
+
frontend:
|
| 227 |
+
aliases:
|
| 228 |
+
- api
|
| 229 |
+
dokploy-network:
|
| 230 |
+
aliases:
|
| 231 |
+
- api
|
| 232 |
+
redis:
|
| 233 |
+
image: redis:alpine
|
| 234 |
+
networks:
|
| 235 |
+
dokploy-network:
|
| 236 |
+
db:
|
| 237 |
+
image: myapi:latest
|
| 238 |
+
networks:
|
| 239 |
+
dokploy-network:
|
| 240 |
+
aliases:
|
| 241 |
+
- apid
|
| 242 |
+
|
| 243 |
+
`;
|
| 244 |
+
|
| 245 |
+
test("It shoudn't add suffix to dokploy-network in services multiples cases", () => {
|
| 246 |
+
const composeData = load(composeFile8) as ComposeSpecification;
|
| 247 |
+
|
| 248 |
+
const suffix = generateRandomHash();
|
| 249 |
+
|
| 250 |
+
if (!composeData?.services) {
|
| 251 |
+
return;
|
| 252 |
+
}
|
| 253 |
+
const networks = addSuffixToServiceNetworks(composeData.services, suffix);
|
| 254 |
+
const service = networks.web;
|
| 255 |
+
const api = networks.api;
|
| 256 |
+
const redis = networks.redis;
|
| 257 |
+
const db = networks.db;
|
| 258 |
+
|
| 259 |
+
const dbNetworks = db?.networks as {
|
| 260 |
+
[key: string]: unknown;
|
| 261 |
+
};
|
| 262 |
+
|
| 263 |
+
const apiNetworks = api?.networks as {
|
| 264 |
+
[key: string]: unknown;
|
| 265 |
+
};
|
| 266 |
+
|
| 267 |
+
expect(service).toBeDefined();
|
| 268 |
+
expect(service?.networks).toContain("dokploy-network");
|
| 269 |
+
|
| 270 |
+
expect(redis?.networks).toHaveProperty("dokploy-network");
|
| 271 |
+
expect(dbNetworks["dokploy-network"]).toBeDefined();
|
| 272 |
+
expect(apiNetworks["dokploy-network"]).toBeDefined();
|
| 273 |
+
});
|
data/apps/dokploy/__test__/compose/network/network.test.ts
ADDED
|
@@ -0,0 +1,334 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { generateRandomHash } from "@dokploy/server";
|
| 2 |
+
import {
|
| 3 |
+
addSuffixToAllNetworks,
|
| 4 |
+
addSuffixToServiceNetworks,
|
| 5 |
+
} from "@dokploy/server";
|
| 6 |
+
import { addSuffixToNetworksRoot } from "@dokploy/server";
|
| 7 |
+
import type { ComposeSpecification } from "@dokploy/server";
|
| 8 |
+
import { load } from "js-yaml";
|
| 9 |
+
import { expect, test } from "vitest";
|
| 10 |
+
|
| 11 |
+
const composeFileCombined = `
|
| 12 |
+
version: "3.8"
|
| 13 |
+
|
| 14 |
+
services:
|
| 15 |
+
web:
|
| 16 |
+
image: nginx:latest
|
| 17 |
+
networks:
|
| 18 |
+
- frontend
|
| 19 |
+
- backend
|
| 20 |
+
|
| 21 |
+
api:
|
| 22 |
+
image: myapi:latest
|
| 23 |
+
networks:
|
| 24 |
+
frontend:
|
| 25 |
+
aliases:
|
| 26 |
+
- api
|
| 27 |
+
|
| 28 |
+
redis:
|
| 29 |
+
image: redis:alpine
|
| 30 |
+
networks:
|
| 31 |
+
backend:
|
| 32 |
+
|
| 33 |
+
networks:
|
| 34 |
+
frontend:
|
| 35 |
+
driver: bridge
|
| 36 |
+
|
| 37 |
+
backend:
|
| 38 |
+
driver: bridge
|
| 39 |
+
`;
|
| 40 |
+
|
| 41 |
+
test("Add suffix to networks in services and root (combined case)", () => {
|
| 42 |
+
const composeData = load(composeFileCombined) as ComposeSpecification;
|
| 43 |
+
|
| 44 |
+
const suffix = generateRandomHash();
|
| 45 |
+
|
| 46 |
+
// Prefijo para redes definidas en el root
|
| 47 |
+
if (composeData.networks) {
|
| 48 |
+
composeData.networks = addSuffixToNetworksRoot(
|
| 49 |
+
composeData.networks,
|
| 50 |
+
suffix,
|
| 51 |
+
);
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
// Prefijo para redes definidas en los servicios
|
| 55 |
+
if (composeData.services) {
|
| 56 |
+
composeData.services = addSuffixToServiceNetworks(
|
| 57 |
+
composeData.services,
|
| 58 |
+
suffix,
|
| 59 |
+
);
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
const actualComposeData = { ...composeData };
|
| 63 |
+
|
| 64 |
+
// Verificar redes en root
|
| 65 |
+
expect(actualComposeData.networks).toHaveProperty(`frontend-${suffix}`);
|
| 66 |
+
expect(actualComposeData.networks).toHaveProperty(`backend-${suffix}`);
|
| 67 |
+
expect(actualComposeData.networks).not.toHaveProperty("frontend");
|
| 68 |
+
expect(actualComposeData.networks).not.toHaveProperty("backend");
|
| 69 |
+
|
| 70 |
+
// Caso 1: ListOfStrings
|
| 71 |
+
expect(actualComposeData.services?.web?.networks).toContain(
|
| 72 |
+
`frontend-${suffix}`,
|
| 73 |
+
);
|
| 74 |
+
expect(actualComposeData.services?.web?.networks).toContain(
|
| 75 |
+
`backend-${suffix}`,
|
| 76 |
+
);
|
| 77 |
+
|
| 78 |
+
// Caso 2: Objeto con aliases
|
| 79 |
+
const apiNetworks = actualComposeData.services?.api?.networks as {
|
| 80 |
+
[key: string]: { aliases?: string[] };
|
| 81 |
+
};
|
| 82 |
+
expect(apiNetworks).toHaveProperty(`frontend-${suffix}`);
|
| 83 |
+
expect(apiNetworks?.[`frontend-${suffix}`]?.aliases).toContain("api");
|
| 84 |
+
expect(apiNetworks).not.toHaveProperty("frontend");
|
| 85 |
+
|
| 86 |
+
// Caso 3: Objeto con redes simples
|
| 87 |
+
const redisNetworks = actualComposeData.services?.redis?.networks;
|
| 88 |
+
expect(redisNetworks).toHaveProperty(`backend-${suffix}`);
|
| 89 |
+
expect(redisNetworks).not.toHaveProperty("backend");
|
| 90 |
+
});
|
| 91 |
+
|
| 92 |
+
const expectedComposeFile = load(`
|
| 93 |
+
version: "3.8"
|
| 94 |
+
|
| 95 |
+
services:
|
| 96 |
+
web:
|
| 97 |
+
image: nginx:latest
|
| 98 |
+
networks:
|
| 99 |
+
- frontend-testhash
|
| 100 |
+
- backend-testhash
|
| 101 |
+
|
| 102 |
+
api:
|
| 103 |
+
image: myapi:latest
|
| 104 |
+
networks:
|
| 105 |
+
frontend-testhash:
|
| 106 |
+
aliases:
|
| 107 |
+
- api
|
| 108 |
+
|
| 109 |
+
redis:
|
| 110 |
+
image: redis:alpine
|
| 111 |
+
networks:
|
| 112 |
+
backend-testhash:
|
| 113 |
+
|
| 114 |
+
networks:
|
| 115 |
+
frontend-testhash:
|
| 116 |
+
driver: bridge
|
| 117 |
+
|
| 118 |
+
backend-testhash:
|
| 119 |
+
driver: bridge
|
| 120 |
+
`);
|
| 121 |
+
|
| 122 |
+
test("Add suffix to networks in compose file", () => {
|
| 123 |
+
const composeData = load(composeFileCombined) as ComposeSpecification;
|
| 124 |
+
|
| 125 |
+
const suffix = "testhash";
|
| 126 |
+
if (!composeData?.networks) {
|
| 127 |
+
return;
|
| 128 |
+
}
|
| 129 |
+
const updatedComposeData = addSuffixToAllNetworks(composeData, suffix);
|
| 130 |
+
|
| 131 |
+
expect(updatedComposeData).toEqual(expectedComposeFile);
|
| 132 |
+
});
|
| 133 |
+
|
| 134 |
+
const composeFile2 = `
|
| 135 |
+
version: "3.8"
|
| 136 |
+
|
| 137 |
+
services:
|
| 138 |
+
web:
|
| 139 |
+
image: nginx:latest
|
| 140 |
+
networks:
|
| 141 |
+
- frontend
|
| 142 |
+
- backend
|
| 143 |
+
|
| 144 |
+
db:
|
| 145 |
+
image: postgres:latest
|
| 146 |
+
networks:
|
| 147 |
+
backend:
|
| 148 |
+
aliases:
|
| 149 |
+
- db
|
| 150 |
+
|
| 151 |
+
networks:
|
| 152 |
+
frontend:
|
| 153 |
+
external: true
|
| 154 |
+
|
| 155 |
+
backend:
|
| 156 |
+
driver: bridge
|
| 157 |
+
`;
|
| 158 |
+
|
| 159 |
+
const expectedComposeFile2 = load(`
|
| 160 |
+
version: "3.8"
|
| 161 |
+
|
| 162 |
+
services:
|
| 163 |
+
web:
|
| 164 |
+
image: nginx:latest
|
| 165 |
+
networks:
|
| 166 |
+
- frontend-testhash
|
| 167 |
+
- backend-testhash
|
| 168 |
+
|
| 169 |
+
db:
|
| 170 |
+
image: postgres:latest
|
| 171 |
+
networks:
|
| 172 |
+
backend-testhash:
|
| 173 |
+
aliases:
|
| 174 |
+
- db
|
| 175 |
+
|
| 176 |
+
networks:
|
| 177 |
+
frontend-testhash:
|
| 178 |
+
external: true
|
| 179 |
+
|
| 180 |
+
backend-testhash:
|
| 181 |
+
driver: bridge
|
| 182 |
+
`);
|
| 183 |
+
|
| 184 |
+
test("Add suffix to networks in compose file with external and internal networks", () => {
|
| 185 |
+
const composeData = load(composeFile2) as ComposeSpecification;
|
| 186 |
+
|
| 187 |
+
const suffix = "testhash";
|
| 188 |
+
const updatedComposeData = addSuffixToAllNetworks(composeData, suffix);
|
| 189 |
+
|
| 190 |
+
expect(updatedComposeData).toEqual(expectedComposeFile2);
|
| 191 |
+
});
|
| 192 |
+
|
| 193 |
+
const composeFile3 = `
|
| 194 |
+
version: "3.8"
|
| 195 |
+
|
| 196 |
+
services:
|
| 197 |
+
app:
|
| 198 |
+
image: myapp:latest
|
| 199 |
+
networks:
|
| 200 |
+
frontend:
|
| 201 |
+
aliases:
|
| 202 |
+
- app
|
| 203 |
+
backend:
|
| 204 |
+
|
| 205 |
+
worker:
|
| 206 |
+
image: worker:latest
|
| 207 |
+
networks:
|
| 208 |
+
- backend
|
| 209 |
+
|
| 210 |
+
networks:
|
| 211 |
+
frontend:
|
| 212 |
+
driver: bridge
|
| 213 |
+
attachable: true
|
| 214 |
+
|
| 215 |
+
backend:
|
| 216 |
+
driver: bridge
|
| 217 |
+
driver_opts:
|
| 218 |
+
com.docker.network.bridge.enable_icc: "true"
|
| 219 |
+
`;
|
| 220 |
+
|
| 221 |
+
const expectedComposeFile3 = load(`
|
| 222 |
+
version: "3.8"
|
| 223 |
+
|
| 224 |
+
services:
|
| 225 |
+
app:
|
| 226 |
+
image: myapp:latest
|
| 227 |
+
networks:
|
| 228 |
+
frontend-testhash:
|
| 229 |
+
aliases:
|
| 230 |
+
- app
|
| 231 |
+
backend-testhash:
|
| 232 |
+
|
| 233 |
+
worker:
|
| 234 |
+
image: worker:latest
|
| 235 |
+
networks:
|
| 236 |
+
- backend-testhash
|
| 237 |
+
|
| 238 |
+
networks:
|
| 239 |
+
frontend-testhash:
|
| 240 |
+
driver: bridge
|
| 241 |
+
attachable: true
|
| 242 |
+
|
| 243 |
+
backend-testhash:
|
| 244 |
+
driver: bridge
|
| 245 |
+
driver_opts:
|
| 246 |
+
com.docker.network.bridge.enable_icc: "true"
|
| 247 |
+
`);
|
| 248 |
+
|
| 249 |
+
test("Add suffix to networks in compose file with multiple services and complex network configurations", () => {
|
| 250 |
+
const composeData = load(composeFile3) as ComposeSpecification;
|
| 251 |
+
|
| 252 |
+
const suffix = "testhash";
|
| 253 |
+
const updatedComposeData = addSuffixToAllNetworks(composeData, suffix);
|
| 254 |
+
|
| 255 |
+
expect(updatedComposeData).toEqual(expectedComposeFile3);
|
| 256 |
+
});
|
| 257 |
+
|
| 258 |
+
const composeFile4 = `
|
| 259 |
+
version: "3.8"
|
| 260 |
+
|
| 261 |
+
services:
|
| 262 |
+
app:
|
| 263 |
+
image: myapp:latest
|
| 264 |
+
networks:
|
| 265 |
+
frontend:
|
| 266 |
+
aliases:
|
| 267 |
+
- app
|
| 268 |
+
backend:
|
| 269 |
+
dokploy-network:
|
| 270 |
+
|
| 271 |
+
worker:
|
| 272 |
+
image: worker:latest
|
| 273 |
+
networks:
|
| 274 |
+
- backend
|
| 275 |
+
- dokploy-network
|
| 276 |
+
|
| 277 |
+
networks:
|
| 278 |
+
frontend:
|
| 279 |
+
driver: bridge
|
| 280 |
+
attachable: true
|
| 281 |
+
|
| 282 |
+
backend:
|
| 283 |
+
driver: bridge
|
| 284 |
+
driver_opts:
|
| 285 |
+
com.docker.network.bridge.enable_icc: "true"
|
| 286 |
+
|
| 287 |
+
dokploy-network:
|
| 288 |
+
driver: bridge
|
| 289 |
+
|
| 290 |
+
`;
|
| 291 |
+
|
| 292 |
+
const expectedComposeFile4 = load(`
|
| 293 |
+
version: "3.8"
|
| 294 |
+
|
| 295 |
+
services:
|
| 296 |
+
app:
|
| 297 |
+
image: myapp:latest
|
| 298 |
+
networks:
|
| 299 |
+
frontend-testhash:
|
| 300 |
+
aliases:
|
| 301 |
+
- app
|
| 302 |
+
backend-testhash:
|
| 303 |
+
dokploy-network:
|
| 304 |
+
|
| 305 |
+
worker:
|
| 306 |
+
image: worker:latest
|
| 307 |
+
networks:
|
| 308 |
+
- backend-testhash
|
| 309 |
+
- dokploy-network
|
| 310 |
+
|
| 311 |
+
networks:
|
| 312 |
+
frontend-testhash:
|
| 313 |
+
driver: bridge
|
| 314 |
+
attachable: true
|
| 315 |
+
|
| 316 |
+
backend-testhash:
|
| 317 |
+
driver: bridge
|
| 318 |
+
driver_opts:
|
| 319 |
+
com.docker.network.bridge.enable_icc: "true"
|
| 320 |
+
|
| 321 |
+
dokploy-network:
|
| 322 |
+
driver: bridge
|
| 323 |
+
|
| 324 |
+
|
| 325 |
+
|
| 326 |
+
`);
|
| 327 |
+
|
| 328 |
+
test("Expect don't add suffix to dokploy-network in compose file with multiple services and complex network configurations", () => {
|
| 329 |
+
const composeData = load(composeFile4) as ComposeSpecification;
|
| 330 |
+
|
| 331 |
+
const suffix = "testhash";
|
| 332 |
+
const updatedComposeData = addSuffixToAllNetworks(composeData, suffix);
|
| 333 |
+
expect(updatedComposeData).toEqual(expectedComposeFile4);
|
| 334 |
+
});
|
data/apps/dokploy/__test__/compose/secrets/secret-root.test.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { generateRandomHash } from "@dokploy/server";
|
| 2 |
+
import { addSuffixToSecretsRoot } from "@dokploy/server";
|
| 3 |
+
import type { ComposeSpecification } from "@dokploy/server";
|
| 4 |
+
import { load } from "js-yaml";
|
| 5 |
+
import { expect, test } from "vitest";
|
| 6 |
+
|
| 7 |
+
test("Generate random hash with 8 characters", () => {
|
| 8 |
+
const hash = generateRandomHash();
|
| 9 |
+
|
| 10 |
+
expect(hash).toBeDefined();
|
| 11 |
+
expect(hash.length).toBe(8);
|
| 12 |
+
});
|
| 13 |
+
|
| 14 |
+
const composeFileSecretsRoot = `
|
| 15 |
+
version: "3.8"
|
| 16 |
+
|
| 17 |
+
services:
|
| 18 |
+
web:
|
| 19 |
+
image: nginx:latest
|
| 20 |
+
|
| 21 |
+
secrets:
|
| 22 |
+
db_password:
|
| 23 |
+
file: ./db_password.txt
|
| 24 |
+
`;
|
| 25 |
+
|
| 26 |
+
test("Add suffix to secrets in root property", () => {
|
| 27 |
+
const composeData = load(composeFileSecretsRoot) as ComposeSpecification;
|
| 28 |
+
const suffix = generateRandomHash();
|
| 29 |
+
|
| 30 |
+
if (!composeData?.secrets) {
|
| 31 |
+
return;
|
| 32 |
+
}
|
| 33 |
+
const secrets = addSuffixToSecretsRoot(composeData.secrets, suffix);
|
| 34 |
+
expect(secrets).toBeDefined();
|
| 35 |
+
if (secrets) {
|
| 36 |
+
for (const secretKey of Object.keys(secrets)) {
|
| 37 |
+
expect(secretKey).toContain(`-${suffix}`);
|
| 38 |
+
expect(secrets[secretKey]).toBeDefined();
|
| 39 |
+
}
|
| 40 |
+
}
|
| 41 |
+
});
|
| 42 |
+
|
| 43 |
+
const composeFileSecretsRoot1 = `
|
| 44 |
+
version: "3.8"
|
| 45 |
+
|
| 46 |
+
services:
|
| 47 |
+
api:
|
| 48 |
+
image: myapi:latest
|
| 49 |
+
|
| 50 |
+
secrets:
|
| 51 |
+
api_key:
|
| 52 |
+
file: ./api_key.txt
|
| 53 |
+
`;
|
| 54 |
+
|
| 55 |
+
test("Add suffix to secrets in root property (Test 1)", () => {
|
| 56 |
+
const composeData = load(composeFileSecretsRoot1) as ComposeSpecification;
|
| 57 |
+
const suffix = generateRandomHash();
|
| 58 |
+
|
| 59 |
+
if (!composeData?.secrets) {
|
| 60 |
+
return;
|
| 61 |
+
}
|
| 62 |
+
const secrets = addSuffixToSecretsRoot(composeData.secrets, suffix);
|
| 63 |
+
expect(secrets).toBeDefined();
|
| 64 |
+
|
| 65 |
+
if (secrets) {
|
| 66 |
+
for (const secretKey of Object.keys(secrets)) {
|
| 67 |
+
expect(secretKey).toContain(`-${suffix}`);
|
| 68 |
+
expect(secrets[secretKey]).toBeDefined();
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
});
|
| 72 |
+
|
| 73 |
+
const composeFileSecretsRoot2 = `
|
| 74 |
+
version: "3.8"
|
| 75 |
+
|
| 76 |
+
services:
|
| 77 |
+
frontend:
|
| 78 |
+
image: nginx:latest
|
| 79 |
+
|
| 80 |
+
secrets:
|
| 81 |
+
frontend_secret:
|
| 82 |
+
file: ./frontend_secret.txt
|
| 83 |
+
db_password:
|
| 84 |
+
external: true
|
| 85 |
+
`;
|
| 86 |
+
|
| 87 |
+
test("Add suffix to secrets in root property (Test 2)", () => {
|
| 88 |
+
const composeData = load(composeFileSecretsRoot2) as ComposeSpecification;
|
| 89 |
+
const suffix = generateRandomHash();
|
| 90 |
+
|
| 91 |
+
if (!composeData?.secrets) {
|
| 92 |
+
return;
|
| 93 |
+
}
|
| 94 |
+
const secrets = addSuffixToSecretsRoot(composeData.secrets, suffix);
|
| 95 |
+
expect(secrets).toBeDefined();
|
| 96 |
+
|
| 97 |
+
if (secrets) {
|
| 98 |
+
for (const secretKey of Object.keys(secrets)) {
|
| 99 |
+
expect(secretKey).toContain(`-${suffix}`);
|
| 100 |
+
expect(secrets[secretKey]).toBeDefined();
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
});
|
data/apps/dokploy/__test__/compose/secrets/secret-services.test.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { generateRandomHash } from "@dokploy/server";
|
| 2 |
+
import { addSuffixToSecretsInServices } from "@dokploy/server";
|
| 3 |
+
import type { ComposeSpecification } from "@dokploy/server";
|
| 4 |
+
import { load } from "js-yaml";
|
| 5 |
+
import { expect, test } from "vitest";
|
| 6 |
+
|
| 7 |
+
const composeFileSecretsServices = `
|
| 8 |
+
version: "3.8"
|
| 9 |
+
|
| 10 |
+
services:
|
| 11 |
+
db:
|
| 12 |
+
image: postgres:latest
|
| 13 |
+
secrets:
|
| 14 |
+
- db_password
|
| 15 |
+
|
| 16 |
+
secrets:
|
| 17 |
+
db_password:
|
| 18 |
+
file: ./db_password.txt
|
| 19 |
+
`;
|
| 20 |
+
|
| 21 |
+
test("Add suffix to secrets in services", () => {
|
| 22 |
+
const composeData = load(composeFileSecretsServices) as ComposeSpecification;
|
| 23 |
+
const suffix = generateRandomHash();
|
| 24 |
+
|
| 25 |
+
if (!composeData.services) {
|
| 26 |
+
return;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
const updatedComposeData = addSuffixToSecretsInServices(
|
| 30 |
+
composeData.services,
|
| 31 |
+
suffix,
|
| 32 |
+
);
|
| 33 |
+
const actualComposeData = { ...composeData, services: updatedComposeData };
|
| 34 |
+
|
| 35 |
+
expect(actualComposeData.services?.db?.secrets).toContain(
|
| 36 |
+
`db_password-${suffix}`,
|
| 37 |
+
);
|
| 38 |
+
});
|
| 39 |
+
|
| 40 |
+
const composeFileSecretsServices1 = `
|
| 41 |
+
version: "3.8"
|
| 42 |
+
|
| 43 |
+
services:
|
| 44 |
+
app:
|
| 45 |
+
image: node:14
|
| 46 |
+
secrets:
|
| 47 |
+
- app_secret
|
| 48 |
+
|
| 49 |
+
secrets:
|
| 50 |
+
app_secret:
|
| 51 |
+
file: ./app_secret.txt
|
| 52 |
+
`;
|
| 53 |
+
|
| 54 |
+
test("Add suffix to secrets in services (Test 1)", () => {
|
| 55 |
+
const composeData = load(composeFileSecretsServices1) as ComposeSpecification;
|
| 56 |
+
const suffix = generateRandomHash();
|
| 57 |
+
|
| 58 |
+
if (!composeData.services) {
|
| 59 |
+
return;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
const updatedComposeData = addSuffixToSecretsInServices(
|
| 63 |
+
composeData.services,
|
| 64 |
+
suffix,
|
| 65 |
+
);
|
| 66 |
+
const actualComposeData = { ...composeData, services: updatedComposeData };
|
| 67 |
+
|
| 68 |
+
expect(actualComposeData.services?.app?.secrets).toContain(
|
| 69 |
+
`app_secret-${suffix}`,
|
| 70 |
+
);
|
| 71 |
+
});
|
| 72 |
+
|
| 73 |
+
const composeFileSecretsServices2 = `
|
| 74 |
+
version: "3.8"
|
| 75 |
+
|
| 76 |
+
services:
|
| 77 |
+
backend:
|
| 78 |
+
image: backend:latest
|
| 79 |
+
secrets:
|
| 80 |
+
- backend_secret
|
| 81 |
+
frontend:
|
| 82 |
+
image: frontend:latest
|
| 83 |
+
secrets:
|
| 84 |
+
- frontend_secret
|
| 85 |
+
|
| 86 |
+
secrets:
|
| 87 |
+
backend_secret:
|
| 88 |
+
file: ./backend_secret.txt
|
| 89 |
+
frontend_secret:
|
| 90 |
+
file: ./frontend_secret.txt
|
| 91 |
+
`;
|
| 92 |
+
|
| 93 |
+
test("Add suffix to secrets in services (Test 2)", () => {
|
| 94 |
+
const composeData = load(composeFileSecretsServices2) as ComposeSpecification;
|
| 95 |
+
const suffix = generateRandomHash();
|
| 96 |
+
|
| 97 |
+
if (!composeData.services) {
|
| 98 |
+
return;
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
const updatedComposeData = addSuffixToSecretsInServices(
|
| 102 |
+
composeData.services,
|
| 103 |
+
suffix,
|
| 104 |
+
);
|
| 105 |
+
const actualComposeData = { ...composeData, services: updatedComposeData };
|
| 106 |
+
|
| 107 |
+
expect(actualComposeData.services?.backend?.secrets).toContain(
|
| 108 |
+
`backend_secret-${suffix}`,
|
| 109 |
+
);
|
| 110 |
+
expect(actualComposeData.services?.frontend?.secrets).toContain(
|
| 111 |
+
`frontend_secret-${suffix}`,
|
| 112 |
+
);
|
| 113 |
+
});
|
data/apps/dokploy/__test__/compose/secrets/secret.test.ts
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { addSuffixToAllSecrets } from "@dokploy/server";
|
| 2 |
+
import type { ComposeSpecification } from "@dokploy/server";
|
| 3 |
+
import { load } from "js-yaml";
|
| 4 |
+
import { expect, test } from "vitest";
|
| 5 |
+
|
| 6 |
+
const composeFileCombinedSecrets = `
|
| 7 |
+
version: "3.8"
|
| 8 |
+
|
| 9 |
+
services:
|
| 10 |
+
web:
|
| 11 |
+
image: nginx:latest
|
| 12 |
+
secrets:
|
| 13 |
+
- web_secret
|
| 14 |
+
|
| 15 |
+
app:
|
| 16 |
+
image: node:14
|
| 17 |
+
secrets:
|
| 18 |
+
- app_secret
|
| 19 |
+
|
| 20 |
+
secrets:
|
| 21 |
+
web_secret:
|
| 22 |
+
file: ./web_secret.txt
|
| 23 |
+
|
| 24 |
+
app_secret:
|
| 25 |
+
file: ./app_secret.txt
|
| 26 |
+
`;
|
| 27 |
+
|
| 28 |
+
const expectedComposeFileCombinedSecrets = load(`
|
| 29 |
+
version: "3.8"
|
| 30 |
+
|
| 31 |
+
services:
|
| 32 |
+
web:
|
| 33 |
+
image: nginx:latest
|
| 34 |
+
secrets:
|
| 35 |
+
- web_secret-testhash
|
| 36 |
+
|
| 37 |
+
app:
|
| 38 |
+
image: node:14
|
| 39 |
+
secrets:
|
| 40 |
+
- app_secret-testhash
|
| 41 |
+
|
| 42 |
+
secrets:
|
| 43 |
+
web_secret-testhash:
|
| 44 |
+
file: ./web_secret.txt
|
| 45 |
+
|
| 46 |
+
app_secret-testhash:
|
| 47 |
+
file: ./app_secret.txt
|
| 48 |
+
`) as ComposeSpecification;
|
| 49 |
+
|
| 50 |
+
test("Add suffix to all secrets", () => {
|
| 51 |
+
const composeData = load(composeFileCombinedSecrets) as ComposeSpecification;
|
| 52 |
+
const suffix = "testhash";
|
| 53 |
+
|
| 54 |
+
const updatedComposeData = addSuffixToAllSecrets(composeData, suffix);
|
| 55 |
+
|
| 56 |
+
expect(updatedComposeData).toEqual(expectedComposeFileCombinedSecrets);
|
| 57 |
+
});
|
| 58 |
+
|
| 59 |
+
const composeFileCombinedSecrets3 = `
|
| 60 |
+
version: "3.8"
|
| 61 |
+
|
| 62 |
+
services:
|
| 63 |
+
api:
|
| 64 |
+
image: myapi:latest
|
| 65 |
+
secrets:
|
| 66 |
+
- api_key
|
| 67 |
+
|
| 68 |
+
cache:
|
| 69 |
+
image: redis:latest
|
| 70 |
+
secrets:
|
| 71 |
+
- cache_secret
|
| 72 |
+
|
| 73 |
+
secrets:
|
| 74 |
+
api_key:
|
| 75 |
+
file: ./api_key.txt
|
| 76 |
+
cache_secret:
|
| 77 |
+
file: ./cache_secret.txt
|
| 78 |
+
`;
|
| 79 |
+
|
| 80 |
+
const expectedComposeFileCombinedSecrets3 = load(`
|
| 81 |
+
version: "3.8"
|
| 82 |
+
|
| 83 |
+
services:
|
| 84 |
+
api:
|
| 85 |
+
image: myapi:latest
|
| 86 |
+
secrets:
|
| 87 |
+
- api_key-testhash
|
| 88 |
+
|
| 89 |
+
cache:
|
| 90 |
+
image: redis:latest
|
| 91 |
+
secrets:
|
| 92 |
+
- cache_secret-testhash
|
| 93 |
+
|
| 94 |
+
secrets:
|
| 95 |
+
api_key-testhash:
|
| 96 |
+
file: ./api_key.txt
|
| 97 |
+
cache_secret-testhash:
|
| 98 |
+
file: ./cache_secret.txt
|
| 99 |
+
`) as ComposeSpecification;
|
| 100 |
+
|
| 101 |
+
test("Add suffix to all secrets (3rd Case)", () => {
|
| 102 |
+
const composeData = load(composeFileCombinedSecrets3) as ComposeSpecification;
|
| 103 |
+
const suffix = "testhash";
|
| 104 |
+
|
| 105 |
+
const updatedComposeData = addSuffixToAllSecrets(composeData, suffix);
|
| 106 |
+
|
| 107 |
+
expect(updatedComposeData).toEqual(expectedComposeFileCombinedSecrets3);
|
| 108 |
+
});
|
| 109 |
+
|
| 110 |
+
const composeFileCombinedSecrets4 = `
|
| 111 |
+
version: "3.8"
|
| 112 |
+
|
| 113 |
+
services:
|
| 114 |
+
web:
|
| 115 |
+
image: nginx:latest
|
| 116 |
+
secrets:
|
| 117 |
+
- web_secret
|
| 118 |
+
|
| 119 |
+
db:
|
| 120 |
+
image: postgres:latest
|
| 121 |
+
secrets:
|
| 122 |
+
- db_password
|
| 123 |
+
|
| 124 |
+
secrets:
|
| 125 |
+
web_secret:
|
| 126 |
+
file: ./web_secret.txt
|
| 127 |
+
db_password:
|
| 128 |
+
file: ./db_password.txt
|
| 129 |
+
`;
|
| 130 |
+
|
| 131 |
+
const expectedComposeFileCombinedSecrets4 = load(`
|
| 132 |
+
version: "3.8"
|
| 133 |
+
|
| 134 |
+
services:
|
| 135 |
+
web:
|
| 136 |
+
image: nginx:latest
|
| 137 |
+
secrets:
|
| 138 |
+
- web_secret-testhash
|
| 139 |
+
|
| 140 |
+
db:
|
| 141 |
+
image: postgres:latest
|
| 142 |
+
secrets:
|
| 143 |
+
- db_password-testhash
|
| 144 |
+
|
| 145 |
+
secrets:
|
| 146 |
+
web_secret-testhash:
|
| 147 |
+
file: ./web_secret.txt
|
| 148 |
+
db_password-testhash:
|
| 149 |
+
file: ./db_password.txt
|
| 150 |
+
`) as ComposeSpecification;
|
| 151 |
+
|
| 152 |
+
test("Add suffix to all secrets (4th Case)", () => {
|
| 153 |
+
const composeData = load(composeFileCombinedSecrets4) as ComposeSpecification;
|
| 154 |
+
const suffix = "testhash";
|
| 155 |
+
|
| 156 |
+
const updatedComposeData = addSuffixToAllSecrets(composeData, suffix);
|
| 157 |
+
|
| 158 |
+
expect(updatedComposeData).toEqual(expectedComposeFileCombinedSecrets4);
|
| 159 |
+
});
|
data/apps/dokploy/__test__/compose/service/service-container-name.test.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { generateRandomHash } from "@dokploy/server";
|
| 2 |
+
import { addSuffixToServiceNames } from "@dokploy/server";
|
| 3 |
+
import type { ComposeSpecification } from "@dokploy/server";
|
| 4 |
+
import { load } from "js-yaml";
|
| 5 |
+
import { expect, test } from "vitest";
|
| 6 |
+
|
| 7 |
+
const composeFile = `
|
| 8 |
+
version: "3.8"
|
| 9 |
+
|
| 10 |
+
services:
|
| 11 |
+
web:
|
| 12 |
+
image: nginx:latest
|
| 13 |
+
container_name: web_container
|
| 14 |
+
|
| 15 |
+
api:
|
| 16 |
+
image: myapi:latest
|
| 17 |
+
|
| 18 |
+
networks:
|
| 19 |
+
default:
|
| 20 |
+
driver: bridge
|
| 21 |
+
`;
|
| 22 |
+
|
| 23 |
+
test("Generate random hash with 8 characters", () => {
|
| 24 |
+
const hash = generateRandomHash();
|
| 25 |
+
|
| 26 |
+
expect(hash).toBeDefined();
|
| 27 |
+
expect(hash.length).toBe(8);
|
| 28 |
+
});
|
| 29 |
+
|
| 30 |
+
test("Add suffix to service names with container_name in compose file", () => {
|
| 31 |
+
const composeData = load(composeFile) as ComposeSpecification;
|
| 32 |
+
|
| 33 |
+
const suffix = generateRandomHash();
|
| 34 |
+
|
| 35 |
+
if (!composeData.services) {
|
| 36 |
+
return;
|
| 37 |
+
}
|
| 38 |
+
const updatedComposeData = addSuffixToServiceNames(
|
| 39 |
+
composeData.services,
|
| 40 |
+
suffix,
|
| 41 |
+
);
|
| 42 |
+
const actualComposeData = { ...composeData, services: updatedComposeData };
|
| 43 |
+
|
| 44 |
+
// Verificar que el nombre del contenedor ha cambiado correctamente
|
| 45 |
+
expect(actualComposeData.services?.[`web-${suffix}`]?.container_name).toBe(
|
| 46 |
+
`web_container-${suffix}`,
|
| 47 |
+
);
|
| 48 |
+
// Verificar que la nueva clave del servicio tiene el prefijo y la vieja clave no existe
|
| 49 |
+
expect(actualComposeData.services).toHaveProperty(`web-${suffix}`);
|
| 50 |
+
expect(actualComposeData.services).not.toHaveProperty("web");
|
| 51 |
+
|
| 52 |
+
// Verificar que la configuración de la imagen sigue igual
|
| 53 |
+
expect(actualComposeData.services?.[`web-${suffix}`]?.image).toBe(
|
| 54 |
+
"nginx:latest",
|
| 55 |
+
);
|
| 56 |
+
expect(actualComposeData.services?.[`api-${suffix}`]?.image).toBe(
|
| 57 |
+
"myapi:latest",
|
| 58 |
+
);
|
| 59 |
+
});
|
data/apps/dokploy/__test__/compose/service/service-depends-on.test.ts
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { generateRandomHash } from "@dokploy/server";
|
| 2 |
+
import { addSuffixToServiceNames } from "@dokploy/server";
|
| 3 |
+
import type { ComposeSpecification } from "@dokploy/server";
|
| 4 |
+
import { load } from "js-yaml";
|
| 5 |
+
import { expect, test } from "vitest";
|
| 6 |
+
|
| 7 |
+
test("Generate random hash with 8 characters", () => {
|
| 8 |
+
const hash = generateRandomHash();
|
| 9 |
+
|
| 10 |
+
expect(hash).toBeDefined();
|
| 11 |
+
expect(hash.length).toBe(8);
|
| 12 |
+
});
|
| 13 |
+
|
| 14 |
+
const composeFile4 = `
|
| 15 |
+
version: "3.8"
|
| 16 |
+
|
| 17 |
+
services:
|
| 18 |
+
web:
|
| 19 |
+
image: nginx:latest
|
| 20 |
+
depends_on:
|
| 21 |
+
- db
|
| 22 |
+
- api
|
| 23 |
+
|
| 24 |
+
api:
|
| 25 |
+
image: myapi:latest
|
| 26 |
+
|
| 27 |
+
db:
|
| 28 |
+
image: postgres:latest
|
| 29 |
+
|
| 30 |
+
networks:
|
| 31 |
+
default:
|
| 32 |
+
driver: bridge
|
| 33 |
+
`;
|
| 34 |
+
|
| 35 |
+
test("Add suffix to service names with depends_on (array) in compose file", () => {
|
| 36 |
+
const composeData = load(composeFile4) as ComposeSpecification;
|
| 37 |
+
|
| 38 |
+
const suffix = generateRandomHash();
|
| 39 |
+
|
| 40 |
+
if (!composeData.services) {
|
| 41 |
+
return;
|
| 42 |
+
}
|
| 43 |
+
const updatedComposeData = addSuffixToServiceNames(
|
| 44 |
+
composeData.services,
|
| 45 |
+
suffix,
|
| 46 |
+
);
|
| 47 |
+
const actualComposeData = { ...composeData, services: updatedComposeData };
|
| 48 |
+
|
| 49 |
+
// Verificar que la nueva clave del servicio tiene el prefijo y la vieja clave no existe
|
| 50 |
+
expect(actualComposeData.services).toHaveProperty(`web-${suffix}`);
|
| 51 |
+
expect(actualComposeData.services).not.toHaveProperty("web");
|
| 52 |
+
|
| 53 |
+
// Verificar que la configuración de la imagen sigue igual
|
| 54 |
+
expect(actualComposeData.services?.[`web-${suffix}`]?.image).toBe(
|
| 55 |
+
"nginx:latest",
|
| 56 |
+
);
|
| 57 |
+
expect(actualComposeData.services?.[`api-${suffix}`]?.image).toBe(
|
| 58 |
+
"myapi:latest",
|
| 59 |
+
);
|
| 60 |
+
|
| 61 |
+
// Verificar que los nombres en depends_on tienen el prefijo
|
| 62 |
+
expect(actualComposeData.services?.[`web-${suffix}`]?.depends_on).toContain(
|
| 63 |
+
`db-${suffix}`,
|
| 64 |
+
);
|
| 65 |
+
expect(actualComposeData.services?.[`web-${suffix}`]?.depends_on).toContain(
|
| 66 |
+
`api-${suffix}`,
|
| 67 |
+
);
|
| 68 |
+
|
| 69 |
+
// Verificar que los servicios `db` y `api` también tienen el prefijo
|
| 70 |
+
expect(actualComposeData.services).toHaveProperty(`db-${suffix}`);
|
| 71 |
+
expect(actualComposeData.services).not.toHaveProperty("db");
|
| 72 |
+
expect(actualComposeData.services?.[`db-${suffix}`]?.image).toBe(
|
| 73 |
+
"postgres:latest",
|
| 74 |
+
);
|
| 75 |
+
expect(actualComposeData.services).toHaveProperty(`api-${suffix}`);
|
| 76 |
+
expect(actualComposeData.services).not.toHaveProperty("api");
|
| 77 |
+
expect(actualComposeData.services?.[`api-${suffix}`]?.image).toBe(
|
| 78 |
+
"myapi:latest",
|
| 79 |
+
);
|
| 80 |
+
});
|
| 81 |
+
|
| 82 |
+
const composeFile5 = `
|
| 83 |
+
version: "3.8"
|
| 84 |
+
|
| 85 |
+
services:
|
| 86 |
+
web:
|
| 87 |
+
image: nginx:latest
|
| 88 |
+
depends_on:
|
| 89 |
+
db:
|
| 90 |
+
condition: service_healthy
|
| 91 |
+
api:
|
| 92 |
+
condition: service_started
|
| 93 |
+
|
| 94 |
+
api:
|
| 95 |
+
image: myapi:latest
|
| 96 |
+
|
| 97 |
+
db:
|
| 98 |
+
image: postgres:latest
|
| 99 |
+
|
| 100 |
+
networks:
|
| 101 |
+
default:
|
| 102 |
+
driver: bridge
|
| 103 |
+
`;
|
| 104 |
+
|
| 105 |
+
test("Add suffix to service names with depends_on (object) in compose file", () => {
|
| 106 |
+
const composeData = load(composeFile5) as ComposeSpecification;
|
| 107 |
+
|
| 108 |
+
const suffix = generateRandomHash();
|
| 109 |
+
|
| 110 |
+
if (!composeData.services) {
|
| 111 |
+
return;
|
| 112 |
+
}
|
| 113 |
+
const updatedComposeData = addSuffixToServiceNames(
|
| 114 |
+
composeData.services,
|
| 115 |
+
suffix,
|
| 116 |
+
);
|
| 117 |
+
const actualComposeData = { ...composeData, services: updatedComposeData };
|
| 118 |
+
|
| 119 |
+
// Verificar que la nueva clave del servicio tiene el prefijo y la vieja clave no existe
|
| 120 |
+
expect(actualComposeData.services).toHaveProperty(`web-${suffix}`);
|
| 121 |
+
expect(actualComposeData.services).not.toHaveProperty("web");
|
| 122 |
+
|
| 123 |
+
// Verificar que la configuración de la imagen sigue igual
|
| 124 |
+
expect(actualComposeData.services?.[`web-${suffix}`]?.image).toBe(
|
| 125 |
+
"nginx:latest",
|
| 126 |
+
);
|
| 127 |
+
expect(actualComposeData.services?.[`api-${suffix}`]?.image).toBe(
|
| 128 |
+
"myapi:latest",
|
| 129 |
+
);
|
| 130 |
+
|
| 131 |
+
// Verificar que los nombres en depends_on tienen el prefijo
|
| 132 |
+
const webDependsOn = actualComposeData.services?.[`web-${suffix}`]
|
| 133 |
+
?.depends_on as Record<string, any>;
|
| 134 |
+
expect(webDependsOn).toHaveProperty(`db-${suffix}`);
|
| 135 |
+
expect(webDependsOn).toHaveProperty(`api-${suffix}`);
|
| 136 |
+
expect(webDependsOn[`db-${suffix}`].condition).toBe("service_healthy");
|
| 137 |
+
expect(webDependsOn[`api-${suffix}`].condition).toBe("service_started");
|
| 138 |
+
|
| 139 |
+
// Verificar que los servicios `db` y `api` también tienen el prefijo
|
| 140 |
+
expect(actualComposeData.services).toHaveProperty(`db-${suffix}`);
|
| 141 |
+
expect(actualComposeData.services).not.toHaveProperty("db");
|
| 142 |
+
expect(actualComposeData.services?.[`db-${suffix}`]?.image).toBe(
|
| 143 |
+
"postgres:latest",
|
| 144 |
+
);
|
| 145 |
+
expect(actualComposeData.services).toHaveProperty(`api-${suffix}`);
|
| 146 |
+
expect(actualComposeData.services).not.toHaveProperty("api");
|
| 147 |
+
expect(actualComposeData.services?.[`api-${suffix}`]?.image).toBe(
|
| 148 |
+
"myapi:latest",
|
| 149 |
+
);
|
| 150 |
+
});
|
data/apps/dokploy/__test__/compose/service/service-extends.test.ts
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { generateRandomHash } from "@dokploy/server";
|
| 2 |
+
import { addSuffixToServiceNames } from "@dokploy/server";
|
| 3 |
+
import type { ComposeSpecification } from "@dokploy/server";
|
| 4 |
+
import { load } from "js-yaml";
|
| 5 |
+
import { expect, test } from "vitest";
|
| 6 |
+
|
| 7 |
+
test("Generate random hash with 8 characters", () => {
|
| 8 |
+
const hash = generateRandomHash();
|
| 9 |
+
|
| 10 |
+
expect(hash).toBeDefined();
|
| 11 |
+
expect(hash.length).toBe(8);
|
| 12 |
+
});
|
| 13 |
+
|
| 14 |
+
const composeFile6 = `
|
| 15 |
+
version: "3.8"
|
| 16 |
+
|
| 17 |
+
services:
|
| 18 |
+
web:
|
| 19 |
+
image: nginx:latest
|
| 20 |
+
extends: base_service
|
| 21 |
+
|
| 22 |
+
api:
|
| 23 |
+
image: myapi:latest
|
| 24 |
+
|
| 25 |
+
base_service:
|
| 26 |
+
image: base:latest
|
| 27 |
+
|
| 28 |
+
networks:
|
| 29 |
+
default:
|
| 30 |
+
driver: bridge
|
| 31 |
+
`;
|
| 32 |
+
|
| 33 |
+
test("Add suffix to service names with extends (string) in compose file", () => {
|
| 34 |
+
const composeData = load(composeFile6) as ComposeSpecification;
|
| 35 |
+
|
| 36 |
+
const suffix = generateRandomHash();
|
| 37 |
+
|
| 38 |
+
if (!composeData.services) {
|
| 39 |
+
return;
|
| 40 |
+
}
|
| 41 |
+
const updatedComposeData = addSuffixToServiceNames(
|
| 42 |
+
composeData.services,
|
| 43 |
+
suffix,
|
| 44 |
+
);
|
| 45 |
+
const actualComposeData = { ...composeData, services: updatedComposeData };
|
| 46 |
+
|
| 47 |
+
// Verificar que la nueva clave del servicio tiene el prefijo y la vieja clave no existe
|
| 48 |
+
expect(actualComposeData.services).toHaveProperty(`web-${suffix}`);
|
| 49 |
+
expect(actualComposeData.services).not.toHaveProperty("web");
|
| 50 |
+
|
| 51 |
+
// Verificar que la configuración de la imagen sigue igual
|
| 52 |
+
expect(actualComposeData.services?.[`web-${suffix}`]?.image).toBe(
|
| 53 |
+
"nginx:latest",
|
| 54 |
+
);
|
| 55 |
+
expect(actualComposeData.services?.[`api-${suffix}`]?.image).toBe(
|
| 56 |
+
"myapi:latest",
|
| 57 |
+
);
|
| 58 |
+
|
| 59 |
+
// Verificar que el nombre en extends tiene el prefijo
|
| 60 |
+
expect(actualComposeData.services?.[`web-${suffix}`]?.extends).toBe(
|
| 61 |
+
`base_service-${suffix}`,
|
| 62 |
+
);
|
| 63 |
+
|
| 64 |
+
// Verificar que el servicio `base_service` también tiene el prefijo
|
| 65 |
+
expect(actualComposeData.services).toHaveProperty(`base_service-${suffix}`);
|
| 66 |
+
expect(actualComposeData.services).not.toHaveProperty("base_service");
|
| 67 |
+
expect(actualComposeData.services?.[`base_service-${suffix}`]?.image).toBe(
|
| 68 |
+
"base:latest",
|
| 69 |
+
);
|
| 70 |
+
});
|
| 71 |
+
|
| 72 |
+
const composeFile7 = `
|
| 73 |
+
version: "3.8"
|
| 74 |
+
|
| 75 |
+
services:
|
| 76 |
+
web:
|
| 77 |
+
image: nginx:latest
|
| 78 |
+
extends:
|
| 79 |
+
service: base_service
|
| 80 |
+
file: docker-compose.base.yml
|
| 81 |
+
|
| 82 |
+
api:
|
| 83 |
+
image: myapi:latest
|
| 84 |
+
|
| 85 |
+
base_service:
|
| 86 |
+
image: base:latest
|
| 87 |
+
|
| 88 |
+
networks:
|
| 89 |
+
default:
|
| 90 |
+
driver: bridge
|
| 91 |
+
`;
|
| 92 |
+
|
| 93 |
+
test("Add suffix to service names with extends (object) in compose file", () => {
|
| 94 |
+
const composeData = load(composeFile7) as ComposeSpecification;
|
| 95 |
+
|
| 96 |
+
const suffix = generateRandomHash();
|
| 97 |
+
|
| 98 |
+
if (!composeData.services) {
|
| 99 |
+
return;
|
| 100 |
+
}
|
| 101 |
+
const updatedComposeData = addSuffixToServiceNames(
|
| 102 |
+
composeData.services,
|
| 103 |
+
suffix,
|
| 104 |
+
);
|
| 105 |
+
const actualComposeData = { ...composeData, services: updatedComposeData };
|
| 106 |
+
|
| 107 |
+
// Verificar que la nueva clave del servicio tiene el prefijo y la vieja clave no existe
|
| 108 |
+
expect(actualComposeData.services).toHaveProperty(`web-${suffix}`);
|
| 109 |
+
expect(actualComposeData.services).not.toHaveProperty("web");
|
| 110 |
+
|
| 111 |
+
// Verificar que la configuración de la imagen sigue igual
|
| 112 |
+
expect(actualComposeData.services?.[`web-${suffix}`]?.image).toBe(
|
| 113 |
+
"nginx:latest",
|
| 114 |
+
);
|
| 115 |
+
expect(actualComposeData.services?.[`api-${suffix}`]?.image).toBe(
|
| 116 |
+
"myapi:latest",
|
| 117 |
+
);
|
| 118 |
+
|
| 119 |
+
// Verificar que el nombre en extends.service tiene el prefijo
|
| 120 |
+
const webExtends = actualComposeData.services?.[`web-${suffix}`]?.extends;
|
| 121 |
+
if (typeof webExtends !== "string") {
|
| 122 |
+
expect(webExtends?.service).toBe(`base_service-${suffix}`);
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
// Verificar que el servicio `base_service` también tiene el prefijo
|
| 126 |
+
expect(actualComposeData.services).toHaveProperty(`base_service-${suffix}`);
|
| 127 |
+
expect(actualComposeData.services).not.toHaveProperty("base_service");
|
| 128 |
+
expect(actualComposeData.services?.[`base_service-${suffix}`]?.image).toBe(
|
| 129 |
+
"base:latest",
|
| 130 |
+
);
|
| 131 |
+
});
|
data/apps/dokploy/__test__/compose/service/service-links.test.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { generateRandomHash } from "@dokploy/server";
|
| 2 |
+
import { addSuffixToServiceNames } from "@dokploy/server";
|
| 3 |
+
import type { ComposeSpecification } from "@dokploy/server";
|
| 4 |
+
import { load } from "js-yaml";
|
| 5 |
+
import { expect, test } from "vitest";
|
| 6 |
+
|
| 7 |
+
test("Generate random hash with 8 characters", () => {
|
| 8 |
+
const hash = generateRandomHash();
|
| 9 |
+
|
| 10 |
+
expect(hash).toBeDefined();
|
| 11 |
+
expect(hash.length).toBe(8);
|
| 12 |
+
});
|
| 13 |
+
|
| 14 |
+
const composeFile2 = `
|
| 15 |
+
version: "3.8"
|
| 16 |
+
|
| 17 |
+
services:
|
| 18 |
+
web:
|
| 19 |
+
image: nginx:latest
|
| 20 |
+
links:
|
| 21 |
+
- db
|
| 22 |
+
|
| 23 |
+
api:
|
| 24 |
+
image: myapi:latest
|
| 25 |
+
|
| 26 |
+
db:
|
| 27 |
+
image: postgres:latest
|
| 28 |
+
|
| 29 |
+
networks:
|
| 30 |
+
default:
|
| 31 |
+
driver: bridge
|
| 32 |
+
`;
|
| 33 |
+
|
| 34 |
+
test("Add suffix to service names with links in compose file", () => {
|
| 35 |
+
const composeData = load(composeFile2) as ComposeSpecification;
|
| 36 |
+
|
| 37 |
+
const suffix = generateRandomHash();
|
| 38 |
+
|
| 39 |
+
if (!composeData.services) {
|
| 40 |
+
return;
|
| 41 |
+
}
|
| 42 |
+
const updatedComposeData = addSuffixToServiceNames(
|
| 43 |
+
composeData.services,
|
| 44 |
+
suffix,
|
| 45 |
+
);
|
| 46 |
+
const actualComposeData = { ...composeData, services: updatedComposeData };
|
| 47 |
+
|
| 48 |
+
// Verificar que la nueva clave del servicio tiene el prefijo y la vieja clave no existe
|
| 49 |
+
expect(actualComposeData.services).toHaveProperty(`web-${suffix}`);
|
| 50 |
+
expect(actualComposeData.services).not.toHaveProperty("web");
|
| 51 |
+
|
| 52 |
+
// Verificar que la configuración de la imagen sigue igual
|
| 53 |
+
expect(actualComposeData.services?.[`web-${suffix}`]?.image).toBe(
|
| 54 |
+
"nginx:latest",
|
| 55 |
+
);
|
| 56 |
+
expect(actualComposeData.services?.[`api-${suffix}`]?.image).toBe(
|
| 57 |
+
"myapi:latest",
|
| 58 |
+
);
|
| 59 |
+
|
| 60 |
+
// Verificar que los nombres en links tienen el prefijo
|
| 61 |
+
expect(actualComposeData.services?.[`web-${suffix}`]?.links).toContain(
|
| 62 |
+
`db-${suffix}`,
|
| 63 |
+
);
|
| 64 |
+
|
| 65 |
+
// Verificar que los servicios `db` y `api` también tienen el prefijo
|
| 66 |
+
expect(actualComposeData.services).toHaveProperty(`db-${suffix}`);
|
| 67 |
+
expect(actualComposeData.services).not.toHaveProperty("db");
|
| 68 |
+
expect(actualComposeData.services?.[`db-${suffix}`]?.image).toBe(
|
| 69 |
+
"postgres:latest",
|
| 70 |
+
);
|
| 71 |
+
expect(actualComposeData.services).toHaveProperty(`api-${suffix}`);
|
| 72 |
+
expect(actualComposeData.services).not.toHaveProperty("api");
|
| 73 |
+
expect(actualComposeData.services?.[`api-${suffix}`]?.image).toBe(
|
| 74 |
+
"myapi:latest",
|
| 75 |
+
);
|
| 76 |
+
});
|
data/apps/dokploy/__test__/compose/service/service-names.test.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { generateRandomHash } from "@dokploy/server";
|
| 2 |
+
import { addSuffixToServiceNames } from "@dokploy/server";
|
| 3 |
+
import type { ComposeSpecification } from "@dokploy/server";
|
| 4 |
+
import { load } from "js-yaml";
|
| 5 |
+
import { expect, test } from "vitest";
|
| 6 |
+
|
| 7 |
+
test("Generate random hash with 8 characters", () => {
|
| 8 |
+
const hash = generateRandomHash();
|
| 9 |
+
|
| 10 |
+
expect(hash).toBeDefined();
|
| 11 |
+
expect(hash.length).toBe(8);
|
| 12 |
+
});
|
| 13 |
+
|
| 14 |
+
const composeFile = `
|
| 15 |
+
version: "3.8"
|
| 16 |
+
|
| 17 |
+
services:
|
| 18 |
+
web:
|
| 19 |
+
image: nginx:latest
|
| 20 |
+
|
| 21 |
+
api:
|
| 22 |
+
image: myapi:latest
|
| 23 |
+
|
| 24 |
+
networks:
|
| 25 |
+
default:
|
| 26 |
+
driver: bridge
|
| 27 |
+
`;
|
| 28 |
+
|
| 29 |
+
test("Add suffix to service names in compose file", () => {
|
| 30 |
+
const composeData = load(composeFile) as ComposeSpecification;
|
| 31 |
+
|
| 32 |
+
const suffix = generateRandomHash();
|
| 33 |
+
|
| 34 |
+
if (!composeData.services) {
|
| 35 |
+
return;
|
| 36 |
+
}
|
| 37 |
+
const updatedComposeData = addSuffixToServiceNames(
|
| 38 |
+
composeData.services,
|
| 39 |
+
suffix,
|
| 40 |
+
);
|
| 41 |
+
const actualComposeData = { ...composeData, services: updatedComposeData };
|
| 42 |
+
|
| 43 |
+
// Verificar que los nombres de los servicios han cambiado correctamente
|
| 44 |
+
expect(actualComposeData.services).toHaveProperty(`web-${suffix}`);
|
| 45 |
+
expect(actualComposeData.services).toHaveProperty(`api-${suffix}`);
|
| 46 |
+
// Verificar que las claves originales no existen
|
| 47 |
+
expect(actualComposeData.services).not.toHaveProperty("web");
|
| 48 |
+
expect(actualComposeData.services).not.toHaveProperty("api");
|
| 49 |
+
});
|
data/apps/dokploy/__test__/compose/service/service.test.ts
ADDED
|
@@ -0,0 +1,375 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {
|
| 2 |
+
addSuffixToAllServiceNames,
|
| 3 |
+
addSuffixToServiceNames,
|
| 4 |
+
} from "@dokploy/server";
|
| 5 |
+
import type { ComposeSpecification } from "@dokploy/server";
|
| 6 |
+
import { load } from "js-yaml";
|
| 7 |
+
import { expect, test } from "vitest";
|
| 8 |
+
|
| 9 |
+
const composeFileCombinedAllCases = `
|
| 10 |
+
version: "3.8"
|
| 11 |
+
|
| 12 |
+
services:
|
| 13 |
+
web:
|
| 14 |
+
image: nginx:latest
|
| 15 |
+
container_name: web_container
|
| 16 |
+
links:
|
| 17 |
+
- api
|
| 18 |
+
depends_on:
|
| 19 |
+
- api
|
| 20 |
+
extends: base_service
|
| 21 |
+
|
| 22 |
+
api:
|
| 23 |
+
image: myapi:latest
|
| 24 |
+
depends_on:
|
| 25 |
+
db:
|
| 26 |
+
condition: service_healthy
|
| 27 |
+
volumes_from:
|
| 28 |
+
- db
|
| 29 |
+
|
| 30 |
+
db:
|
| 31 |
+
image: postgres:latest
|
| 32 |
+
|
| 33 |
+
base_service:
|
| 34 |
+
image: base:latest
|
| 35 |
+
|
| 36 |
+
networks:
|
| 37 |
+
default:
|
| 38 |
+
driver: bridge
|
| 39 |
+
`;
|
| 40 |
+
|
| 41 |
+
const expectedComposeFile = load(`
|
| 42 |
+
version: "3.8"
|
| 43 |
+
|
| 44 |
+
services:
|
| 45 |
+
web-testhash:
|
| 46 |
+
image: nginx:latest
|
| 47 |
+
container_name: web_container-testhash
|
| 48 |
+
links:
|
| 49 |
+
- api-testhash
|
| 50 |
+
depends_on:
|
| 51 |
+
- api-testhash
|
| 52 |
+
extends: base_service-testhash
|
| 53 |
+
|
| 54 |
+
api-testhash:
|
| 55 |
+
image: myapi:latest
|
| 56 |
+
depends_on:
|
| 57 |
+
db-testhash:
|
| 58 |
+
condition: service_healthy
|
| 59 |
+
volumes_from:
|
| 60 |
+
- db-testhash
|
| 61 |
+
|
| 62 |
+
db-testhash:
|
| 63 |
+
image: postgres:latest
|
| 64 |
+
|
| 65 |
+
base_service-testhash:
|
| 66 |
+
image: base:latest
|
| 67 |
+
|
| 68 |
+
networks:
|
| 69 |
+
default:
|
| 70 |
+
driver: bridge
|
| 71 |
+
`);
|
| 72 |
+
|
| 73 |
+
test("Add suffix to all service names in compose file", () => {
|
| 74 |
+
const composeData = load(composeFileCombinedAllCases) as ComposeSpecification;
|
| 75 |
+
|
| 76 |
+
const suffix = "testhash";
|
| 77 |
+
|
| 78 |
+
if (!composeData.services) {
|
| 79 |
+
return;
|
| 80 |
+
}
|
| 81 |
+
const updatedComposeData = addSuffixToServiceNames(
|
| 82 |
+
composeData.services,
|
| 83 |
+
suffix,
|
| 84 |
+
);
|
| 85 |
+
const actualComposeData = { ...composeData, services: updatedComposeData };
|
| 86 |
+
|
| 87 |
+
expect(actualComposeData).toEqual(expectedComposeFile);
|
| 88 |
+
});
|
| 89 |
+
|
| 90 |
+
const composeFile1 = `
|
| 91 |
+
version: "3.8"
|
| 92 |
+
|
| 93 |
+
services:
|
| 94 |
+
web:
|
| 95 |
+
image: nginx:latest
|
| 96 |
+
container_name: web_container
|
| 97 |
+
depends_on:
|
| 98 |
+
- app
|
| 99 |
+
networks:
|
| 100 |
+
- frontend
|
| 101 |
+
volumes_from:
|
| 102 |
+
- data
|
| 103 |
+
links:
|
| 104 |
+
- db
|
| 105 |
+
extends:
|
| 106 |
+
service: base_service
|
| 107 |
+
|
| 108 |
+
app:
|
| 109 |
+
image: node:14
|
| 110 |
+
networks:
|
| 111 |
+
- backend
|
| 112 |
+
- frontend
|
| 113 |
+
|
| 114 |
+
db:
|
| 115 |
+
image: postgres:13
|
| 116 |
+
networks:
|
| 117 |
+
- backend
|
| 118 |
+
|
| 119 |
+
data:
|
| 120 |
+
image: busybox
|
| 121 |
+
volumes:
|
| 122 |
+
- /data
|
| 123 |
+
|
| 124 |
+
base_service:
|
| 125 |
+
image: base:latest
|
| 126 |
+
|
| 127 |
+
networks:
|
| 128 |
+
frontend:
|
| 129 |
+
driver: bridge
|
| 130 |
+
backend:
|
| 131 |
+
driver: bridge
|
| 132 |
+
`;
|
| 133 |
+
|
| 134 |
+
const expectedComposeFile1 = load(`
|
| 135 |
+
version: "3.8"
|
| 136 |
+
|
| 137 |
+
services:
|
| 138 |
+
web-testhash:
|
| 139 |
+
image: nginx:latest
|
| 140 |
+
container_name: web_container-testhash
|
| 141 |
+
depends_on:
|
| 142 |
+
- app-testhash
|
| 143 |
+
networks:
|
| 144 |
+
- frontend
|
| 145 |
+
volumes_from:
|
| 146 |
+
- data-testhash
|
| 147 |
+
links:
|
| 148 |
+
- db-testhash
|
| 149 |
+
extends:
|
| 150 |
+
service: base_service-testhash
|
| 151 |
+
|
| 152 |
+
app-testhash:
|
| 153 |
+
image: node:14
|
| 154 |
+
networks:
|
| 155 |
+
- backend
|
| 156 |
+
- frontend
|
| 157 |
+
|
| 158 |
+
db-testhash:
|
| 159 |
+
image: postgres:13
|
| 160 |
+
networks:
|
| 161 |
+
- backend
|
| 162 |
+
|
| 163 |
+
data-testhash:
|
| 164 |
+
image: busybox
|
| 165 |
+
volumes:
|
| 166 |
+
- /data
|
| 167 |
+
|
| 168 |
+
base_service-testhash:
|
| 169 |
+
image: base:latest
|
| 170 |
+
|
| 171 |
+
networks:
|
| 172 |
+
frontend:
|
| 173 |
+
driver: bridge
|
| 174 |
+
backend:
|
| 175 |
+
driver: bridge
|
| 176 |
+
`) as ComposeSpecification;
|
| 177 |
+
|
| 178 |
+
test("Add suffix to all service names in compose file 1", () => {
|
| 179 |
+
const composeData = load(composeFile1) as ComposeSpecification;
|
| 180 |
+
const suffix = "testhash";
|
| 181 |
+
|
| 182 |
+
const updatedComposeData = addSuffixToAllServiceNames(composeData, suffix);
|
| 183 |
+
|
| 184 |
+
expect(updatedComposeData).toEqual(expectedComposeFile1);
|
| 185 |
+
});
|
| 186 |
+
|
| 187 |
+
const composeFile2 = `
|
| 188 |
+
version: "3.8"
|
| 189 |
+
|
| 190 |
+
services:
|
| 191 |
+
frontend:
|
| 192 |
+
image: nginx:latest
|
| 193 |
+
depends_on:
|
| 194 |
+
- backend
|
| 195 |
+
networks:
|
| 196 |
+
- public
|
| 197 |
+
volumes_from:
|
| 198 |
+
- logs
|
| 199 |
+
links:
|
| 200 |
+
- cache
|
| 201 |
+
extends:
|
| 202 |
+
service: shared_service
|
| 203 |
+
|
| 204 |
+
backend:
|
| 205 |
+
image: node:14
|
| 206 |
+
networks:
|
| 207 |
+
- private
|
| 208 |
+
- public
|
| 209 |
+
|
| 210 |
+
cache:
|
| 211 |
+
image: redis:latest
|
| 212 |
+
networks:
|
| 213 |
+
- private
|
| 214 |
+
|
| 215 |
+
logs:
|
| 216 |
+
image: busybox
|
| 217 |
+
volumes:
|
| 218 |
+
- /logs
|
| 219 |
+
|
| 220 |
+
shared_service:
|
| 221 |
+
image: shared:latest
|
| 222 |
+
|
| 223 |
+
networks:
|
| 224 |
+
public:
|
| 225 |
+
driver: bridge
|
| 226 |
+
private:
|
| 227 |
+
driver: bridge
|
| 228 |
+
`;
|
| 229 |
+
|
| 230 |
+
const expectedComposeFile2 = load(`
|
| 231 |
+
version: "3.8"
|
| 232 |
+
|
| 233 |
+
services:
|
| 234 |
+
frontend-testhash:
|
| 235 |
+
image: nginx:latest
|
| 236 |
+
depends_on:
|
| 237 |
+
- backend-testhash
|
| 238 |
+
networks:
|
| 239 |
+
- public
|
| 240 |
+
volumes_from:
|
| 241 |
+
- logs-testhash
|
| 242 |
+
links:
|
| 243 |
+
- cache-testhash
|
| 244 |
+
extends:
|
| 245 |
+
service: shared_service-testhash
|
| 246 |
+
|
| 247 |
+
backend-testhash:
|
| 248 |
+
image: node:14
|
| 249 |
+
networks:
|
| 250 |
+
- private
|
| 251 |
+
- public
|
| 252 |
+
|
| 253 |
+
cache-testhash:
|
| 254 |
+
image: redis:latest
|
| 255 |
+
networks:
|
| 256 |
+
- private
|
| 257 |
+
|
| 258 |
+
logs-testhash:
|
| 259 |
+
image: busybox
|
| 260 |
+
volumes:
|
| 261 |
+
- /logs
|
| 262 |
+
|
| 263 |
+
shared_service-testhash:
|
| 264 |
+
image: shared:latest
|
| 265 |
+
|
| 266 |
+
networks:
|
| 267 |
+
public:
|
| 268 |
+
driver: bridge
|
| 269 |
+
private:
|
| 270 |
+
driver: bridge
|
| 271 |
+
`) as ComposeSpecification;
|
| 272 |
+
|
| 273 |
+
test("Add suffix to all service names in compose file 2", () => {
|
| 274 |
+
const composeData = load(composeFile2) as ComposeSpecification;
|
| 275 |
+
const suffix = "testhash";
|
| 276 |
+
|
| 277 |
+
const updatedComposeData = addSuffixToAllServiceNames(composeData, suffix);
|
| 278 |
+
|
| 279 |
+
expect(updatedComposeData).toEqual(expectedComposeFile2);
|
| 280 |
+
});
|
| 281 |
+
|
| 282 |
+
const composeFile3 = `
|
| 283 |
+
version: "3.8"
|
| 284 |
+
|
| 285 |
+
services:
|
| 286 |
+
service_a:
|
| 287 |
+
image: service_a:latest
|
| 288 |
+
depends_on:
|
| 289 |
+
- service_b
|
| 290 |
+
networks:
|
| 291 |
+
- net_a
|
| 292 |
+
volumes_from:
|
| 293 |
+
- data_volume
|
| 294 |
+
links:
|
| 295 |
+
- service_c
|
| 296 |
+
extends:
|
| 297 |
+
service: common_service
|
| 298 |
+
|
| 299 |
+
service_b:
|
| 300 |
+
image: service_b:latest
|
| 301 |
+
networks:
|
| 302 |
+
- net_b
|
| 303 |
+
- net_a
|
| 304 |
+
|
| 305 |
+
service_c:
|
| 306 |
+
image: service_c:latest
|
| 307 |
+
networks:
|
| 308 |
+
- net_b
|
| 309 |
+
|
| 310 |
+
data_volume:
|
| 311 |
+
image: busybox
|
| 312 |
+
volumes:
|
| 313 |
+
- /data
|
| 314 |
+
|
| 315 |
+
common_service:
|
| 316 |
+
image: common:latest
|
| 317 |
+
|
| 318 |
+
networks:
|
| 319 |
+
net_a:
|
| 320 |
+
driver: bridge
|
| 321 |
+
net_b:
|
| 322 |
+
driver: bridge
|
| 323 |
+
`;
|
| 324 |
+
|
| 325 |
+
const expectedComposeFile3 = load(`
|
| 326 |
+
version: "3.8"
|
| 327 |
+
|
| 328 |
+
services:
|
| 329 |
+
service_a-testhash:
|
| 330 |
+
image: service_a:latest
|
| 331 |
+
depends_on:
|
| 332 |
+
- service_b-testhash
|
| 333 |
+
networks:
|
| 334 |
+
- net_a
|
| 335 |
+
volumes_from:
|
| 336 |
+
- data_volume-testhash
|
| 337 |
+
links:
|
| 338 |
+
- service_c-testhash
|
| 339 |
+
extends:
|
| 340 |
+
service: common_service-testhash
|
| 341 |
+
|
| 342 |
+
service_b-testhash:
|
| 343 |
+
image: service_b:latest
|
| 344 |
+
networks:
|
| 345 |
+
- net_b
|
| 346 |
+
- net_a
|
| 347 |
+
|
| 348 |
+
service_c-testhash:
|
| 349 |
+
image: service_c:latest
|
| 350 |
+
networks:
|
| 351 |
+
- net_b
|
| 352 |
+
|
| 353 |
+
data_volume-testhash:
|
| 354 |
+
image: busybox
|
| 355 |
+
volumes:
|
| 356 |
+
- /data
|
| 357 |
+
|
| 358 |
+
common_service-testhash:
|
| 359 |
+
image: common:latest
|
| 360 |
+
|
| 361 |
+
networks:
|
| 362 |
+
net_a:
|
| 363 |
+
driver: bridge
|
| 364 |
+
net_b:
|
| 365 |
+
driver: bridge
|
| 366 |
+
`) as ComposeSpecification;
|
| 367 |
+
|
| 368 |
+
test("Add suffix to all service names in compose file 3", () => {
|
| 369 |
+
const composeData = load(composeFile3) as ComposeSpecification;
|
| 370 |
+
const suffix = "testhash";
|
| 371 |
+
|
| 372 |
+
const updatedComposeData = addSuffixToAllServiceNames(composeData, suffix);
|
| 373 |
+
|
| 374 |
+
expect(updatedComposeData).toEqual(expectedComposeFile3);
|
| 375 |
+
});
|
data/apps/dokploy/__test__/compose/service/sevice-volumes-from.test.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { generateRandomHash } from "@dokploy/server";
|
| 2 |
+
import { addSuffixToServiceNames } from "@dokploy/server";
|
| 3 |
+
import type { ComposeSpecification } from "@dokploy/server";
|
| 4 |
+
import { load } from "js-yaml";
|
| 5 |
+
import { expect, test } from "vitest";
|
| 6 |
+
|
| 7 |
+
test("Generate random hash with 8 characters", () => {
|
| 8 |
+
const hash = generateRandomHash();
|
| 9 |
+
|
| 10 |
+
expect(hash).toBeDefined();
|
| 11 |
+
expect(hash.length).toBe(8);
|
| 12 |
+
});
|
| 13 |
+
|
| 14 |
+
const composeFile3 = `
|
| 15 |
+
version: "3.8"
|
| 16 |
+
|
| 17 |
+
services:
|
| 18 |
+
web:
|
| 19 |
+
image: nginx:latest
|
| 20 |
+
volumes_from:
|
| 21 |
+
- shared
|
| 22 |
+
|
| 23 |
+
api:
|
| 24 |
+
image: myapi:latest
|
| 25 |
+
volumes_from:
|
| 26 |
+
- shared
|
| 27 |
+
|
| 28 |
+
shared:
|
| 29 |
+
image: busybox
|
| 30 |
+
volumes:
|
| 31 |
+
- /data
|
| 32 |
+
|
| 33 |
+
networks:
|
| 34 |
+
default:
|
| 35 |
+
driver: bridge
|
| 36 |
+
`;
|
| 37 |
+
|
| 38 |
+
test("Add suffix to service names with volumes_from in compose file", () => {
|
| 39 |
+
const composeData = load(composeFile3) as ComposeSpecification;
|
| 40 |
+
|
| 41 |
+
const suffix = generateRandomHash();
|
| 42 |
+
|
| 43 |
+
if (!composeData.services) {
|
| 44 |
+
return;
|
| 45 |
+
}
|
| 46 |
+
const updatedComposeData = addSuffixToServiceNames(
|
| 47 |
+
composeData.services,
|
| 48 |
+
suffix,
|
| 49 |
+
);
|
| 50 |
+
const actualComposeData = { ...composeData, services: updatedComposeData };
|
| 51 |
+
|
| 52 |
+
// Verificar que la nueva clave del servicio tiene el prefijo y la vieja clave no existe
|
| 53 |
+
expect(actualComposeData.services).toHaveProperty(`web-${suffix}`);
|
| 54 |
+
expect(actualComposeData.services).not.toHaveProperty("web");
|
| 55 |
+
|
| 56 |
+
// Verificar que la configuración de la imagen sigue igual
|
| 57 |
+
expect(actualComposeData.services?.[`web-${suffix}`]?.image).toBe(
|
| 58 |
+
"nginx:latest",
|
| 59 |
+
);
|
| 60 |
+
expect(actualComposeData.services?.[`api-${suffix}`]?.image).toBe(
|
| 61 |
+
"myapi:latest",
|
| 62 |
+
);
|
| 63 |
+
|
| 64 |
+
// Verificar que los nombres en volumes_from tienen el prefijo
|
| 65 |
+
expect(actualComposeData.services?.[`web-${suffix}`]?.volumes_from).toContain(
|
| 66 |
+
`shared-${suffix}`,
|
| 67 |
+
);
|
| 68 |
+
expect(actualComposeData.services?.[`api-${suffix}`]?.volumes_from).toContain(
|
| 69 |
+
`shared-${suffix}`,
|
| 70 |
+
);
|
| 71 |
+
|
| 72 |
+
// Verificar que el servicio shared también tiene el prefijo
|
| 73 |
+
expect(actualComposeData.services).toHaveProperty(`shared-${suffix}`);
|
| 74 |
+
expect(actualComposeData.services).not.toHaveProperty("shared");
|
| 75 |
+
expect(actualComposeData.services?.[`shared-${suffix}`]?.image).toBe(
|
| 76 |
+
"busybox",
|
| 77 |
+
);
|
| 78 |
+
});
|
data/apps/dokploy/__test__/compose/volume/volume-2.test.ts
ADDED
|
@@ -0,0 +1,1174 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { generateRandomHash } from "@dokploy/server";
|
| 2 |
+
import { addSuffixToAllVolumes, addSuffixToVolumesRoot } from "@dokploy/server";
|
| 3 |
+
import type { ComposeSpecification } from "@dokploy/server";
|
| 4 |
+
import { load } from "js-yaml";
|
| 5 |
+
import { expect, test } from "vitest";
|
| 6 |
+
|
| 7 |
+
const composeFile = `
|
| 8 |
+
services:
|
| 9 |
+
mail:
|
| 10 |
+
image: bytemark/smtp
|
| 11 |
+
restart: always
|
| 12 |
+
|
| 13 |
+
plausible_db:
|
| 14 |
+
image: postgres:14-alpine
|
| 15 |
+
restart: always
|
| 16 |
+
volumes:
|
| 17 |
+
- db-data:/var/lib/postgresql/data
|
| 18 |
+
environment:
|
| 19 |
+
- POSTGRES_PASSWORD=postgres
|
| 20 |
+
|
| 21 |
+
plausible_events_db:
|
| 22 |
+
image: clickhouse/clickhouse-server:23.3.7.5-alpine
|
| 23 |
+
restart: always
|
| 24 |
+
volumes:
|
| 25 |
+
- event-data:/var/lib/clickhouse
|
| 26 |
+
- event-logs:/var/log/clickhouse-server
|
| 27 |
+
- ./clickhouse/clickhouse-config.xml:/etc/clickhouse-server/config.d/logging.xml:ro
|
| 28 |
+
- ./clickhouse/clickhouse-user-config.xml:/etc/clickhouse-server/users.d/logging.xml:ro
|
| 29 |
+
ulimits:
|
| 30 |
+
nofile:
|
| 31 |
+
soft: 262144
|
| 32 |
+
hard: 262144
|
| 33 |
+
|
| 34 |
+
plausible:
|
| 35 |
+
image: plausible/analytics:v2.0
|
| 36 |
+
restart: always
|
| 37 |
+
command: sh -c "sleep 10 && /entrypoint.sh db createdb && /entrypoint.sh db migrate && /entrypoint.sh run"
|
| 38 |
+
depends_on:
|
| 39 |
+
- plausible_db
|
| 40 |
+
- plausible_events_db
|
| 41 |
+
- mail
|
| 42 |
+
ports:
|
| 43 |
+
- 127.0.0.1:8000:8000
|
| 44 |
+
env_file:
|
| 45 |
+
- plausible-conf.env
|
| 46 |
+
volumes:
|
| 47 |
+
- type: volume
|
| 48 |
+
source: plausible-data
|
| 49 |
+
target: /data
|
| 50 |
+
|
| 51 |
+
mysql:
|
| 52 |
+
image: mysql:5.7
|
| 53 |
+
restart: always
|
| 54 |
+
environment:
|
| 55 |
+
MYSQL_ROOT_PASSWORD: example
|
| 56 |
+
volumes:
|
| 57 |
+
- type: volume
|
| 58 |
+
source: db-data
|
| 59 |
+
target: /var/lib/mysql/data
|
| 60 |
+
|
| 61 |
+
volumes:
|
| 62 |
+
db-data:
|
| 63 |
+
driver: local
|
| 64 |
+
event-data:
|
| 65 |
+
driver: local
|
| 66 |
+
event-logs:
|
| 67 |
+
driver: local
|
| 68 |
+
`;
|
| 69 |
+
|
| 70 |
+
const expectedDockerCompose = load(`
|
| 71 |
+
services:
|
| 72 |
+
mail:
|
| 73 |
+
image: bytemark/smtp
|
| 74 |
+
restart: always
|
| 75 |
+
|
| 76 |
+
plausible_db:
|
| 77 |
+
image: postgres:14-alpine
|
| 78 |
+
restart: always
|
| 79 |
+
volumes:
|
| 80 |
+
- db-data-testhash:/var/lib/postgresql/data
|
| 81 |
+
environment:
|
| 82 |
+
- POSTGRES_PASSWORD=postgres
|
| 83 |
+
|
| 84 |
+
plausible_events_db:
|
| 85 |
+
image: clickhouse/clickhouse-server:23.3.7.5-alpine
|
| 86 |
+
restart: always
|
| 87 |
+
volumes:
|
| 88 |
+
- event-data-testhash:/var/lib/clickhouse
|
| 89 |
+
- event-logs-testhash:/var/log/clickhouse-server
|
| 90 |
+
- ./clickhouse/clickhouse-config.xml:/etc/clickhouse-server/config.d/logging.xml:ro
|
| 91 |
+
- ./clickhouse/clickhouse-user-config.xml:/etc/clickhouse-server/users.d/logging.xml:ro
|
| 92 |
+
ulimits:
|
| 93 |
+
nofile:
|
| 94 |
+
soft: 262144
|
| 95 |
+
hard: 262144
|
| 96 |
+
|
| 97 |
+
plausible:
|
| 98 |
+
image: plausible/analytics:v2.0
|
| 99 |
+
restart: always
|
| 100 |
+
command: sh -c "sleep 10 && /entrypoint.sh db createdb && /entrypoint.sh db migrate && /entrypoint.sh run"
|
| 101 |
+
depends_on:
|
| 102 |
+
- plausible_db
|
| 103 |
+
- plausible_events_db
|
| 104 |
+
- mail
|
| 105 |
+
ports:
|
| 106 |
+
- 127.0.0.1:8000:8000
|
| 107 |
+
env_file:
|
| 108 |
+
- plausible-conf.env
|
| 109 |
+
volumes:
|
| 110 |
+
- type: volume
|
| 111 |
+
source: plausible-data-testhash
|
| 112 |
+
target: /data
|
| 113 |
+
|
| 114 |
+
mysql:
|
| 115 |
+
image: mysql:5.7
|
| 116 |
+
restart: always
|
| 117 |
+
environment:
|
| 118 |
+
MYSQL_ROOT_PASSWORD: example
|
| 119 |
+
volumes:
|
| 120 |
+
- type: volume
|
| 121 |
+
source: db-data-testhash
|
| 122 |
+
target: /var/lib/mysql/data
|
| 123 |
+
|
| 124 |
+
volumes:
|
| 125 |
+
db-data-testhash:
|
| 126 |
+
driver: local
|
| 127 |
+
event-data-testhash:
|
| 128 |
+
driver: local
|
| 129 |
+
event-logs-testhash:
|
| 130 |
+
driver: local
|
| 131 |
+
`) as ComposeSpecification;
|
| 132 |
+
|
| 133 |
+
test("Generate random hash with 8 characters", () => {
|
| 134 |
+
const hash = generateRandomHash();
|
| 135 |
+
|
| 136 |
+
expect(hash).toBeDefined();
|
| 137 |
+
expect(hash.length).toBe(8);
|
| 138 |
+
});
|
| 139 |
+
|
| 140 |
+
// Docker compose needs unique names for services, volumes, networks and containers
|
| 141 |
+
// So base on a input which is a dockercompose file, it should replace the name with a hash and return a new dockercompose file
|
| 142 |
+
test("Add suffix to volumes root property", () => {
|
| 143 |
+
const composeData = load(composeFile) as ComposeSpecification;
|
| 144 |
+
|
| 145 |
+
const suffix = generateRandomHash();
|
| 146 |
+
|
| 147 |
+
if (!composeData?.volumes) {
|
| 148 |
+
return;
|
| 149 |
+
}
|
| 150 |
+
const volumes = addSuffixToVolumesRoot(composeData.volumes, suffix);
|
| 151 |
+
|
| 152 |
+
// {
|
| 153 |
+
// 'db-data-af045046': { driver: 'local' },
|
| 154 |
+
// 'event-data-af045046': { driver: 'local' },
|
| 155 |
+
// 'event-logs-af045046': { driver: 'local' }
|
| 156 |
+
// }
|
| 157 |
+
|
| 158 |
+
expect(volumes).toBeDefined();
|
| 159 |
+
for (const volumeKey of Object.keys(volumes)) {
|
| 160 |
+
expect(volumeKey).toContain(`-${suffix}`);
|
| 161 |
+
}
|
| 162 |
+
});
|
| 163 |
+
|
| 164 |
+
test("Expect to change the suffix in all the possible places", () => {
|
| 165 |
+
const composeData = load(composeFile) as ComposeSpecification;
|
| 166 |
+
const suffix = "testhash";
|
| 167 |
+
|
| 168 |
+
const updatedComposeData = addSuffixToAllVolumes(composeData, suffix);
|
| 169 |
+
|
| 170 |
+
expect(updatedComposeData).toEqual(expectedDockerCompose);
|
| 171 |
+
});
|
| 172 |
+
|
| 173 |
+
const composeFile2 = `
|
| 174 |
+
version: '3.8'
|
| 175 |
+
services:
|
| 176 |
+
app:
|
| 177 |
+
image: myapp:latest
|
| 178 |
+
build:
|
| 179 |
+
context: .
|
| 180 |
+
dockerfile: Dockerfile
|
| 181 |
+
volumes:
|
| 182 |
+
- app-config:/usr/src/app/config
|
| 183 |
+
- ./config:/usr/src/app/config:ro
|
| 184 |
+
environment:
|
| 185 |
+
- NODE_ENV=production
|
| 186 |
+
mongo:
|
| 187 |
+
image: mongo:4.2
|
| 188 |
+
volumes:
|
| 189 |
+
- mongo-data:/data/db
|
| 190 |
+
volumes:
|
| 191 |
+
app-config:
|
| 192 |
+
mongo-data:
|
| 193 |
+
`;
|
| 194 |
+
|
| 195 |
+
const expectedDockerCompose2 = load(`
|
| 196 |
+
version: '3.8'
|
| 197 |
+
services:
|
| 198 |
+
app:
|
| 199 |
+
image: myapp:latest
|
| 200 |
+
build:
|
| 201 |
+
context: .
|
| 202 |
+
dockerfile: Dockerfile
|
| 203 |
+
volumes:
|
| 204 |
+
- app-config-testhash:/usr/src/app/config
|
| 205 |
+
- ./config:/usr/src/app/config:ro
|
| 206 |
+
environment:
|
| 207 |
+
- NODE_ENV=production
|
| 208 |
+
mongo:
|
| 209 |
+
image: mongo:4.2
|
| 210 |
+
volumes:
|
| 211 |
+
- mongo-data-testhash:/data/db
|
| 212 |
+
volumes:
|
| 213 |
+
app-config-testhash:
|
| 214 |
+
mongo-data-testhash:
|
| 215 |
+
`) as ComposeSpecification;
|
| 216 |
+
|
| 217 |
+
test("Expect to change the suffix in all the possible places (2 Try)", () => {
|
| 218 |
+
const composeData = load(composeFile2) as ComposeSpecification;
|
| 219 |
+
const suffix = "testhash";
|
| 220 |
+
|
| 221 |
+
const updatedComposeData = addSuffixToAllVolumes(composeData, suffix);
|
| 222 |
+
|
| 223 |
+
expect(updatedComposeData).toEqual(expectedDockerCompose2);
|
| 224 |
+
});
|
| 225 |
+
|
| 226 |
+
const composeFile3 = `
|
| 227 |
+
version: '3.8'
|
| 228 |
+
services:
|
| 229 |
+
app:
|
| 230 |
+
image: myapp:latest
|
| 231 |
+
build:
|
| 232 |
+
context: .
|
| 233 |
+
dockerfile: Dockerfile
|
| 234 |
+
volumes:
|
| 235 |
+
- app-config:/usr/src/app/config
|
| 236 |
+
- ./config:/usr/src/app/config:ro
|
| 237 |
+
environment:
|
| 238 |
+
- NODE_ENV=production
|
| 239 |
+
mongo:
|
| 240 |
+
image: mongo:4.2
|
| 241 |
+
volumes:
|
| 242 |
+
- mongo-data:/data/db
|
| 243 |
+
volumes:
|
| 244 |
+
app-config:
|
| 245 |
+
mongo-data:
|
| 246 |
+
`;
|
| 247 |
+
|
| 248 |
+
const expectedDockerCompose3 = load(`
|
| 249 |
+
version: '3.8'
|
| 250 |
+
services:
|
| 251 |
+
app:
|
| 252 |
+
image: myapp:latest
|
| 253 |
+
build:
|
| 254 |
+
context: .
|
| 255 |
+
dockerfile: Dockerfile
|
| 256 |
+
volumes:
|
| 257 |
+
- app-config-testhash:/usr/src/app/config
|
| 258 |
+
- ./config:/usr/src/app/config:ro
|
| 259 |
+
environment:
|
| 260 |
+
- NODE_ENV=production
|
| 261 |
+
mongo:
|
| 262 |
+
image: mongo:4.2
|
| 263 |
+
volumes:
|
| 264 |
+
- mongo-data-testhash:/data/db
|
| 265 |
+
volumes:
|
| 266 |
+
app-config-testhash:
|
| 267 |
+
mongo-data-testhash:
|
| 268 |
+
`) as ComposeSpecification;
|
| 269 |
+
|
| 270 |
+
test("Expect to change the suffix in all the possible places (3 Try)", () => {
|
| 271 |
+
const composeData = load(composeFile3) as ComposeSpecification;
|
| 272 |
+
const suffix = "testhash";
|
| 273 |
+
|
| 274 |
+
const updatedComposeData = addSuffixToAllVolumes(composeData, suffix);
|
| 275 |
+
|
| 276 |
+
expect(updatedComposeData).toEqual(expectedDockerCompose3);
|
| 277 |
+
});
|
| 278 |
+
|
| 279 |
+
const composeFileComplex = `
|
| 280 |
+
version: "3.8"
|
| 281 |
+
services:
|
| 282 |
+
studio:
|
| 283 |
+
container_name: supabase-studio
|
| 284 |
+
image: supabase/studio:20240422-5cf8f30
|
| 285 |
+
restart: unless-stopped
|
| 286 |
+
healthcheck:
|
| 287 |
+
test:
|
| 288 |
+
[
|
| 289 |
+
"CMD",
|
| 290 |
+
"node",
|
| 291 |
+
"-e",
|
| 292 |
+
"require('http').get('http://localhost:3000/api/profile', (r) => {if (r.statusCode !== 200) throw new Error(r.statusCode)})"
|
| 293 |
+
]
|
| 294 |
+
timeout: 5s
|
| 295 |
+
interval: 5s
|
| 296 |
+
retries: 3
|
| 297 |
+
depends_on:
|
| 298 |
+
analytics:
|
| 299 |
+
condition: service_healthy
|
| 300 |
+
environment:
|
| 301 |
+
STUDIO_PG_META_URL: http://meta:8080
|
| 302 |
+
POSTGRES_PASSWORD: \${POSTGRES_PASSWORD}
|
| 303 |
+
DEFAULT_ORGANIZATION_NAME: \${STUDIO_DEFAULT_ORGANIZATION}
|
| 304 |
+
DEFAULT_PROJECT_NAME: \${STUDIO_DEFAULT_PROJECT}
|
| 305 |
+
SUPABASE_URL: http://kong:8000
|
| 306 |
+
SUPABASE_PUBLIC_URL: \${SUPABASE_PUBLIC_URL}
|
| 307 |
+
SUPABASE_ANON_KEY: \${ANON_KEY}
|
| 308 |
+
SUPABASE_SERVICE_KEY: \${SERVICE_ROLE_KEY}
|
| 309 |
+
LOGFLARE_API_KEY: \${LOGFLARE_API_KEY}
|
| 310 |
+
LOGFLARE_URL: http://analytics:4000
|
| 311 |
+
NEXT_PUBLIC_ENABLE_LOGS: true
|
| 312 |
+
NEXT_ANALYTICS_BACKEND_PROVIDER: postgres
|
| 313 |
+
|
| 314 |
+
kong:
|
| 315 |
+
container_name: supabase-kong
|
| 316 |
+
image: kong:2.8.1
|
| 317 |
+
restart: unless-stopped
|
| 318 |
+
entrypoint: bash -c 'eval "echo \"$$(cat ~/temp.yml)\"" > ~/kong.yml && /docker-entrypoint.sh kong docker-start'
|
| 319 |
+
ports:
|
| 320 |
+
- \${KONG_HTTP_PORT}:8000/tcp
|
| 321 |
+
- \${KONG_HTTPS_PORT}:8443/tcp
|
| 322 |
+
depends_on:
|
| 323 |
+
analytics:
|
| 324 |
+
condition: service_healthy
|
| 325 |
+
environment:
|
| 326 |
+
KONG_DATABASE: "off"
|
| 327 |
+
KONG_DECLARATIVE_CONFIG: /home/kong/kong.yml
|
| 328 |
+
KONG_DNS_ORDER: LAST,A,CNAME
|
| 329 |
+
KONG_PLUGINS: request-transformer,cors,key-auth,acl,basic-auth
|
| 330 |
+
KONG_NGINX_PROXY_PROXY_BUFFER_SIZE: 160k
|
| 331 |
+
KONG_NGINX_PROXY_PROXY_BUFFERS: 64 160k
|
| 332 |
+
SUPABASE_ANON_KEY: \${ANON_KEY}
|
| 333 |
+
SUPABASE_SERVICE_KEY: \${SERVICE_ROLE_KEY}
|
| 334 |
+
DASHBOARD_USERNAME: \${DASHBOARD_USERNAME}
|
| 335 |
+
DASHBOARD_PASSWORD: \${DASHBOARD_PASSWORD}
|
| 336 |
+
volumes:
|
| 337 |
+
- ./volumes/api/kong.yml:/home/kong/temp.yml:ro
|
| 338 |
+
|
| 339 |
+
auth:
|
| 340 |
+
container_name: supabase-auth
|
| 341 |
+
image: supabase/gotrue:v2.151.0
|
| 342 |
+
depends_on:
|
| 343 |
+
db:
|
| 344 |
+
condition: service_healthy
|
| 345 |
+
analytics:
|
| 346 |
+
condition: service_healthy
|
| 347 |
+
healthcheck:
|
| 348 |
+
test:
|
| 349 |
+
[
|
| 350 |
+
"CMD",
|
| 351 |
+
"wget",
|
| 352 |
+
"--no-verbose",
|
| 353 |
+
"--tries=1",
|
| 354 |
+
"--spider",
|
| 355 |
+
"http://localhost:9999/health"
|
| 356 |
+
]
|
| 357 |
+
timeout: 5s
|
| 358 |
+
interval: 5s
|
| 359 |
+
retries: 3
|
| 360 |
+
restart: unless-stopped
|
| 361 |
+
environment:
|
| 362 |
+
GOTRUE_API_HOST: 0.0.0.0
|
| 363 |
+
GOTRUE_API_PORT: 9999
|
| 364 |
+
API_EXTERNAL_URL: \${API_EXTERNAL_URL}
|
| 365 |
+
GOTRUE_DB_DRIVER: postgres
|
| 366 |
+
GOTRUE_DB_DATABASE_URL: postgres://supabase_auth_admin:\${POSTGRES_PASSWORD}@\${POSTGRES_HOST}:\${POSTGRES_PORT}/\${POSTGRES_DB}
|
| 367 |
+
GOTRUE_SITE_URL: \${SITE_URL}
|
| 368 |
+
GOTRUE_URI_ALLOW_LIST: \${ADDITIONAL_REDIRECT_URLS}
|
| 369 |
+
GOTRUE_DISABLE_SIGNUP: \${DISABLE_SIGNUP}
|
| 370 |
+
GOTRUE_JWT_ADMIN_ROLES: service_role
|
| 371 |
+
GOTRUE_JWT_AUD: authenticated
|
| 372 |
+
GOTRUE_JWT_DEFAULT_GROUP_NAME: authenticated
|
| 373 |
+
GOTRUE_JWT_EXP: \${JWT_EXPIRY}
|
| 374 |
+
GOTRUE_JWT_SECRET: \${JWT_SECRET}
|
| 375 |
+
GOTRUE_EXTERNAL_EMAIL_ENABLED: \${ENABLE_EMAIL_SIGNUP}
|
| 376 |
+
GOTRUE_EXTERNAL_ANONYMOUS_USERS_ENABLED: \${ENABLE_ANONYMOUS_USERS}
|
| 377 |
+
GOTRUE_MAILER_AUTOCONFIRM: \${ENABLE_EMAIL_AUTOCONFIRM}
|
| 378 |
+
GOTRUE_SMTP_ADMIN_EMAIL: \${SMTP_ADMIN_EMAIL}
|
| 379 |
+
GOTRUE_SMTP_HOST: \${SMTP_HOST}
|
| 380 |
+
GOTRUE_SMTP_PORT: \${SMTP_PORT}
|
| 381 |
+
GOTRUE_SMTP_USER: \${SMTP_USER}
|
| 382 |
+
GOTRUE_SMTP_PASS: \${SMTP_PASS}
|
| 383 |
+
GOTRUE_SMTP_SENDER_NAME: \${SMTP_SENDER_NAME}
|
| 384 |
+
GOTRUE_MAILER_URLPATHS_INVITE: \${MAILER_URLPATHS_INVITE}
|
| 385 |
+
GOTRUE_MAILER_URLPATHS_CONFIRMATION: \${MAILER_URLPATHS_CONFIRMATION}
|
| 386 |
+
GOTRUE_MAILER_URLPATHS_RECOVERY: \${MAILER_URLPATHS_RECOVERY}
|
| 387 |
+
GOTRUE_MAILER_URLPATHS_EMAIL_CHANGE: \${MAILER_URLPATHS_EMAIL_CHANGE}
|
| 388 |
+
GOTRUE_EXTERNAL_PHONE_ENABLED: \${ENABLE_PHONE_SIGNUP}
|
| 389 |
+
GOTRUE_SMS_AUTOCONFIRM: \${ENABLE_PHONE_AUTOCONFIRM}
|
| 390 |
+
|
| 391 |
+
rest:
|
| 392 |
+
container_name: supabase-rest
|
| 393 |
+
image: postgrest/postgrest:v12.0.1
|
| 394 |
+
depends_on:
|
| 395 |
+
db:
|
| 396 |
+
condition: service_healthy
|
| 397 |
+
analytics:
|
| 398 |
+
condition: service_healthy
|
| 399 |
+
restart: unless-stopped
|
| 400 |
+
environment:
|
| 401 |
+
PGRST_DB_URI: postgres://authenticator:\${POSTGRES_PASSWORD}@\${POSTGRES_HOST}:\${POSTGRES_PORT}/\${POSTGRES_DB}
|
| 402 |
+
PGRST_DB_SCHEMAS: \${PGRST_DB_SCHEMAS}
|
| 403 |
+
PGRST_DB_ANON_ROLE: anon
|
| 404 |
+
PGRST_JWT_SECRET: \${JWT_SECRET}
|
| 405 |
+
PGRST_DB_USE_LEGACY_GUCS: "false"
|
| 406 |
+
PGRST_APP_SETTINGS_JWT_SECRET: \${JWT_SECRET}
|
| 407 |
+
PGRST_APP_SETTINGS_JWT_EXP: \${JWT_EXPIRY}
|
| 408 |
+
command: "postgrest"
|
| 409 |
+
|
| 410 |
+
realtime:
|
| 411 |
+
container_name: realtime-dev.supabase-realtime
|
| 412 |
+
image: supabase/realtime:v2.28.32
|
| 413 |
+
depends_on:
|
| 414 |
+
db:
|
| 415 |
+
condition: service_healthy
|
| 416 |
+
analytics:
|
| 417 |
+
condition: service_healthy
|
| 418 |
+
healthcheck:
|
| 419 |
+
test:
|
| 420 |
+
[
|
| 421 |
+
"CMD",
|
| 422 |
+
"curl",
|
| 423 |
+
"-sSfL",
|
| 424 |
+
"--head",
|
| 425 |
+
"-o",
|
| 426 |
+
"/dev/null",
|
| 427 |
+
"-H",
|
| 428 |
+
"Authorization: Bearer \${ANON_KEY}",
|
| 429 |
+
"http://localhost:4000/api/tenants/realtime-dev/health"
|
| 430 |
+
]
|
| 431 |
+
timeout: 5s
|
| 432 |
+
interval: 5s
|
| 433 |
+
retries: 3
|
| 434 |
+
restart: unless-stopped
|
| 435 |
+
environment:
|
| 436 |
+
PORT: 4000
|
| 437 |
+
DB_HOST: \${POSTGRES_HOST}
|
| 438 |
+
DB_PORT: \${POSTGRES_PORT}
|
| 439 |
+
DB_USER: supabase_admin
|
| 440 |
+
DB_PASSWORD: \${POSTGRES_PASSWORD}
|
| 441 |
+
DB_NAME: \${POSTGRES_DB}
|
| 442 |
+
DB_AFTER_CONNECT_QUERY: 'SET search_path TO _realtime'
|
| 443 |
+
DB_ENC_KEY: supabaserealtime
|
| 444 |
+
API_JWT_SECRET: \${JWT_SECRET}
|
| 445 |
+
FLY_ALLOC_ID: fly123
|
| 446 |
+
FLY_APP_NAME: realtime
|
| 447 |
+
SECRET_KEY_BASE: UpNVntn3cDxHJpq99YMc1T1AQgQpc8kfYTuRgBiYa15BLrx8etQoXz3gZv1/u2oq
|
| 448 |
+
ERL_AFLAGS: -proto_dist inet_tcp
|
| 449 |
+
ENABLE_TAILSCALE: "false"
|
| 450 |
+
DNS_NODES: "''"
|
| 451 |
+
command: >
|
| 452 |
+
sh -c "/app/bin/migrate && /app/bin/realtime eval 'Realtime.Release.seeds(Realtime.Repo)' && /app/bin/server"
|
| 453 |
+
|
| 454 |
+
storage:
|
| 455 |
+
container_name: supabase-storage
|
| 456 |
+
image: supabase/storage-api:v1.0.6
|
| 457 |
+
depends_on:
|
| 458 |
+
db:
|
| 459 |
+
condition: service_healthy
|
| 460 |
+
rest:
|
| 461 |
+
condition: service_started
|
| 462 |
+
imgproxy:
|
| 463 |
+
condition: service_started
|
| 464 |
+
healthcheck:
|
| 465 |
+
test:
|
| 466 |
+
[
|
| 467 |
+
"CMD",
|
| 468 |
+
"wget",
|
| 469 |
+
"--no-verbose",
|
| 470 |
+
"--tries=1",
|
| 471 |
+
"--spider",
|
| 472 |
+
"http://localhost:5000/status"
|
| 473 |
+
]
|
| 474 |
+
timeout: 5s
|
| 475 |
+
interval: 5s
|
| 476 |
+
retries: 3
|
| 477 |
+
restart: unless-stopped
|
| 478 |
+
environment:
|
| 479 |
+
ANON_KEY: \${ANON_KEY}
|
| 480 |
+
SERVICE_KEY: \${SERVICE_ROLE_KEY}
|
| 481 |
+
POSTGREST_URL: http://rest:3000
|
| 482 |
+
PGRST_JWT_SECRET: \${JWT_SECRET}
|
| 483 |
+
DATABASE_URL: postgres://supabase_storage_admin:\${POSTGRES_PASSWORD}@\${POSTGRES_HOST}:\${POSTGRES_PORT}/\${POSTGRES_DB}
|
| 484 |
+
FILE_SIZE_LIMIT: 52428800
|
| 485 |
+
STORAGE_BACKEND: file
|
| 486 |
+
FILE_STORAGE_BACKEND_PATH: /var/lib/storage
|
| 487 |
+
TENANT_ID: stub
|
| 488 |
+
REGION: stub
|
| 489 |
+
GLOBAL_S3_BUCKET: stub
|
| 490 |
+
ENABLE_IMAGE_TRANSFORMATION: "true"
|
| 491 |
+
IMGPROXY_URL: http://imgproxy:5001
|
| 492 |
+
volumes:
|
| 493 |
+
- ./volumes/storage:/var/lib/storage:z
|
| 494 |
+
|
| 495 |
+
imgproxy:
|
| 496 |
+
container_name: supabase-imgproxy
|
| 497 |
+
image: darthsim/imgproxy:v3.8.0
|
| 498 |
+
healthcheck:
|
| 499 |
+
test: [ "CMD", "imgproxy", "health" ]
|
| 500 |
+
timeout: 5s
|
| 501 |
+
interval: 5s
|
| 502 |
+
retries: 3
|
| 503 |
+
environment:
|
| 504 |
+
IMGPROXY_BIND: ":5001"
|
| 505 |
+
IMGPROXY_LOCAL_FILESYSTEM_ROOT: /
|
| 506 |
+
IMGPROXY_USE_ETAG: "true"
|
| 507 |
+
IMGPROXY_ENABLE_WEBP_DETECTION: \${IMGPROXY_ENABLE_WEBP_DETECTION}
|
| 508 |
+
volumes:
|
| 509 |
+
- ./volumes/storage:/var/lib/storage:z
|
| 510 |
+
|
| 511 |
+
meta:
|
| 512 |
+
container_name: supabase-meta
|
| 513 |
+
image: supabase/postgres-meta:v0.80.0
|
| 514 |
+
depends_on:
|
| 515 |
+
db:
|
| 516 |
+
condition: service_healthy
|
| 517 |
+
analytics:
|
| 518 |
+
condition: service_healthy
|
| 519 |
+
restart: unless-stopped
|
| 520 |
+
environment:
|
| 521 |
+
PG_META_PORT: 8080
|
| 522 |
+
PG_META_DB_HOST: \${POSTGRES_HOST}
|
| 523 |
+
PG_META_DB_PORT: \${POSTGRES_PORT}
|
| 524 |
+
PG_META_DB_NAME: \${POSTGRES_DB}
|
| 525 |
+
PG_META_DB_USER: supabase_admin
|
| 526 |
+
PG_META_DB_PASSWORD: \${POSTGRES_PASSWORD}
|
| 527 |
+
|
| 528 |
+
functions:
|
| 529 |
+
container_name: supabase-edge-functions
|
| 530 |
+
image: supabase/edge-runtime:v1.45.2
|
| 531 |
+
restart: unless-stopped
|
| 532 |
+
depends_on:
|
| 533 |
+
analytics:
|
| 534 |
+
condition: service_healthy
|
| 535 |
+
environment:
|
| 536 |
+
JWT_SECRET: \${JWT_SECRET}
|
| 537 |
+
SUPABASE_URL: http://kong:8000
|
| 538 |
+
SUPABASE_ANON_KEY: \${ANON_KEY}
|
| 539 |
+
SUPABASE_SERVICE_ROLE_KEY: \${SERVICE_ROLE_KEY}
|
| 540 |
+
SUPABASE_DB_URL: postgresql://postgres:\${POSTGRES_PASSWORD}@\${POSTGRES_HOST}:\${POSTGRES_PORT}/\${POSTGRES_DB}
|
| 541 |
+
VERIFY_JWT: "\${FUNCTIONS_VERIFY_JWT}"
|
| 542 |
+
volumes:
|
| 543 |
+
- ./volumes/functions:/home/deno/functions:Z
|
| 544 |
+
command:
|
| 545 |
+
- start
|
| 546 |
+
- --main-service
|
| 547 |
+
- /home/deno/functions/main
|
| 548 |
+
|
| 549 |
+
analytics:
|
| 550 |
+
container_name: supabase-analytics
|
| 551 |
+
image: supabase/logflare:1.4.0
|
| 552 |
+
healthcheck:
|
| 553 |
+
test: [ "CMD", "curl", "http://localhost:4000/health" ]
|
| 554 |
+
timeout: 5s
|
| 555 |
+
interval: 5s
|
| 556 |
+
retries: 10
|
| 557 |
+
restart: unless-stopped
|
| 558 |
+
depends_on:
|
| 559 |
+
db:
|
| 560 |
+
condition: service_healthy
|
| 561 |
+
environment:
|
| 562 |
+
LOGFLARE_NODE_HOST: 127.0.0.1
|
| 563 |
+
DB_USERNAME: supabase_admin
|
| 564 |
+
DB_DATABASE: \${POSTGRES_DB}
|
| 565 |
+
DB_HOSTNAME: \${POSTGRES_HOST}
|
| 566 |
+
DB_PORT: \${POSTGRES_PORT}
|
| 567 |
+
DB_PASSWORD: \${POSTGRES_PASSWORD}
|
| 568 |
+
DB_SCHEMA: _analytics
|
| 569 |
+
LOGFLARE_API_KEY: \${LOGFLARE_API_KEY}
|
| 570 |
+
LOGFLARE_SINGLE_TENANT: true
|
| 571 |
+
LOGFLARE_SUPABASE_MODE: true
|
| 572 |
+
LOGFLARE_MIN_CLUSTER_SIZE: 1
|
| 573 |
+
POSTGRES_BACKEND_URL: postgresql://supabase_admin:\${POSTGRES_PASSWORD}@\${POSTGRES_HOST}:\${POSTGRES_PORT}/\${POSTGRES_DB}
|
| 574 |
+
POSTGRES_BACKEND_SCHEMA: _analytics
|
| 575 |
+
LOGFLARE_FEATURE_FLAG_OVERRIDE: multibackend=true
|
| 576 |
+
ports:
|
| 577 |
+
- 4000:4000
|
| 578 |
+
|
| 579 |
+
db:
|
| 580 |
+
container_name: supabase-db
|
| 581 |
+
image: supabase/postgres:15.1.1.41
|
| 582 |
+
healthcheck:
|
| 583 |
+
test: pg_isready -U postgres -h localhost
|
| 584 |
+
interval: 5s
|
| 585 |
+
timeout: 5s
|
| 586 |
+
retries: 10
|
| 587 |
+
depends_on:
|
| 588 |
+
vector:
|
| 589 |
+
condition: service_healthy
|
| 590 |
+
command:
|
| 591 |
+
- postgres
|
| 592 |
+
- -c
|
| 593 |
+
- config_file=/etc/postgresql/postgresql.conf
|
| 594 |
+
- -c
|
| 595 |
+
- log_min_messages=fatal
|
| 596 |
+
restart: unless-stopped
|
| 597 |
+
ports:
|
| 598 |
+
- \${POSTGRES_PORT}:\${POSTGRES_PORT}
|
| 599 |
+
environment:
|
| 600 |
+
POSTGRES_HOST: /var/run/postgresql
|
| 601 |
+
PGPORT: \${POSTGRES_PORT}
|
| 602 |
+
POSTGRES_PORT: \${POSTGRES_PORT}
|
| 603 |
+
PGPASSWORD: \${POSTGRES_PASSWORD}
|
| 604 |
+
POSTGRES_PASSWORD: \${POSTGRES_PASSWORD}
|
| 605 |
+
PGDATABASE: \${POSTGRES_DB}
|
| 606 |
+
POSTGRES_DB: \${POSTGRES_DB}
|
| 607 |
+
JWT_SECRET: \${JWT_SECRET}
|
| 608 |
+
JWT_EXP: \${JWT_EXPIRY}
|
| 609 |
+
volumes:
|
| 610 |
+
- ./volumes/db/realtime.sql:/docker-entrypoint-initdb.d/migrations/99-realtime.sql:Z
|
| 611 |
+
- ./volumes/db/webhooks.sql:/docker-entrypoint-initdb.d/init-scripts/98-webhooks.sql:Z
|
| 612 |
+
- ./volumes/db/roles.sql:/docker-entrypoint-initdb.d/init-scripts/99-roles.sql:Z
|
| 613 |
+
- ./volumes/db/jwt.sql:/docker-entrypoint-initdb.d/init-scripts/99-jwt.sql:Z
|
| 614 |
+
- ./volumes/db/data:/var/lib/postgresql/data:Z
|
| 615 |
+
- ./volumes/db/logs.sql:/docker-entrypoint-initdb.d/migrations/99-logs.sql:Z
|
| 616 |
+
- db-config:/etc/postgresql-custom
|
| 617 |
+
|
| 618 |
+
vector:
|
| 619 |
+
container_name: supabase-vector
|
| 620 |
+
image: timberio/vector:0.28.1-alpine
|
| 621 |
+
healthcheck:
|
| 622 |
+
test:
|
| 623 |
+
[
|
| 624 |
+
"CMD",
|
| 625 |
+
"wget",
|
| 626 |
+
"--no-verbose",
|
| 627 |
+
"--tries=1",
|
| 628 |
+
"--spider",
|
| 629 |
+
"http://vector:9001/health"
|
| 630 |
+
]
|
| 631 |
+
timeout: 5s
|
| 632 |
+
interval: 5s
|
| 633 |
+
retries: 3
|
| 634 |
+
volumes:
|
| 635 |
+
- ./volumes/logs/vector.yml:/etc/vector/vector.yml:ro
|
| 636 |
+
- "\${DOCKER_SOCKET_LOCATION}:/var/run/docker.sock:ro"
|
| 637 |
+
environment:
|
| 638 |
+
LOGFLARE_API_KEY: \${LOGFLARE_API_KEY}
|
| 639 |
+
command: [ "--config", "etc/vector/vector.yml" ]
|
| 640 |
+
|
| 641 |
+
volumes:
|
| 642 |
+
db-config:
|
| 643 |
+
`;
|
| 644 |
+
|
| 645 |
+
const expectedDockerComposeComplex = load(`
|
| 646 |
+
version: "3.8"
|
| 647 |
+
services:
|
| 648 |
+
studio:
|
| 649 |
+
container_name: supabase-studio
|
| 650 |
+
image: supabase/studio:20240422-5cf8f30
|
| 651 |
+
restart: unless-stopped
|
| 652 |
+
healthcheck:
|
| 653 |
+
test:
|
| 654 |
+
[
|
| 655 |
+
"CMD",
|
| 656 |
+
"node",
|
| 657 |
+
"-e",
|
| 658 |
+
"require('http').get('http://localhost:3000/api/profile', (r) => {if (r.statusCode !== 200) throw new Error(r.statusCode)})"
|
| 659 |
+
]
|
| 660 |
+
timeout: 5s
|
| 661 |
+
interval: 5s
|
| 662 |
+
retries: 3
|
| 663 |
+
depends_on:
|
| 664 |
+
analytics:
|
| 665 |
+
condition: service_healthy
|
| 666 |
+
environment:
|
| 667 |
+
STUDIO_PG_META_URL: http://meta:8080
|
| 668 |
+
POSTGRES_PASSWORD: \${POSTGRES_PASSWORD}
|
| 669 |
+
DEFAULT_ORGANIZATION_NAME: \${STUDIO_DEFAULT_ORGANIZATION}
|
| 670 |
+
DEFAULT_PROJECT_NAME: \${STUDIO_DEFAULT_PROJECT}
|
| 671 |
+
SUPABASE_URL: http://kong:8000
|
| 672 |
+
SUPABASE_PUBLIC_URL: \${SUPABASE_PUBLIC_URL}
|
| 673 |
+
SUPABASE_ANON_KEY: \${ANON_KEY}
|
| 674 |
+
SUPABASE_SERVICE_KEY: \${SERVICE_ROLE_KEY}
|
| 675 |
+
LOGFLARE_API_KEY: \${LOGFLARE_API_KEY}
|
| 676 |
+
LOGFLARE_URL: http://analytics:4000
|
| 677 |
+
NEXT_PUBLIC_ENABLE_LOGS: true
|
| 678 |
+
NEXT_ANALYTICS_BACKEND_PROVIDER: postgres
|
| 679 |
+
|
| 680 |
+
kong:
|
| 681 |
+
container_name: supabase-kong
|
| 682 |
+
image: kong:2.8.1
|
| 683 |
+
restart: unless-stopped
|
| 684 |
+
entrypoint: bash -c 'eval "echo \"$$(cat ~/temp.yml)\"" > ~/kong.yml && /docker-entrypoint.sh kong docker-start'
|
| 685 |
+
ports:
|
| 686 |
+
- \${KONG_HTTP_PORT}:8000/tcp
|
| 687 |
+
- \${KONG_HTTPS_PORT}:8443/tcp
|
| 688 |
+
depends_on:
|
| 689 |
+
analytics:
|
| 690 |
+
condition: service_healthy
|
| 691 |
+
environment:
|
| 692 |
+
KONG_DATABASE: "off"
|
| 693 |
+
KONG_DECLARATIVE_CONFIG: /home/kong/kong.yml
|
| 694 |
+
KONG_DNS_ORDER: LAST,A,CNAME
|
| 695 |
+
KONG_PLUGINS: request-transformer,cors,key-auth,acl,basic-auth
|
| 696 |
+
KONG_NGINX_PROXY_PROXY_BUFFER_SIZE: 160k
|
| 697 |
+
KONG_NGINX_PROXY_PROXY_BUFFERS: 64 160k
|
| 698 |
+
SUPABASE_ANON_KEY: \${ANON_KEY}
|
| 699 |
+
SUPABASE_SERVICE_KEY: \${SERVICE_ROLE_KEY}
|
| 700 |
+
DASHBOARD_USERNAME: \${DASHBOARD_USERNAME}
|
| 701 |
+
DASHBOARD_PASSWORD: \${DASHBOARD_PASSWORD}
|
| 702 |
+
volumes:
|
| 703 |
+
- ./volumes/api/kong.yml:/home/kong/temp.yml:ro
|
| 704 |
+
|
| 705 |
+
auth:
|
| 706 |
+
container_name: supabase-auth
|
| 707 |
+
image: supabase/gotrue:v2.151.0
|
| 708 |
+
depends_on:
|
| 709 |
+
db:
|
| 710 |
+
condition: service_healthy
|
| 711 |
+
analytics:
|
| 712 |
+
condition: service_healthy
|
| 713 |
+
healthcheck:
|
| 714 |
+
test:
|
| 715 |
+
[
|
| 716 |
+
"CMD",
|
| 717 |
+
"wget",
|
| 718 |
+
"--no-verbose",
|
| 719 |
+
"--tries=1",
|
| 720 |
+
"--spider",
|
| 721 |
+
"http://localhost:9999/health"
|
| 722 |
+
]
|
| 723 |
+
timeout: 5s
|
| 724 |
+
interval: 5s
|
| 725 |
+
retries: 3
|
| 726 |
+
restart: unless-stopped
|
| 727 |
+
environment:
|
| 728 |
+
GOTRUE_API_HOST: 0.0.0.0
|
| 729 |
+
GOTRUE_API_PORT: 9999
|
| 730 |
+
API_EXTERNAL_URL: \${API_EXTERNAL_URL}
|
| 731 |
+
GOTRUE_DB_DRIVER: postgres
|
| 732 |
+
GOTRUE_DB_DATABASE_URL: postgres://supabase_auth_admin:\${POSTGRES_PASSWORD}@\${POSTGRES_HOST}:\${POSTGRES_PORT}/\${POSTGRES_DB}
|
| 733 |
+
GOTRUE_SITE_URL: \${SITE_URL}
|
| 734 |
+
GOTRUE_URI_ALLOW_LIST: \${ADDITIONAL_REDIRECT_URLS}
|
| 735 |
+
GOTRUE_DISABLE_SIGNUP: \${DISABLE_SIGNUP}
|
| 736 |
+
GOTRUE_JWT_ADMIN_ROLES: service_role
|
| 737 |
+
GOTRUE_JWT_AUD: authenticated
|
| 738 |
+
GOTRUE_JWT_DEFAULT_GROUP_NAME: authenticated
|
| 739 |
+
GOTRUE_JWT_EXP: \${JWT_EXPIRY}
|
| 740 |
+
GOTRUE_JWT_SECRET: \${JWT_SECRET}
|
| 741 |
+
GOTRUE_EXTERNAL_EMAIL_ENABLED: \${ENABLE_EMAIL_SIGNUP}
|
| 742 |
+
GOTRUE_EXTERNAL_ANONYMOUS_USERS_ENABLED: \${ENABLE_ANONYMOUS_USERS}
|
| 743 |
+
GOTRUE_MAILER_AUTOCONFIRM: \${ENABLE_EMAIL_AUTOCONFIRM}
|
| 744 |
+
GOTRUE_SMTP_ADMIN_EMAIL: \${SMTP_ADMIN_EMAIL}
|
| 745 |
+
GOTRUE_SMTP_HOST: \${SMTP_HOST}
|
| 746 |
+
GOTRUE_SMTP_PORT: \${SMTP_PORT}
|
| 747 |
+
GOTRUE_SMTP_USER: \${SMTP_USER}
|
| 748 |
+
GOTRUE_SMTP_PASS: \${SMTP_PASS}
|
| 749 |
+
GOTRUE_SMTP_SENDER_NAME: \${SMTP_SENDER_NAME}
|
| 750 |
+
GOTRUE_MAILER_URLPATHS_INVITE: \${MAILER_URLPATHS_INVITE}
|
| 751 |
+
GOTRUE_MAILER_URLPATHS_CONFIRMATION: \${MAILER_URLPATHS_CONFIRMATION}
|
| 752 |
+
GOTRUE_MAILER_URLPATHS_RECOVERY: \${MAILER_URLPATHS_RECOVERY}
|
| 753 |
+
GOTRUE_MAILER_URLPATHS_EMAIL_CHANGE: \${MAILER_URLPATHS_EMAIL_CHANGE}
|
| 754 |
+
GOTRUE_EXTERNAL_PHONE_ENABLED: \${ENABLE_PHONE_SIGNUP}
|
| 755 |
+
GOTRUE_SMS_AUTOCONFIRM: \${ENABLE_PHONE_AUTOCONFIRM}
|
| 756 |
+
|
| 757 |
+
rest:
|
| 758 |
+
container_name: supabase-rest
|
| 759 |
+
image: postgrest/postgrest:v12.0.1
|
| 760 |
+
depends_on:
|
| 761 |
+
db:
|
| 762 |
+
condition: service_healthy
|
| 763 |
+
analytics:
|
| 764 |
+
condition: service_healthy
|
| 765 |
+
restart: unless-stopped
|
| 766 |
+
environment:
|
| 767 |
+
PGRST_DB_URI: postgres://authenticator:\${POSTGRES_PASSWORD}@\${POSTGRES_HOST}:\${POSTGRES_PORT}/\${POSTGRES_DB}
|
| 768 |
+
PGRST_DB_SCHEMAS: \${PGRST_DB_SCHEMAS}
|
| 769 |
+
PGRST_DB_ANON_ROLE: anon
|
| 770 |
+
PGRST_JWT_SECRET: \${JWT_SECRET}
|
| 771 |
+
PGRST_DB_USE_LEGACY_GUCS: "false"
|
| 772 |
+
PGRST_APP_SETTINGS_JWT_SECRET: \${JWT_SECRET}
|
| 773 |
+
PGRST_APP_SETTINGS_JWT_EXP: \${JWT_EXPIRY}
|
| 774 |
+
command: "postgrest"
|
| 775 |
+
|
| 776 |
+
realtime:
|
| 777 |
+
container_name: realtime-dev.supabase-realtime
|
| 778 |
+
image: supabase/realtime:v2.28.32
|
| 779 |
+
depends_on:
|
| 780 |
+
db:
|
| 781 |
+
condition: service_healthy
|
| 782 |
+
analytics:
|
| 783 |
+
condition: service_healthy
|
| 784 |
+
healthcheck:
|
| 785 |
+
test:
|
| 786 |
+
[
|
| 787 |
+
"CMD",
|
| 788 |
+
"curl",
|
| 789 |
+
"-sSfL",
|
| 790 |
+
"--head",
|
| 791 |
+
"-o",
|
| 792 |
+
"/dev/null",
|
| 793 |
+
"-H",
|
| 794 |
+
"Authorization: Bearer \${ANON_KEY}",
|
| 795 |
+
"http://localhost:4000/api/tenants/realtime-dev/health"
|
| 796 |
+
]
|
| 797 |
+
timeout: 5s
|
| 798 |
+
interval: 5s
|
| 799 |
+
retries: 3
|
| 800 |
+
restart: unless-stopped
|
| 801 |
+
environment:
|
| 802 |
+
PORT: 4000
|
| 803 |
+
DB_HOST: \${POSTGRES_HOST}
|
| 804 |
+
DB_PORT: \${POSTGRES_PORT}
|
| 805 |
+
DB_USER: supabase_admin
|
| 806 |
+
DB_PASSWORD: \${POSTGRES_PASSWORD}
|
| 807 |
+
DB_NAME: \${POSTGRES_DB}
|
| 808 |
+
DB_AFTER_CONNECT_QUERY: 'SET search_path TO _realtime'
|
| 809 |
+
DB_ENC_KEY: supabaserealtime
|
| 810 |
+
API_JWT_SECRET: \${JWT_SECRET}
|
| 811 |
+
FLY_ALLOC_ID: fly123
|
| 812 |
+
FLY_APP_NAME: realtime
|
| 813 |
+
SECRET_KEY_BASE: UpNVntn3cDxHJpq99YMc1T1AQgQpc8kfYTuRgBiYa15BLrx8etQoXz3gZv1/u2oq
|
| 814 |
+
ERL_AFLAGS: -proto_dist inet_tcp
|
| 815 |
+
ENABLE_TAILSCALE: "false"
|
| 816 |
+
DNS_NODES: "''"
|
| 817 |
+
command: >
|
| 818 |
+
sh -c "/app/bin/migrate && /app/bin/realtime eval 'Realtime.Release.seeds(Realtime.Repo)' && /app/bin/server"
|
| 819 |
+
|
| 820 |
+
storage:
|
| 821 |
+
container_name: supabase-storage
|
| 822 |
+
image: supabase/storage-api:v1.0.6
|
| 823 |
+
depends_on:
|
| 824 |
+
db:
|
| 825 |
+
condition: service_healthy
|
| 826 |
+
rest:
|
| 827 |
+
condition: service_started
|
| 828 |
+
imgproxy:
|
| 829 |
+
condition: service_started
|
| 830 |
+
healthcheck:
|
| 831 |
+
test:
|
| 832 |
+
[
|
| 833 |
+
"CMD",
|
| 834 |
+
"wget",
|
| 835 |
+
"--no-verbose",
|
| 836 |
+
"--tries=1",
|
| 837 |
+
"--spider",
|
| 838 |
+
"http://localhost:5000/status"
|
| 839 |
+
]
|
| 840 |
+
timeout: 5s
|
| 841 |
+
interval: 5s
|
| 842 |
+
retries: 3
|
| 843 |
+
restart: unless-stopped
|
| 844 |
+
environment:
|
| 845 |
+
ANON_KEY: \${ANON_KEY}
|
| 846 |
+
SERVICE_KEY: \${SERVICE_ROLE_KEY}
|
| 847 |
+
POSTGREST_URL: http://rest:3000
|
| 848 |
+
PGRST_JWT_SECRET: \${JWT_SECRET}
|
| 849 |
+
DATABASE_URL: postgres://supabase_storage_admin:\${POSTGRES_PASSWORD}@\${POSTGRES_HOST}:\${POSTGRES_PORT}/\${POSTGRES_DB}
|
| 850 |
+
FILE_SIZE_LIMIT: 52428800
|
| 851 |
+
STORAGE_BACKEND: file
|
| 852 |
+
FILE_STORAGE_BACKEND_PATH: /var/lib/storage
|
| 853 |
+
TENANT_ID: stub
|
| 854 |
+
REGION: stub
|
| 855 |
+
GLOBAL_S3_BUCKET: stub
|
| 856 |
+
ENABLE_IMAGE_TRANSFORMATION: "true"
|
| 857 |
+
IMGPROXY_URL: http://imgproxy:5001
|
| 858 |
+
volumes:
|
| 859 |
+
- ./volumes/storage:/var/lib/storage:z
|
| 860 |
+
|
| 861 |
+
imgproxy:
|
| 862 |
+
container_name: supabase-imgproxy
|
| 863 |
+
image: darthsim/imgproxy:v3.8.0
|
| 864 |
+
healthcheck:
|
| 865 |
+
test: [ "CMD", "imgproxy", "health" ]
|
| 866 |
+
timeout: 5s
|
| 867 |
+
interval: 5s
|
| 868 |
+
retries: 3
|
| 869 |
+
environment:
|
| 870 |
+
IMGPROXY_BIND: ":5001"
|
| 871 |
+
IMGPROXY_LOCAL_FILESYSTEM_ROOT: /
|
| 872 |
+
IMGPROXY_USE_ETAG: "true"
|
| 873 |
+
IMGPROXY_ENABLE_WEBP_DETECTION: \${IMGPROXY_ENABLE_WEBP_DETECTION}
|
| 874 |
+
volumes:
|
| 875 |
+
- ./volumes/storage:/var/lib/storage:z
|
| 876 |
+
|
| 877 |
+
meta:
|
| 878 |
+
container_name: supabase-meta
|
| 879 |
+
image: supabase/postgres-meta:v0.80.0
|
| 880 |
+
depends_on:
|
| 881 |
+
db:
|
| 882 |
+
condition: service_healthy
|
| 883 |
+
analytics:
|
| 884 |
+
condition: service_healthy
|
| 885 |
+
restart: unless-stopped
|
| 886 |
+
environment:
|
| 887 |
+
PG_META_PORT: 8080
|
| 888 |
+
PG_META_DB_HOST: \${POSTGRES_HOST}
|
| 889 |
+
PG_META_DB_PORT: \${POSTGRES_PORT}
|
| 890 |
+
PG_META_DB_NAME: \${POSTGRES_DB}
|
| 891 |
+
PG_META_DB_USER: supabase_admin
|
| 892 |
+
PG_META_DB_PASSWORD: \${POSTGRES_PASSWORD}
|
| 893 |
+
|
| 894 |
+
functions:
|
| 895 |
+
container_name: supabase-edge-functions
|
| 896 |
+
image: supabase/edge-runtime:v1.45.2
|
| 897 |
+
restart: unless-stopped
|
| 898 |
+
depends_on:
|
| 899 |
+
analytics:
|
| 900 |
+
condition: service_healthy
|
| 901 |
+
environment:
|
| 902 |
+
JWT_SECRET: \${JWT_SECRET}
|
| 903 |
+
SUPABASE_URL: http://kong:8000
|
| 904 |
+
SUPABASE_ANON_KEY: \${ANON_KEY}
|
| 905 |
+
SUPABASE_SERVICE_ROLE_KEY: \${SERVICE_ROLE_KEY}
|
| 906 |
+
SUPABASE_DB_URL: postgresql://postgres:\${POSTGRES_PASSWORD}@\${POSTGRES_HOST}:\${POSTGRES_PORT}/\${POSTGRES_DB}
|
| 907 |
+
VERIFY_JWT: "\${FUNCTIONS_VERIFY_JWT}"
|
| 908 |
+
volumes:
|
| 909 |
+
- ./volumes/functions:/home/deno/functions:Z
|
| 910 |
+
command:
|
| 911 |
+
- start
|
| 912 |
+
- --main-service
|
| 913 |
+
- /home/deno/functions/main
|
| 914 |
+
|
| 915 |
+
analytics:
|
| 916 |
+
container_name: supabase-analytics
|
| 917 |
+
image: supabase/logflare:1.4.0
|
| 918 |
+
healthcheck:
|
| 919 |
+
test: [ "CMD", "curl", "http://localhost:4000/health" ]
|
| 920 |
+
timeout: 5s
|
| 921 |
+
interval: 5s
|
| 922 |
+
retries: 10
|
| 923 |
+
restart: unless-stopped
|
| 924 |
+
depends_on:
|
| 925 |
+
db:
|
| 926 |
+
condition: service_healthy
|
| 927 |
+
environment:
|
| 928 |
+
LOGFLARE_NODE_HOST: 127.0.0.1
|
| 929 |
+
DB_USERNAME: supabase_admin
|
| 930 |
+
DB_DATABASE: \${POSTGRES_DB}
|
| 931 |
+
DB_HOSTNAME: \${POSTGRES_HOST}
|
| 932 |
+
DB_PORT: \${POSTGRES_PORT}
|
| 933 |
+
DB_PASSWORD: \${POSTGRES_PASSWORD}
|
| 934 |
+
DB_SCHEMA: _analytics
|
| 935 |
+
LOGFLARE_API_KEY: \${LOGFLARE_API_KEY}
|
| 936 |
+
LOGFLARE_SINGLE_TENANT: true
|
| 937 |
+
LOGFLARE_SUPABASE_MODE: true
|
| 938 |
+
LOGFLARE_MIN_CLUSTER_SIZE: 1
|
| 939 |
+
POSTGRES_BACKEND_URL: postgresql://supabase_admin:\${POSTGRES_PASSWORD}@\${POSTGRES_HOST}:\${POSTGRES_PORT}/\${POSTGRES_DB}
|
| 940 |
+
POSTGRES_BACKEND_SCHEMA: _analytics
|
| 941 |
+
LOGFLARE_FEATURE_FLAG_OVERRIDE: multibackend=true
|
| 942 |
+
ports:
|
| 943 |
+
- 4000:4000
|
| 944 |
+
|
| 945 |
+
db:
|
| 946 |
+
container_name: supabase-db
|
| 947 |
+
image: supabase/postgres:15.1.1.41
|
| 948 |
+
healthcheck:
|
| 949 |
+
test: pg_isready -U postgres -h localhost
|
| 950 |
+
interval: 5s
|
| 951 |
+
timeout: 5s
|
| 952 |
+
retries: 10
|
| 953 |
+
depends_on:
|
| 954 |
+
vector:
|
| 955 |
+
condition: service_healthy
|
| 956 |
+
command:
|
| 957 |
+
- postgres
|
| 958 |
+
- -c
|
| 959 |
+
- config_file=/etc/postgresql/postgresql.conf
|
| 960 |
+
- -c
|
| 961 |
+
- log_min_messages=fatal
|
| 962 |
+
restart: unless-stopped
|
| 963 |
+
ports:
|
| 964 |
+
- \${POSTGRES_PORT}:\${POSTGRES_PORT}
|
| 965 |
+
environment:
|
| 966 |
+
POSTGRES_HOST: /var/run/postgresql
|
| 967 |
+
PGPORT: \${POSTGRES_PORT}
|
| 968 |
+
POSTGRES_PORT: \${POSTGRES_PORT}
|
| 969 |
+
PGPASSWORD: \${POSTGRES_PASSWORD}
|
| 970 |
+
POSTGRES_PASSWORD: \${POSTGRES_PASSWORD}
|
| 971 |
+
PGDATABASE: \${POSTGRES_DB}
|
| 972 |
+
POSTGRES_DB: \${POSTGRES_DB}
|
| 973 |
+
JWT_SECRET: \${JWT_SECRET}
|
| 974 |
+
JWT_EXP: \${JWT_EXPIRY}
|
| 975 |
+
volumes:
|
| 976 |
+
- ./volumes/db/realtime.sql:/docker-entrypoint-initdb.d/migrations/99-realtime.sql:Z
|
| 977 |
+
- ./volumes/db/webhooks.sql:/docker-entrypoint-initdb.d/init-scripts/98-webhooks.sql:Z
|
| 978 |
+
- ./volumes/db/roles.sql:/docker-entrypoint-initdb.d/init-scripts/99-roles.sql:Z
|
| 979 |
+
- ./volumes/db/jwt.sql:/docker-entrypoint-initdb.d/init-scripts/99-jwt.sql:Z
|
| 980 |
+
- ./volumes/db/data:/var/lib/postgresql/data:Z
|
| 981 |
+
- ./volumes/db/logs.sql:/docker-entrypoint-initdb.d/migrations/99-logs.sql:Z
|
| 982 |
+
- db-config-testhash:/etc/postgresql-custom
|
| 983 |
+
|
| 984 |
+
vector:
|
| 985 |
+
container_name: supabase-vector
|
| 986 |
+
image: timberio/vector:0.28.1-alpine
|
| 987 |
+
healthcheck:
|
| 988 |
+
test:
|
| 989 |
+
[
|
| 990 |
+
"CMD",
|
| 991 |
+
"wget",
|
| 992 |
+
"--no-verbose",
|
| 993 |
+
"--tries=1",
|
| 994 |
+
"--spider",
|
| 995 |
+
"http://vector:9001/health"
|
| 996 |
+
]
|
| 997 |
+
timeout: 5s
|
| 998 |
+
interval: 5s
|
| 999 |
+
retries: 3
|
| 1000 |
+
volumes:
|
| 1001 |
+
- ./volumes/logs/vector.yml:/etc/vector/vector.yml:ro
|
| 1002 |
+
- \${DOCKER_SOCKET_LOCATION}:/var/run/docker.sock:ro
|
| 1003 |
+
environment:
|
| 1004 |
+
LOGFLARE_API_KEY: \${LOGFLARE_API_KEY}
|
| 1005 |
+
command: [ "--config", "etc/vector/vector.yml" ]
|
| 1006 |
+
|
| 1007 |
+
volumes:
|
| 1008 |
+
db-config-testhash:
|
| 1009 |
+
`);
|
| 1010 |
+
|
| 1011 |
+
test("Expect to change the suffix in all the possible places (4 Try)", () => {
|
| 1012 |
+
const composeData = load(composeFileComplex) as ComposeSpecification;
|
| 1013 |
+
const suffix = "testhash";
|
| 1014 |
+
|
| 1015 |
+
const updatedComposeData = addSuffixToAllVolumes(composeData, suffix);
|
| 1016 |
+
|
| 1017 |
+
expect(updatedComposeData).toEqual(expectedDockerComposeComplex);
|
| 1018 |
+
});
|
| 1019 |
+
|
| 1020 |
+
const composeFileExample1 = `
|
| 1021 |
+
version: "3.8"
|
| 1022 |
+
services:
|
| 1023 |
+
web:
|
| 1024 |
+
image: nginx:latest
|
| 1025 |
+
ports:
|
| 1026 |
+
- "80:80"
|
| 1027 |
+
networks:
|
| 1028 |
+
- frontend
|
| 1029 |
+
volumes:
|
| 1030 |
+
- web-data:/var/www/html
|
| 1031 |
+
- ./nginx.conf:/etc/nginx/nginx.conf:ro
|
| 1032 |
+
|
| 1033 |
+
app:
|
| 1034 |
+
image: node:14
|
| 1035 |
+
depends_on:
|
| 1036 |
+
- db
|
| 1037 |
+
networks:
|
| 1038 |
+
- backend
|
| 1039 |
+
- frontend
|
| 1040 |
+
volumes:
|
| 1041 |
+
- app-data:/usr/src/app
|
| 1042 |
+
- ./src:/usr/src/app/src
|
| 1043 |
+
|
| 1044 |
+
db:
|
| 1045 |
+
image: postgres:13
|
| 1046 |
+
environment:
|
| 1047 |
+
POSTGRES_PASSWORD: example
|
| 1048 |
+
networks:
|
| 1049 |
+
- backend
|
| 1050 |
+
volumes:
|
| 1051 |
+
- db-data:/var/lib/postgresql/data
|
| 1052 |
+
|
| 1053 |
+
networks:
|
| 1054 |
+
frontend:
|
| 1055 |
+
driver: bridge
|
| 1056 |
+
backend:
|
| 1057 |
+
driver: bridge
|
| 1058 |
+
|
| 1059 |
+
volumes:
|
| 1060 |
+
web-data:
|
| 1061 |
+
app-data:
|
| 1062 |
+
db-data:
|
| 1063 |
+
`;
|
| 1064 |
+
|
| 1065 |
+
const expectedDockerComposeExample1 = load(`
|
| 1066 |
+
version: "3.8"
|
| 1067 |
+
services:
|
| 1068 |
+
web:
|
| 1069 |
+
image: nginx:latest
|
| 1070 |
+
ports:
|
| 1071 |
+
- "80:80"
|
| 1072 |
+
networks:
|
| 1073 |
+
- frontend
|
| 1074 |
+
volumes:
|
| 1075 |
+
- web-data-testhash:/var/www/html
|
| 1076 |
+
- ./nginx.conf:/etc/nginx/nginx.conf:ro
|
| 1077 |
+
|
| 1078 |
+
app:
|
| 1079 |
+
image: node:14
|
| 1080 |
+
depends_on:
|
| 1081 |
+
- db
|
| 1082 |
+
networks:
|
| 1083 |
+
- backend
|
| 1084 |
+
- frontend
|
| 1085 |
+
volumes:
|
| 1086 |
+
- app-data-testhash:/usr/src/app
|
| 1087 |
+
- ./src:/usr/src/app/src
|
| 1088 |
+
|
| 1089 |
+
db:
|
| 1090 |
+
image: postgres:13
|
| 1091 |
+
environment:
|
| 1092 |
+
POSTGRES_PASSWORD: example
|
| 1093 |
+
networks:
|
| 1094 |
+
- backend
|
| 1095 |
+
volumes:
|
| 1096 |
+
- db-data-testhash:/var/lib/postgresql/data
|
| 1097 |
+
|
| 1098 |
+
networks:
|
| 1099 |
+
frontend:
|
| 1100 |
+
driver: bridge
|
| 1101 |
+
backend:
|
| 1102 |
+
driver: bridge
|
| 1103 |
+
|
| 1104 |
+
volumes:
|
| 1105 |
+
web-data-testhash:
|
| 1106 |
+
app-data-testhash:
|
| 1107 |
+
db-data-testhash:
|
| 1108 |
+
`) as ComposeSpecification;
|
| 1109 |
+
|
| 1110 |
+
test("Expect to change the suffix in all the possible places (5 Try)", () => {
|
| 1111 |
+
const composeData = load(composeFileExample1) as ComposeSpecification;
|
| 1112 |
+
const suffix = "testhash";
|
| 1113 |
+
|
| 1114 |
+
const updatedComposeData = addSuffixToAllVolumes(composeData, suffix);
|
| 1115 |
+
|
| 1116 |
+
expect(updatedComposeData).toEqual(expectedDockerComposeExample1);
|
| 1117 |
+
});
|
| 1118 |
+
|
| 1119 |
+
const composeFileBackrest = `
|
| 1120 |
+
services:
|
| 1121 |
+
backrest:
|
| 1122 |
+
image: garethgeorge/backrest:v1.7.3
|
| 1123 |
+
restart: unless-stopped
|
| 1124 |
+
ports:
|
| 1125 |
+
- 9898
|
| 1126 |
+
environment:
|
| 1127 |
+
- BACKREST_PORT=9898
|
| 1128 |
+
- BACKREST_DATA=/data
|
| 1129 |
+
- BACKREST_CONFIG=/config/config.json
|
| 1130 |
+
- XDG_CACHE_HOME=/cache
|
| 1131 |
+
- TZ=\${TZ}
|
| 1132 |
+
volumes:
|
| 1133 |
+
- backrest/data:/data
|
| 1134 |
+
- backrest/config:/config
|
| 1135 |
+
- backrest/cache:/cache
|
| 1136 |
+
- /:/userdata:ro
|
| 1137 |
+
|
| 1138 |
+
volumes:
|
| 1139 |
+
backrest:
|
| 1140 |
+
backrest-cache:
|
| 1141 |
+
`;
|
| 1142 |
+
|
| 1143 |
+
const expectedDockerComposeBackrest = load(`
|
| 1144 |
+
services:
|
| 1145 |
+
backrest:
|
| 1146 |
+
image: garethgeorge/backrest:v1.7.3
|
| 1147 |
+
restart: unless-stopped
|
| 1148 |
+
ports:
|
| 1149 |
+
- 9898
|
| 1150 |
+
environment:
|
| 1151 |
+
- BACKREST_PORT=9898
|
| 1152 |
+
- BACKREST_DATA=/data
|
| 1153 |
+
- BACKREST_CONFIG=/config/config.json
|
| 1154 |
+
- XDG_CACHE_HOME=/cache
|
| 1155 |
+
- TZ=\${TZ}
|
| 1156 |
+
volumes:
|
| 1157 |
+
- backrest-testhash/data:/data
|
| 1158 |
+
- backrest-testhash/config:/config
|
| 1159 |
+
- backrest-testhash/cache:/cache
|
| 1160 |
+
- /:/userdata:ro
|
| 1161 |
+
|
| 1162 |
+
volumes:
|
| 1163 |
+
backrest-testhash:
|
| 1164 |
+
backrest-cache-testhash:
|
| 1165 |
+
`) as ComposeSpecification;
|
| 1166 |
+
|
| 1167 |
+
test("Should handle volume paths with subdirectories correctly", () => {
|
| 1168 |
+
const composeData = load(composeFileBackrest) as ComposeSpecification;
|
| 1169 |
+
const suffix = "testhash";
|
| 1170 |
+
|
| 1171 |
+
const updatedComposeData = addSuffixToAllVolumes(composeData, suffix);
|
| 1172 |
+
|
| 1173 |
+
expect(updatedComposeData).toEqual(expectedDockerComposeBackrest);
|
| 1174 |
+
});
|
data/apps/dokploy/__test__/compose/volume/volume-root.test.ts
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { generateRandomHash } from "@dokploy/server";
|
| 2 |
+
import { addSuffixToVolumesRoot } from "@dokploy/server";
|
| 3 |
+
import type { ComposeSpecification } from "@dokploy/server";
|
| 4 |
+
import { load } from "js-yaml";
|
| 5 |
+
import { expect, test } from "vitest";
|
| 6 |
+
|
| 7 |
+
const composeFile = `
|
| 8 |
+
version: "3.8"
|
| 9 |
+
|
| 10 |
+
services:
|
| 11 |
+
web:
|
| 12 |
+
image: nginx:latest
|
| 13 |
+
volumes:
|
| 14 |
+
- web_data:/var/lib/nginx/data
|
| 15 |
+
|
| 16 |
+
volumes:
|
| 17 |
+
web_data:
|
| 18 |
+
driver: local
|
| 19 |
+
|
| 20 |
+
networks:
|
| 21 |
+
default:
|
| 22 |
+
driver: bridge
|
| 23 |
+
`;
|
| 24 |
+
|
| 25 |
+
test("Generate random hash with 8 characters", () => {
|
| 26 |
+
const hash = generateRandomHash();
|
| 27 |
+
|
| 28 |
+
expect(hash).toBeDefined();
|
| 29 |
+
expect(hash.length).toBe(8);
|
| 30 |
+
});
|
| 31 |
+
|
| 32 |
+
test("Add suffix to volumes in root property", () => {
|
| 33 |
+
const composeData = load(composeFile) as ComposeSpecification;
|
| 34 |
+
|
| 35 |
+
const suffix = generateRandomHash();
|
| 36 |
+
|
| 37 |
+
if (!composeData?.volumes) {
|
| 38 |
+
return;
|
| 39 |
+
}
|
| 40 |
+
const volumes = addSuffixToVolumesRoot(composeData.volumes, suffix);
|
| 41 |
+
expect(volumes).toBeDefined();
|
| 42 |
+
for (const volumeKey of Object.keys(volumes)) {
|
| 43 |
+
expect(volumeKey).toContain(`-${suffix}`);
|
| 44 |
+
expect(volumes[volumeKey]).toBeDefined();
|
| 45 |
+
}
|
| 46 |
+
});
|
| 47 |
+
|
| 48 |
+
const composeFile2 = `
|
| 49 |
+
version: "3.8"
|
| 50 |
+
|
| 51 |
+
services:
|
| 52 |
+
app:
|
| 53 |
+
image: node:latest
|
| 54 |
+
volumes:
|
| 55 |
+
- app_data:/var/lib/app/data
|
| 56 |
+
|
| 57 |
+
volumes:
|
| 58 |
+
app_data:
|
| 59 |
+
driver: local
|
| 60 |
+
driver_opts:
|
| 61 |
+
type: nfs
|
| 62 |
+
o: addr=10.0.0.1,rw
|
| 63 |
+
device: ":/exported/path"
|
| 64 |
+
|
| 65 |
+
networks:
|
| 66 |
+
default:
|
| 67 |
+
driver: bridge
|
| 68 |
+
`;
|
| 69 |
+
|
| 70 |
+
test("Add suffix to volumes in root property (Case 2)", () => {
|
| 71 |
+
const composeData = load(composeFile2) as ComposeSpecification;
|
| 72 |
+
|
| 73 |
+
const suffix = generateRandomHash();
|
| 74 |
+
|
| 75 |
+
if (!composeData?.volumes) {
|
| 76 |
+
return;
|
| 77 |
+
}
|
| 78 |
+
const volumes = addSuffixToVolumesRoot(composeData.volumes, suffix);
|
| 79 |
+
expect(volumes).toBeDefined();
|
| 80 |
+
for (const volumeKey of Object.keys(volumes)) {
|
| 81 |
+
expect(volumeKey).toContain(`-${suffix}`);
|
| 82 |
+
expect(volumes[volumeKey]).toBeDefined();
|
| 83 |
+
}
|
| 84 |
+
});
|
| 85 |
+
|
| 86 |
+
const composeFile3 = `
|
| 87 |
+
version: "3.8"
|
| 88 |
+
|
| 89 |
+
services:
|
| 90 |
+
db:
|
| 91 |
+
image: postgres:latest
|
| 92 |
+
volumes:
|
| 93 |
+
- db_data:/var/lib/postgresql/data
|
| 94 |
+
|
| 95 |
+
volumes:
|
| 96 |
+
db_data:
|
| 97 |
+
external: true
|
| 98 |
+
|
| 99 |
+
networks:
|
| 100 |
+
default:
|
| 101 |
+
driver: bridge
|
| 102 |
+
`;
|
| 103 |
+
|
| 104 |
+
test("Add suffix to volumes in root property (Case 3)", () => {
|
| 105 |
+
const composeData = load(composeFile3) as ComposeSpecification;
|
| 106 |
+
|
| 107 |
+
const suffix = generateRandomHash();
|
| 108 |
+
|
| 109 |
+
if (!composeData?.volumes) {
|
| 110 |
+
return;
|
| 111 |
+
}
|
| 112 |
+
const volumes = addSuffixToVolumesRoot(composeData.volumes, suffix);
|
| 113 |
+
|
| 114 |
+
expect(volumes).toBeDefined();
|
| 115 |
+
for (const volumeKey of Object.keys(volumes)) {
|
| 116 |
+
expect(volumeKey).toContain(`-${suffix}`);
|
| 117 |
+
expect(volumes[volumeKey]).toBeDefined();
|
| 118 |
+
}
|
| 119 |
+
});
|
| 120 |
+
|
| 121 |
+
const composeFile4 = `
|
| 122 |
+
version: "3.8"
|
| 123 |
+
|
| 124 |
+
services:
|
| 125 |
+
web:
|
| 126 |
+
image: nginx:latest
|
| 127 |
+
|
| 128 |
+
app:
|
| 129 |
+
image: node:latest
|
| 130 |
+
|
| 131 |
+
db:
|
| 132 |
+
image: postgres:latest
|
| 133 |
+
|
| 134 |
+
volumes:
|
| 135 |
+
web_data:
|
| 136 |
+
driver: local
|
| 137 |
+
|
| 138 |
+
app_data:
|
| 139 |
+
driver: local
|
| 140 |
+
driver_opts:
|
| 141 |
+
type: nfs
|
| 142 |
+
o: addr=10.0.0.1,rw
|
| 143 |
+
device: ":/exported/path"
|
| 144 |
+
|
| 145 |
+
db_data:
|
| 146 |
+
external: true
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
`;
|
| 150 |
+
|
| 151 |
+
// Expected compose file con el prefijo `testhash`
|
| 152 |
+
const expectedComposeFile4 = load(`
|
| 153 |
+
version: "3.8"
|
| 154 |
+
|
| 155 |
+
services:
|
| 156 |
+
web:
|
| 157 |
+
image: nginx:latest
|
| 158 |
+
|
| 159 |
+
app:
|
| 160 |
+
image: node:latest
|
| 161 |
+
|
| 162 |
+
db:
|
| 163 |
+
image: postgres:latest
|
| 164 |
+
|
| 165 |
+
volumes:
|
| 166 |
+
web_data-testhash:
|
| 167 |
+
driver: local
|
| 168 |
+
|
| 169 |
+
app_data-testhash:
|
| 170 |
+
driver: local
|
| 171 |
+
driver_opts:
|
| 172 |
+
type: nfs
|
| 173 |
+
o: addr=10.0.0.1,rw
|
| 174 |
+
device: ":/exported/path"
|
| 175 |
+
|
| 176 |
+
db_data-testhash:
|
| 177 |
+
external: true
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
`) as ComposeSpecification;
|
| 181 |
+
|
| 182 |
+
test("Add suffix to volumes in root property", () => {
|
| 183 |
+
const composeData = load(composeFile4) as ComposeSpecification;
|
| 184 |
+
|
| 185 |
+
const suffix = "testhash";
|
| 186 |
+
|
| 187 |
+
if (!composeData?.volumes) {
|
| 188 |
+
return;
|
| 189 |
+
}
|
| 190 |
+
const volumes = addSuffixToVolumesRoot(composeData.volumes, suffix);
|
| 191 |
+
const updatedComposeData = { ...composeData, volumes };
|
| 192 |
+
|
| 193 |
+
// Verificar que el resultado coincide con el archivo esperado
|
| 194 |
+
expect(updatedComposeData).toEqual(expectedComposeFile4);
|
| 195 |
+
});
|
data/apps/dokploy/__test__/compose/volume/volume-services.test.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { generateRandomHash } from "@dokploy/server";
|
| 2 |
+
import { addSuffixToVolumesInServices } from "@dokploy/server";
|
| 3 |
+
import type { ComposeSpecification } from "@dokploy/server";
|
| 4 |
+
import { load } from "js-yaml";
|
| 5 |
+
import { expect, test } from "vitest";
|
| 6 |
+
|
| 7 |
+
test("Generate random hash with 8 characters", () => {
|
| 8 |
+
const hash = generateRandomHash();
|
| 9 |
+
|
| 10 |
+
expect(hash).toBeDefined();
|
| 11 |
+
expect(hash.length).toBe(8);
|
| 12 |
+
});
|
| 13 |
+
|
| 14 |
+
const composeFile1 = `
|
| 15 |
+
version: "3.8"
|
| 16 |
+
|
| 17 |
+
services:
|
| 18 |
+
db:
|
| 19 |
+
image: postgres:latest
|
| 20 |
+
volumes:
|
| 21 |
+
- db_data:/var/lib/postgresql/data
|
| 22 |
+
`;
|
| 23 |
+
|
| 24 |
+
test("Add suffix to volumes declared directly in services", () => {
|
| 25 |
+
const composeData = load(composeFile1) as ComposeSpecification;
|
| 26 |
+
|
| 27 |
+
const suffix = generateRandomHash();
|
| 28 |
+
|
| 29 |
+
if (!composeData.services) {
|
| 30 |
+
return;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
const updatedComposeData = addSuffixToVolumesInServices(
|
| 34 |
+
composeData.services,
|
| 35 |
+
suffix,
|
| 36 |
+
);
|
| 37 |
+
const actualComposeData = { ...composeData, services: updatedComposeData };
|
| 38 |
+
expect(actualComposeData.services?.db?.volumes).toContain(
|
| 39 |
+
`db_data-${suffix}:/var/lib/postgresql/data`,
|
| 40 |
+
);
|
| 41 |
+
});
|
| 42 |
+
|
| 43 |
+
const composeFileTypeVolume = `
|
| 44 |
+
version: "3.8"
|
| 45 |
+
|
| 46 |
+
services:
|
| 47 |
+
db:
|
| 48 |
+
image: postgres:latest
|
| 49 |
+
volumes:
|
| 50 |
+
- type: volume
|
| 51 |
+
source: db-test
|
| 52 |
+
target: /var/lib/postgresql/data
|
| 53 |
+
|
| 54 |
+
volumes:
|
| 55 |
+
db-test:
|
| 56 |
+
driver: local
|
| 57 |
+
`;
|
| 58 |
+
|
| 59 |
+
test("Add suffix to volumes declared directly in services (Case 2)", () => {
|
| 60 |
+
const composeData = load(composeFileTypeVolume) as ComposeSpecification;
|
| 61 |
+
|
| 62 |
+
const suffix = generateRandomHash();
|
| 63 |
+
|
| 64 |
+
if (!composeData.services) {
|
| 65 |
+
return;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
const updatedComposeData = addSuffixToVolumesInServices(
|
| 69 |
+
composeData.services,
|
| 70 |
+
suffix,
|
| 71 |
+
);
|
| 72 |
+
const actualComposeData = { ...composeData, services: updatedComposeData };
|
| 73 |
+
|
| 74 |
+
expect(actualComposeData.services?.db?.volumes).toEqual([
|
| 75 |
+
{
|
| 76 |
+
type: "volume",
|
| 77 |
+
source: `db-test-${suffix}`,
|
| 78 |
+
target: "/var/lib/postgresql/data",
|
| 79 |
+
},
|
| 80 |
+
]);
|
| 81 |
+
});
|
data/apps/dokploy/__test__/compose/volume/volume.test.ts
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { addSuffixToAllVolumes } from "@dokploy/server";
|
| 2 |
+
import type { ComposeSpecification } from "@dokploy/server";
|
| 3 |
+
import { load } from "js-yaml";
|
| 4 |
+
import { expect, test } from "vitest";
|
| 5 |
+
|
| 6 |
+
const composeFileTypeVolume = `
|
| 7 |
+
version: "3.8"
|
| 8 |
+
|
| 9 |
+
services:
|
| 10 |
+
db1:
|
| 11 |
+
image: postgres:latest
|
| 12 |
+
volumes:
|
| 13 |
+
- "db-test:/var/lib/postgresql/data"
|
| 14 |
+
db2:
|
| 15 |
+
image: postgres:latest
|
| 16 |
+
volumes:
|
| 17 |
+
- type: volume
|
| 18 |
+
source: db-test
|
| 19 |
+
target: /var/lib/postgresql/data
|
| 20 |
+
|
| 21 |
+
volumes:
|
| 22 |
+
db-test:
|
| 23 |
+
driver: local
|
| 24 |
+
`;
|
| 25 |
+
|
| 26 |
+
const expectedComposeFileTypeVolume = load(`
|
| 27 |
+
version: "3.8"
|
| 28 |
+
|
| 29 |
+
services:
|
| 30 |
+
db1:
|
| 31 |
+
image: postgres:latest
|
| 32 |
+
volumes:
|
| 33 |
+
- "db-test-testhash:/var/lib/postgresql/data"
|
| 34 |
+
db2:
|
| 35 |
+
image: postgres:latest
|
| 36 |
+
volumes:
|
| 37 |
+
- type: volume
|
| 38 |
+
source: db-test-testhash
|
| 39 |
+
target: /var/lib/postgresql/data
|
| 40 |
+
|
| 41 |
+
volumes:
|
| 42 |
+
db-test-testhash:
|
| 43 |
+
driver: local
|
| 44 |
+
`) as ComposeSpecification;
|
| 45 |
+
|
| 46 |
+
test("Add suffix to volumes with type: volume in services", () => {
|
| 47 |
+
const composeData = load(composeFileTypeVolume) as ComposeSpecification;
|
| 48 |
+
|
| 49 |
+
const suffix = "testhash";
|
| 50 |
+
|
| 51 |
+
const updatedComposeData = addSuffixToAllVolumes(composeData, suffix);
|
| 52 |
+
const actualComposeData = { ...composeData, ...updatedComposeData };
|
| 53 |
+
|
| 54 |
+
expect(actualComposeData).toEqual(expectedComposeFileTypeVolume);
|
| 55 |
+
});
|
| 56 |
+
|
| 57 |
+
const composeFileTypeVolume1 = `
|
| 58 |
+
version: "3.8"
|
| 59 |
+
|
| 60 |
+
services:
|
| 61 |
+
web:
|
| 62 |
+
image: nginx:latest
|
| 63 |
+
volumes:
|
| 64 |
+
- "web-data:/var/www/html"
|
| 65 |
+
- type: volume
|
| 66 |
+
source: web-logs
|
| 67 |
+
target: /var/log/nginx
|
| 68 |
+
|
| 69 |
+
volumes:
|
| 70 |
+
web-data:
|
| 71 |
+
driver: local
|
| 72 |
+
web-logs:
|
| 73 |
+
driver: local
|
| 74 |
+
`;
|
| 75 |
+
|
| 76 |
+
const expectedComposeFileTypeVolume1 = load(`
|
| 77 |
+
version: "3.8"
|
| 78 |
+
|
| 79 |
+
services:
|
| 80 |
+
web:
|
| 81 |
+
image: nginx:latest
|
| 82 |
+
volumes:
|
| 83 |
+
- "web-data-testhash:/var/www/html"
|
| 84 |
+
- type: volume
|
| 85 |
+
source: web-logs-testhash
|
| 86 |
+
target: /var/log/nginx
|
| 87 |
+
|
| 88 |
+
volumes:
|
| 89 |
+
web-data-testhash:
|
| 90 |
+
driver: local
|
| 91 |
+
web-logs-testhash:
|
| 92 |
+
driver: local
|
| 93 |
+
`) as ComposeSpecification;
|
| 94 |
+
|
| 95 |
+
test("Add suffix to mixed volumes in services", () => {
|
| 96 |
+
const composeData = load(composeFileTypeVolume1) as ComposeSpecification;
|
| 97 |
+
|
| 98 |
+
const suffix = "testhash";
|
| 99 |
+
|
| 100 |
+
const updatedComposeData = addSuffixToAllVolumes(composeData, suffix);
|
| 101 |
+
const actualComposeData = { ...composeData, ...updatedComposeData };
|
| 102 |
+
|
| 103 |
+
expect(actualComposeData).toEqual(expectedComposeFileTypeVolume1);
|
| 104 |
+
});
|
| 105 |
+
|
| 106 |
+
const composeFileTypeVolume2 = `
|
| 107 |
+
version: "3.8"
|
| 108 |
+
|
| 109 |
+
services:
|
| 110 |
+
app:
|
| 111 |
+
image: node:latest
|
| 112 |
+
volumes:
|
| 113 |
+
- "app-data:/usr/src/app"
|
| 114 |
+
- type: volume
|
| 115 |
+
source: app-logs
|
| 116 |
+
target: /var/log/app
|
| 117 |
+
volume:
|
| 118 |
+
nocopy: true
|
| 119 |
+
|
| 120 |
+
volumes:
|
| 121 |
+
app-data:
|
| 122 |
+
driver: local
|
| 123 |
+
app-logs:
|
| 124 |
+
driver: local
|
| 125 |
+
driver_opts:
|
| 126 |
+
o: bind
|
| 127 |
+
type: none
|
| 128 |
+
device: /path/to/app/logs
|
| 129 |
+
`;
|
| 130 |
+
|
| 131 |
+
const expectedComposeFileTypeVolume2 = load(`
|
| 132 |
+
version: "3.8"
|
| 133 |
+
|
| 134 |
+
services:
|
| 135 |
+
app:
|
| 136 |
+
image: node:latest
|
| 137 |
+
volumes:
|
| 138 |
+
- "app-data-testhash:/usr/src/app"
|
| 139 |
+
- type: volume
|
| 140 |
+
source: app-logs-testhash
|
| 141 |
+
target: /var/log/app
|
| 142 |
+
volume:
|
| 143 |
+
nocopy: true
|
| 144 |
+
|
| 145 |
+
volumes:
|
| 146 |
+
app-data-testhash:
|
| 147 |
+
driver: local
|
| 148 |
+
app-logs-testhash:
|
| 149 |
+
driver: local
|
| 150 |
+
driver_opts:
|
| 151 |
+
o: bind
|
| 152 |
+
type: none
|
| 153 |
+
device: /path/to/app/logs
|
| 154 |
+
`) as ComposeSpecification;
|
| 155 |
+
|
| 156 |
+
test("Add suffix to complex volume configurations in services", () => {
|
| 157 |
+
const composeData = load(composeFileTypeVolume2) as ComposeSpecification;
|
| 158 |
+
|
| 159 |
+
const suffix = "testhash";
|
| 160 |
+
|
| 161 |
+
const updatedComposeData = addSuffixToAllVolumes(composeData, suffix);
|
| 162 |
+
const actualComposeData = { ...composeData, ...updatedComposeData };
|
| 163 |
+
|
| 164 |
+
expect(actualComposeData).toEqual(expectedComposeFileTypeVolume2);
|
| 165 |
+
});
|
| 166 |
+
|
| 167 |
+
const composeFileTypeVolume3 = `
|
| 168 |
+
version: "3.8"
|
| 169 |
+
|
| 170 |
+
services:
|
| 171 |
+
web:
|
| 172 |
+
image: nginx:latest
|
| 173 |
+
volumes:
|
| 174 |
+
- "web-data:/usr/share/nginx/html"
|
| 175 |
+
- type: volume
|
| 176 |
+
source: web-logs
|
| 177 |
+
target: /var/log/nginx
|
| 178 |
+
volume:
|
| 179 |
+
nocopy: true
|
| 180 |
+
|
| 181 |
+
api:
|
| 182 |
+
image: node:latest
|
| 183 |
+
volumes:
|
| 184 |
+
- "api-data:/usr/src/app"
|
| 185 |
+
- type: volume
|
| 186 |
+
source: api-logs
|
| 187 |
+
target: /var/log/app
|
| 188 |
+
volume:
|
| 189 |
+
nocopy: true
|
| 190 |
+
- type: volume
|
| 191 |
+
source: shared-logs
|
| 192 |
+
target: /shared/logs
|
| 193 |
+
|
| 194 |
+
volumes:
|
| 195 |
+
web-data:
|
| 196 |
+
driver: local
|
| 197 |
+
web-logs:
|
| 198 |
+
driver: local
|
| 199 |
+
driver_opts:
|
| 200 |
+
o: bind
|
| 201 |
+
type: none
|
| 202 |
+
device: /path/to/web/logs
|
| 203 |
+
|
| 204 |
+
api-data:
|
| 205 |
+
driver: local
|
| 206 |
+
api-logs:
|
| 207 |
+
driver: local
|
| 208 |
+
driver_opts:
|
| 209 |
+
o: bind
|
| 210 |
+
type: none
|
| 211 |
+
device: /path/to/api/logs
|
| 212 |
+
|
| 213 |
+
shared-logs:
|
| 214 |
+
driver: local
|
| 215 |
+
driver_opts:
|
| 216 |
+
o: bind
|
| 217 |
+
type: none
|
| 218 |
+
device: /path/to/shared/logs
|
| 219 |
+
`;
|
| 220 |
+
|
| 221 |
+
const expectedComposeFileTypeVolume3 = load(`
|
| 222 |
+
version: "3.8"
|
| 223 |
+
|
| 224 |
+
services:
|
| 225 |
+
web:
|
| 226 |
+
image: nginx:latest
|
| 227 |
+
volumes:
|
| 228 |
+
- "web-data-testhash:/usr/share/nginx/html"
|
| 229 |
+
- type: volume
|
| 230 |
+
source: web-logs-testhash
|
| 231 |
+
target: /var/log/nginx
|
| 232 |
+
volume:
|
| 233 |
+
nocopy: true
|
| 234 |
+
|
| 235 |
+
api:
|
| 236 |
+
image: node:latest
|
| 237 |
+
volumes:
|
| 238 |
+
- "api-data-testhash:/usr/src/app"
|
| 239 |
+
- type: volume
|
| 240 |
+
source: api-logs-testhash
|
| 241 |
+
target: /var/log/app
|
| 242 |
+
volume:
|
| 243 |
+
nocopy: true
|
| 244 |
+
- type: volume
|
| 245 |
+
source: shared-logs-testhash
|
| 246 |
+
target: /shared/logs
|
| 247 |
+
|
| 248 |
+
volumes:
|
| 249 |
+
web-data-testhash:
|
| 250 |
+
driver: local
|
| 251 |
+
web-logs-testhash:
|
| 252 |
+
driver: local
|
| 253 |
+
driver_opts:
|
| 254 |
+
o: bind
|
| 255 |
+
type: none
|
| 256 |
+
device: /path/to/web/logs
|
| 257 |
+
|
| 258 |
+
api-data-testhash:
|
| 259 |
+
driver: local
|
| 260 |
+
api-logs-testhash:
|
| 261 |
+
driver: local
|
| 262 |
+
driver_opts:
|
| 263 |
+
o: bind
|
| 264 |
+
type: none
|
| 265 |
+
device: /path/to/api/logs
|
| 266 |
+
|
| 267 |
+
shared-logs-testhash:
|
| 268 |
+
driver: local
|
| 269 |
+
driver_opts:
|
| 270 |
+
o: bind
|
| 271 |
+
type: none
|
| 272 |
+
device: /path/to/shared/logs
|
| 273 |
+
`) as ComposeSpecification;
|
| 274 |
+
|
| 275 |
+
test("Add suffix to complex nested volumes configuration in services", () => {
|
| 276 |
+
const composeData = load(composeFileTypeVolume3) as ComposeSpecification;
|
| 277 |
+
|
| 278 |
+
const suffix = "testhash";
|
| 279 |
+
|
| 280 |
+
const updatedComposeData = addSuffixToAllVolumes(composeData, suffix);
|
| 281 |
+
const actualComposeData = { ...composeData, ...updatedComposeData };
|
| 282 |
+
|
| 283 |
+
expect(actualComposeData).toEqual(expectedComposeFileTypeVolume3);
|
| 284 |
+
});
|
data/apps/dokploy/__test__/deploy/github.test.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { extractCommitMessage } from "@/pages/api/deploy/[refreshToken]";
|
| 2 |
+
import { describe, expect, it } from "vitest";
|
| 3 |
+
|
| 4 |
+
describe("GitHub Webhook Skip CI", () => {
|
| 5 |
+
const mockGithubHeaders = {
|
| 6 |
+
"x-github-event": "push",
|
| 7 |
+
};
|
| 8 |
+
|
| 9 |
+
const createMockBody = (message: string) => ({
|
| 10 |
+
head_commit: {
|
| 11 |
+
message,
|
| 12 |
+
},
|
| 13 |
+
});
|
| 14 |
+
|
| 15 |
+
const skipKeywords = [
|
| 16 |
+
"[skip ci]",
|
| 17 |
+
"[ci skip]",
|
| 18 |
+
"[no ci]",
|
| 19 |
+
"[skip actions]",
|
| 20 |
+
"[actions skip]",
|
| 21 |
+
];
|
| 22 |
+
|
| 23 |
+
it("should detect skip keywords in commit message", () => {
|
| 24 |
+
for (const keyword of skipKeywords) {
|
| 25 |
+
const message = `feat: add new feature ${keyword}`;
|
| 26 |
+
const commitMessage = extractCommitMessage(
|
| 27 |
+
mockGithubHeaders,
|
| 28 |
+
createMockBody(message),
|
| 29 |
+
);
|
| 30 |
+
expect(commitMessage.includes(keyword)).toBe(true);
|
| 31 |
+
}
|
| 32 |
+
});
|
| 33 |
+
|
| 34 |
+
it("should not detect skip keywords in normal commit message", () => {
|
| 35 |
+
const message = "feat: add new feature";
|
| 36 |
+
const commitMessage = extractCommitMessage(
|
| 37 |
+
mockGithubHeaders,
|
| 38 |
+
createMockBody(message),
|
| 39 |
+
);
|
| 40 |
+
for (const keyword of skipKeywords) {
|
| 41 |
+
expect(commitMessage.includes(keyword)).toBe(false);
|
| 42 |
+
}
|
| 43 |
+
});
|
| 44 |
+
|
| 45 |
+
it("should handle different webhook sources", () => {
|
| 46 |
+
// GitHub
|
| 47 |
+
expect(
|
| 48 |
+
extractCommitMessage(
|
| 49 |
+
{ "x-github-event": "push" },
|
| 50 |
+
{ head_commit: { message: "[skip ci] test" } },
|
| 51 |
+
),
|
| 52 |
+
).toBe("[skip ci] test");
|
| 53 |
+
|
| 54 |
+
// GitLab
|
| 55 |
+
expect(
|
| 56 |
+
extractCommitMessage(
|
| 57 |
+
{ "x-gitlab-event": "push" },
|
| 58 |
+
{ commits: [{ message: "[skip ci] test" }] },
|
| 59 |
+
),
|
| 60 |
+
).toBe("[skip ci] test");
|
| 61 |
+
|
| 62 |
+
// Bitbucket
|
| 63 |
+
expect(
|
| 64 |
+
extractCommitMessage(
|
| 65 |
+
{ "x-event-key": "repo:push" },
|
| 66 |
+
{
|
| 67 |
+
push: {
|
| 68 |
+
changes: [{ new: { target: { message: "[skip ci] test" } } }],
|
| 69 |
+
},
|
| 70 |
+
},
|
| 71 |
+
),
|
| 72 |
+
).toBe("[skip ci] test");
|
| 73 |
+
|
| 74 |
+
// Gitea
|
| 75 |
+
expect(
|
| 76 |
+
extractCommitMessage(
|
| 77 |
+
{ "x-gitea-event": "push" },
|
| 78 |
+
{ commits: [{ message: "[skip ci] test" }] },
|
| 79 |
+
),
|
| 80 |
+
).toBe("[skip ci] test");
|
| 81 |
+
});
|
| 82 |
+
|
| 83 |
+
it("should handle missing commit message", () => {
|
| 84 |
+
expect(extractCommitMessage(mockGithubHeaders, {})).toBe("NEW COMMIT");
|
| 85 |
+
expect(extractCommitMessage({ "x-gitlab-event": "push" }, {})).toBe(
|
| 86 |
+
"NEW COMMIT",
|
| 87 |
+
);
|
| 88 |
+
expect(
|
| 89 |
+
extractCommitMessage(
|
| 90 |
+
{ "x-event-key": "repo:push" },
|
| 91 |
+
{ push: { changes: [] } },
|
| 92 |
+
),
|
| 93 |
+
).toBe("NEW COMMIT");
|
| 94 |
+
expect(extractCommitMessage({ "x-gitea-event": "push" }, {})).toBe(
|
| 95 |
+
"NEW COMMIT",
|
| 96 |
+
);
|
| 97 |
+
});
|
| 98 |
+
});
|
data/apps/dokploy/__test__/drop/drop.test.test.ts
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import fs from "node:fs/promises";
|
| 2 |
+
import path from "node:path";
|
| 3 |
+
import { paths } from "@dokploy/server/constants";
|
| 4 |
+
const { APPLICATIONS_PATH } = paths();
|
| 5 |
+
import type { ApplicationNested } from "@dokploy/server";
|
| 6 |
+
import { unzipDrop } from "@dokploy/server";
|
| 7 |
+
import AdmZip from "adm-zip";
|
| 8 |
+
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
|
| 9 |
+
|
| 10 |
+
vi.mock("@dokploy/server/constants", async (importOriginal) => {
|
| 11 |
+
const actual = await importOriginal();
|
| 12 |
+
return {
|
| 13 |
+
// @ts-ignore
|
| 14 |
+
...actual,
|
| 15 |
+
paths: () => ({
|
| 16 |
+
APPLICATIONS_PATH: "./__test__/drop/zips/output",
|
| 17 |
+
}),
|
| 18 |
+
};
|
| 19 |
+
});
|
| 20 |
+
|
| 21 |
+
if (typeof window === "undefined") {
|
| 22 |
+
const undici = require("undici");
|
| 23 |
+
globalThis.File = undici.File as any;
|
| 24 |
+
globalThis.FileList = undici.FileList as any;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
const baseApp: ApplicationNested = {
|
| 28 |
+
applicationId: "",
|
| 29 |
+
herokuVersion: "",
|
| 30 |
+
giteaBranch: "",
|
| 31 |
+
giteaBuildPath: "",
|
| 32 |
+
giteaId: "",
|
| 33 |
+
giteaOwner: "",
|
| 34 |
+
giteaRepository: "",
|
| 35 |
+
cleanCache: false,
|
| 36 |
+
watchPaths: [],
|
| 37 |
+
enableSubmodules: false,
|
| 38 |
+
applicationStatus: "done",
|
| 39 |
+
triggerType: "push",
|
| 40 |
+
appName: "",
|
| 41 |
+
autoDeploy: true,
|
| 42 |
+
serverId: "",
|
| 43 |
+
registryUrl: "",
|
| 44 |
+
branch: null,
|
| 45 |
+
dockerBuildStage: "",
|
| 46 |
+
isPreviewDeploymentsActive: false,
|
| 47 |
+
previewBuildArgs: null,
|
| 48 |
+
previewCertificateType: "none",
|
| 49 |
+
previewCustomCertResolver: null,
|
| 50 |
+
previewEnv: null,
|
| 51 |
+
previewHttps: false,
|
| 52 |
+
previewPath: "/",
|
| 53 |
+
previewPort: 3000,
|
| 54 |
+
previewLimit: 0,
|
| 55 |
+
previewWildcard: "",
|
| 56 |
+
project: {
|
| 57 |
+
env: "",
|
| 58 |
+
organizationId: "",
|
| 59 |
+
name: "",
|
| 60 |
+
description: "",
|
| 61 |
+
createdAt: "",
|
| 62 |
+
projectId: "",
|
| 63 |
+
},
|
| 64 |
+
buildArgs: null,
|
| 65 |
+
buildPath: "/",
|
| 66 |
+
gitlabPathNamespace: "",
|
| 67 |
+
buildType: "nixpacks",
|
| 68 |
+
bitbucketBranch: "",
|
| 69 |
+
bitbucketBuildPath: "",
|
| 70 |
+
bitbucketId: "",
|
| 71 |
+
bitbucketRepository: "",
|
| 72 |
+
bitbucketOwner: "",
|
| 73 |
+
githubId: "",
|
| 74 |
+
gitlabProjectId: 0,
|
| 75 |
+
gitlabBranch: "",
|
| 76 |
+
gitlabBuildPath: "",
|
| 77 |
+
gitlabId: "",
|
| 78 |
+
gitlabRepository: "",
|
| 79 |
+
gitlabOwner: "",
|
| 80 |
+
command: null,
|
| 81 |
+
cpuLimit: null,
|
| 82 |
+
cpuReservation: null,
|
| 83 |
+
createdAt: "",
|
| 84 |
+
customGitBranch: "",
|
| 85 |
+
customGitBuildPath: "",
|
| 86 |
+
customGitSSHKeyId: null,
|
| 87 |
+
customGitUrl: "",
|
| 88 |
+
description: "",
|
| 89 |
+
dockerfile: null,
|
| 90 |
+
dockerImage: null,
|
| 91 |
+
dropBuildPath: null,
|
| 92 |
+
enabled: null,
|
| 93 |
+
env: null,
|
| 94 |
+
healthCheckSwarm: null,
|
| 95 |
+
labelsSwarm: null,
|
| 96 |
+
memoryLimit: null,
|
| 97 |
+
memoryReservation: null,
|
| 98 |
+
modeSwarm: null,
|
| 99 |
+
mounts: [],
|
| 100 |
+
name: "",
|
| 101 |
+
networkSwarm: null,
|
| 102 |
+
owner: null,
|
| 103 |
+
password: null,
|
| 104 |
+
placementSwarm: null,
|
| 105 |
+
ports: [],
|
| 106 |
+
projectId: "",
|
| 107 |
+
publishDirectory: null,
|
| 108 |
+
isStaticSpa: null,
|
| 109 |
+
redirects: [],
|
| 110 |
+
refreshToken: "",
|
| 111 |
+
registry: null,
|
| 112 |
+
registryId: null,
|
| 113 |
+
replicas: 1,
|
| 114 |
+
repository: null,
|
| 115 |
+
restartPolicySwarm: null,
|
| 116 |
+
rollbackConfigSwarm: null,
|
| 117 |
+
security: [],
|
| 118 |
+
sourceType: "git",
|
| 119 |
+
subtitle: null,
|
| 120 |
+
title: null,
|
| 121 |
+
updateConfigSwarm: null,
|
| 122 |
+
username: null,
|
| 123 |
+
dockerContextPath: null,
|
| 124 |
+
};
|
| 125 |
+
|
| 126 |
+
describe("unzipDrop using real zip files", () => {
|
| 127 |
+
// const { APPLICATIONS_PATH } = paths();
|
| 128 |
+
beforeAll(async () => {
|
| 129 |
+
await fs.rm(APPLICATIONS_PATH, { recursive: true, force: true });
|
| 130 |
+
});
|
| 131 |
+
|
| 132 |
+
afterAll(async () => {
|
| 133 |
+
await fs.rm(APPLICATIONS_PATH, { recursive: true, force: true });
|
| 134 |
+
});
|
| 135 |
+
|
| 136 |
+
it("should correctly extract a zip with a single root folder", async () => {
|
| 137 |
+
baseApp.appName = "single-file";
|
| 138 |
+
// const appName = "single-file";
|
| 139 |
+
try {
|
| 140 |
+
const outputPath = path.join(APPLICATIONS_PATH, baseApp.appName, "code");
|
| 141 |
+
const zip = new AdmZip("./__test__/drop/zips/single-file.zip");
|
| 142 |
+
console.log(`Output Path: ${outputPath}`);
|
| 143 |
+
const zipBuffer = zip.toBuffer();
|
| 144 |
+
const file = new File([zipBuffer], "single.zip");
|
| 145 |
+
await unzipDrop(file, baseApp);
|
| 146 |
+
const files = await fs.readdir(outputPath, { withFileTypes: true });
|
| 147 |
+
expect(files.some((f) => f.name === "test.txt")).toBe(true);
|
| 148 |
+
} catch (err) {
|
| 149 |
+
console.log(err);
|
| 150 |
+
} finally {
|
| 151 |
+
}
|
| 152 |
+
});
|
| 153 |
+
});
|
| 154 |
+
|
| 155 |
+
// it("should correctly extract a zip with a single root folder and a subfolder", async () => {
|
| 156 |
+
// baseApp.appName = "folderwithfile";
|
| 157 |
+
// // const appName = "folderwithfile";
|
| 158 |
+
// const outputPath = path.join(APPLICATIONS_PATH, baseApp.appName, "code");
|
| 159 |
+
// const zip = new AdmZip("./__test__/drop/zips/folder-with-file.zip");
|
| 160 |
+
|
| 161 |
+
// const zipBuffer = zip.toBuffer();
|
| 162 |
+
// const file = new File([zipBuffer], "single.zip");
|
| 163 |
+
// await unzipDrop(file, baseApp);
|
| 164 |
+
|
| 165 |
+
// const files = await fs.readdir(outputPath, { withFileTypes: true });
|
| 166 |
+
// expect(files.some((f) => f.name === "folder1.txt")).toBe(true);
|
| 167 |
+
// });
|
| 168 |
+
|
| 169 |
+
// it("should correctly extract a zip with multiple root folders", async () => {
|
| 170 |
+
// baseApp.appName = "two-folders";
|
| 171 |
+
// // const appName = "two-folders";
|
| 172 |
+
// const outputPath = path.join(APPLICATIONS_PATH, baseApp.appName, "code");
|
| 173 |
+
// const zip = new AdmZip("./__test__/drop/zips/two-folders.zip");
|
| 174 |
+
|
| 175 |
+
// const zipBuffer = zip.toBuffer();
|
| 176 |
+
// const file = new File([zipBuffer], "single.zip");
|
| 177 |
+
// await unzipDrop(file, baseApp);
|
| 178 |
+
|
| 179 |
+
// const files = await fs.readdir(outputPath, { withFileTypes: true });
|
| 180 |
+
|
| 181 |
+
// expect(files.some((f) => f.name === "folder1")).toBe(true);
|
| 182 |
+
// expect(files.some((f) => f.name === "folder2")).toBe(true);
|
| 183 |
+
// });
|
| 184 |
+
|
| 185 |
+
// it("should correctly extract a zip with a single root with a file", async () => {
|
| 186 |
+
// baseApp.appName = "nested";
|
| 187 |
+
// // const appName = "nested";
|
| 188 |
+
// const outputPath = path.join(APPLICATIONS_PATH, baseApp.appName, "code");
|
| 189 |
+
// const zip = new AdmZip("./__test__/drop/zips/nested.zip");
|
| 190 |
+
|
| 191 |
+
// const zipBuffer = zip.toBuffer();
|
| 192 |
+
// const file = new File([zipBuffer], "single.zip");
|
| 193 |
+
// await unzipDrop(file, baseApp);
|
| 194 |
+
|
| 195 |
+
// const files = await fs.readdir(outputPath, { withFileTypes: true });
|
| 196 |
+
|
| 197 |
+
// expect(files.some((f) => f.name === "folder1")).toBe(true);
|
| 198 |
+
// expect(files.some((f) => f.name === "folder2")).toBe(true);
|
| 199 |
+
// expect(files.some((f) => f.name === "folder3")).toBe(true);
|
| 200 |
+
// });
|
| 201 |
+
|
| 202 |
+
// it("should correctly extract a zip with a single root with a folder", async () => {
|
| 203 |
+
// baseApp.appName = "folder-with-sibling-file";
|
| 204 |
+
// // const appName = "folder-with-sibling-file";
|
| 205 |
+
// const outputPath = path.join(APPLICATIONS_PATH, baseApp.appName, "code");
|
| 206 |
+
// const zip = new AdmZip("./__test__/drop/zips/folder-with-sibling-file.zip");
|
| 207 |
+
|
| 208 |
+
// const zipBuffer = zip.toBuffer();
|
| 209 |
+
// const file = new File([zipBuffer], "single.zip");
|
| 210 |
+
// await unzipDrop(file, baseApp);
|
| 211 |
+
|
| 212 |
+
// const files = await fs.readdir(outputPath, { withFileTypes: true });
|
| 213 |
+
|
| 214 |
+
// expect(files.some((f) => f.name === "folder1")).toBe(true);
|
| 215 |
+
// expect(files.some((f) => f.name === "test.txt")).toBe(true);
|
| 216 |
+
// });
|
| 217 |
+
// });
|