Skip to content

Commit

Permalink
Merge pull request #720 from Dokploy/canary
Browse files Browse the repository at this point in the history
v0.12.0
  • Loading branch information
Siumauricio authored Nov 18, 2024
2 parents be93406 + 5db5336 commit 5c87214
Show file tree
Hide file tree
Showing 96 changed files with 11,091 additions and 111 deletions.
19 changes: 16 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ jobs:
docker login -u $DOCKERHUB_USERNAME -p $DOCKERHUB_TOKEN
if [ "${CIRCLE_BRANCH}" == "main" ]; then
TAG="latest"
else
elif [ "${CIRCLE_BRANCH}" == "canary" ]; then
TAG="canary"
else
TAG="feature"
fi
docker build --platform linux/amd64 -t dokploy/dokploy:${TAG}-amd64 .
docker push dokploy/dokploy:${TAG}-amd64
Expand All @@ -41,8 +43,10 @@ jobs:
docker login -u $DOCKERHUB_USERNAME -p $DOCKERHUB_TOKEN
if [ "${CIRCLE_BRANCH}" == "main" ]; then
TAG="latest"
else
elif [ "${CIRCLE_BRANCH}" == "canary" ]; then
TAG="canary"
else
TAG="feature"
fi
docker build --platform linux/arm64 -t dokploy/dokploy:${TAG}-arm64 .
docker push dokploy/dokploy:${TAG}-arm64
Expand Down Expand Up @@ -72,12 +76,18 @@ jobs:
dokploy/dokploy:${TAG}-amd64 \
dokploy/dokploy:${TAG}-arm64
docker manifest push dokploy/dokploy:${VERSION}
else
elif [ "${CIRCLE_BRANCH}" == "canary" ]; then
TAG="canary"
docker manifest create dokploy/dokploy:${TAG} \
dokploy/dokploy:${TAG}-amd64 \
dokploy/dokploy:${TAG}-arm64
docker manifest push dokploy/dokploy:${TAG}
else
TAG="feature"
docker manifest create dokploy/dokploy:${TAG} \
dokploy/dokploy:${TAG}-amd64 \
dokploy/dokploy:${TAG}-arm64
docker manifest push dokploy/dokploy:${TAG}
fi
workflows:
Expand All @@ -89,12 +99,14 @@ workflows:
only:
- main
- canary
- fix/build-i18n
- build-arm64:
filters:
branches:
only:
- main
- canary
- fix/build-i18n
- combine-manifests:
requires:
- build-amd64
Expand All @@ -104,3 +116,4 @@ workflows:
only:
- main
- canary
- fix/build-i18n
4 changes: 3 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ We have a few guidelines to follow when contributing to this project:

## Commit Convention


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.

### Commit Message Format


```
<type>[optional scope]: <description>
Expand Down Expand Up @@ -235,7 +237,7 @@ export function generate(schema: Schema): Template {

5. Add the logo or image of the template to `public/templates/plausible.svg`

### Recomendations
### Recommendations

- Use the same name of the folder as the id of the template.
- The logo should be in the public folder.
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ RUN apt-get update && apt-get install -y curl unzip apache2-utils && rm -rf /var
COPY --from=build /prod/dokploy/.next ./.next
COPY --from=build /prod/dokploy/dist ./dist
COPY --from=build /prod/dokploy/next.config.mjs ./next.config.mjs
COPY --from=build /prod/dokploy/next-i18next.config.cjs ./next-i18next.config.cjs
COPY --from=build /prod/dokploy/public ./public
COPY --from=build /prod/dokploy/package.json ./package.json
COPY --from=build /prod/dokploy/drizzle ./drizzle
Expand Down
1 change: 1 addition & 0 deletions Dockerfile.cloud
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ RUN apt-get update && apt-get install -y curl unzip apache2-utils && rm -rf /var
COPY --from=build /prod/dokploy/.next ./.next
COPY --from=build /prod/dokploy/dist ./dist
COPY --from=build /prod/dokploy/next.config.mjs ./next.config.mjs
COPY --from=build /prod/dokploy/next-i18next.config.cjs ./next-i18next.config.cjs
COPY --from=build /prod/dokploy/public ./public
COPY --from=build /prod/dokploy/package.json ./package.json
COPY --from=build /prod/dokploy/drizzle ./drizzle
Expand Down
8 changes: 8 additions & 0 deletions apps/dokploy/__test__/drop/drop.test.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ const baseApp: ApplicationNested = {
serverId: "",
branch: null,
dockerBuildStage: "",
project: {
env: "",
adminId: "",
name: "",
description: "",
createdAt: "",
projectId: "",
},
buildArgs: null,
buildPath: "/",
gitlabPathNamespace: "",
Expand Down
179 changes: 179 additions & 0 deletions apps/dokploy/__test__/env/shared.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
import { prepareEnvironmentVariables } from "@dokploy/server/index";
import { describe, expect, it } from "vitest";

const projectEnv = `
ENVIRONMENT=staging
DATABASE_URL=postgres://postgres:postgres@localhost:5432/project_db
PORT=3000
`;
const serviceEnv = `
ENVIRONMENT=\${{project.ENVIRONMENT}}
DATABASE_URL=\${{project.DATABASE_URL}}
SERVICE_PORT=4000
`;

describe("prepareEnvironmentVariables", () => {
it("resolves project variables correctly", () => {
const resolved = prepareEnvironmentVariables(serviceEnv, projectEnv);

expect(resolved).toEqual([
"ENVIRONMENT=staging",
"DATABASE_URL=postgres://postgres:postgres@localhost:5432/project_db",
"SERVICE_PORT=4000",
]);
});

it("handles undefined project variables", () => {
const incompleteProjectEnv = `
NODE_ENV=production
`;

const invalidServiceEnv = `
UNDEFINED_VAR=\${{project.UNDEFINED_VAR}}
`;

expect(
() =>
prepareEnvironmentVariables(invalidServiceEnv, incompleteProjectEnv), // Cambiado el orden
).toThrow("Invalid project environment variable: project.UNDEFINED_VAR");
});
it("allows service-specific variables to override project variables", () => {
const serviceSpecificEnv = `
ENVIRONMENT=production
DATABASE_URL=\${{project.DATABASE_URL}}
`;

const resolved = prepareEnvironmentVariables(
serviceSpecificEnv,
projectEnv,
);

expect(resolved).toEqual([
"ENVIRONMENT=production", // Overrides project variable
"DATABASE_URL=postgres://postgres:postgres@localhost:5432/project_db",
]);
});

it("resolves complex references for dynamic endpoints", () => {
const projectEnv = `
BASE_URL=https://api.example.com
API_VERSION=v1
PORT=8000
`;
const serviceEnv = `
API_ENDPOINT=\${{project.BASE_URL}}/\${{project.API_VERSION}}/endpoint
SERVICE_PORT=9000
`;
const resolved = prepareEnvironmentVariables(serviceEnv, projectEnv);

expect(resolved).toEqual([
"API_ENDPOINT=https://api.example.com/v1/endpoint",
"SERVICE_PORT=9000",
]);
});

it("handles missing project variables gracefully", () => {
const projectEnv = `
PORT=8080
`;
const serviceEnv = `
MISSING_VAR=\${{project.MISSING_KEY}}
SERVICE_PORT=3000
`;

expect(() => prepareEnvironmentVariables(serviceEnv, projectEnv)).toThrow(
"Invalid project environment variable: project.MISSING_KEY",
);
});

it("overrides project variables with service-specific values", () => {
const projectEnv = `
ENVIRONMENT=staging
DATABASE_URL=postgres://project:project@localhost:5432/project_db
`;
const serviceEnv = `
ENVIRONMENT=\${{project.ENVIRONMENT}}
DATABASE_URL=postgres://service:service@localhost:5432/service_db
SERVICE_NAME=my-service
`;
const resolved = prepareEnvironmentVariables(serviceEnv, projectEnv);

expect(resolved).toEqual([
"ENVIRONMENT=staging",
"DATABASE_URL=postgres://service:service@localhost:5432/service_db",
"SERVICE_NAME=my-service",
]);
});

it("handles project variables with normal and unusual characters", () => {
const projectEnv = `
ENVIRONMENT=PRODUCTION
`;

// Needs to be in quotes
const serviceEnv = `
NODE_ENV=\${{project.ENVIRONMENT}}
SPECIAL_VAR="$^@$^@#$^@!#$@#$-\${{project.ENVIRONMENT}}"
`;

const resolved = prepareEnvironmentVariables(serviceEnv, projectEnv);

expect(resolved).toEqual([
"NODE_ENV=PRODUCTION",
"SPECIAL_VAR=$^@$^@#$^@!#$@#$-PRODUCTION",
]);
});

it("handles complex cases with multiple references, special characters, and spaces", () => {
const projectEnv = `
ENVIRONMENT=STAGING
APP_NAME=MyApp
`;

const serviceEnv = `
NODE_ENV=\${{project.ENVIRONMENT}}
COMPLEX_VAR="Prefix-$#^!@-\${{project.ENVIRONMENT}}--\${{project.APP_NAME}} Suffix "
`;
const resolved = prepareEnvironmentVariables(serviceEnv, projectEnv);

expect(resolved).toEqual([
"NODE_ENV=STAGING",
"COMPLEX_VAR=Prefix-$#^!@-STAGING--MyApp Suffix ",
]);
});

it("handles references enclosed in single quotes", () => {
const projectEnv = `
ENVIRONMENT=STAGING
APP_NAME=MyApp
`;

const serviceEnv = `
NODE_ENV='\${{project.ENVIRONMENT}}'
COMPLEX_VAR='Prefix-$#^!@-\${{project.ENVIRONMENT}}--\${{project.APP_NAME}} Suffix'
`;
const resolved = prepareEnvironmentVariables(serviceEnv, projectEnv);

expect(resolved).toEqual([
"NODE_ENV=STAGING",
"COMPLEX_VAR=Prefix-$#^!@-STAGING--MyApp Suffix",
]);
});

it("handles double and single quotes combined", () => {
const projectEnv = `
ENVIRONMENT=PRODUCTION
APP_NAME=MyApp
`;
const serviceEnv = `
NODE_ENV="'\${{project.ENVIRONMENT}}'"
COMPLEX_VAR="'Prefix \"DoubleQuoted\" and \${{project.APP_NAME}}'"
`;
const resolved = prepareEnvironmentVariables(serviceEnv, projectEnv);

expect(resolved).toEqual([
"NODE_ENV='PRODUCTION'",
"COMPLEX_VAR='Prefix \"DoubleQuoted\" and MyApp'",
]);
});
});
8 changes: 8 additions & 0 deletions apps/dokploy/__test__/traefik/traefik.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ const baseApp: ApplicationNested = {
branch: null,
dockerBuildStage: "",
buildArgs: null,
project: {
env: "",
adminId: "",
name: "",
description: "",
createdAt: "",
projectId: "",
},
buildPath: "/",
gitlabPathNamespace: "",
buildType: "nixpacks",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const redirectPresets = [
redirect: {
regex: "^https?://(?:www.)?(.+)",
permanent: true,
replacement: "https://www.$${1}",
replacement: "https://www.${1}",
},
},
{
Expand All @@ -70,7 +70,7 @@ const redirectPresets = [
redirect: {
regex: "^https?://www.(.+)",
permanent: true,
replacement: "https://$${1}",
replacement: "https://${1}",
},
},
];
Expand Down
Loading

0 comments on commit 5c87214

Please sign in to comment.