From 63b5fdaa7165d00301231823205b82a625df4f51 Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Wed, 1 May 2024 19:44:41 -0600 Subject: [PATCH] feat: add canary builds for testing purposes --- .dockerignore | 5 ++ docker/build.sh | 17 +++++-- docker/canary.sh | 90 +++++++++++++++++++++++++++++++++ docker/push.sh | 15 ++++-- package.json | 6 ++- server/api/services/settings.ts | 2 +- 6 files changed, 126 insertions(+), 9 deletions(-) create mode 100644 .dockerignore create mode 100644 docker/canary.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..958b26c9d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +node_modules +.git +.gitignore +*.md +dist \ No newline at end of file diff --git a/docker/build.sh b/docker/build.sh index e3901d52f..22104934d 100755 --- a/docker/build.sh +++ b/docker/build.sh @@ -1,7 +1,18 @@ #!/bin/bash -VERSION=$(node -p "require('./package.json').version") +# Determine the type of build based on the first script argument +BUILD_TYPE=${1:-production} -docker build --platform linux/amd64 --pull --rm -f 'Dockerfile' -t "dokploy/dokploy:${VERSION}" . +if [ "$BUILD_TYPE" == "canary" ]; then + TAG="canary" +else + VERSION=$(node -p "require('./package.json').version") + TAG="$VERSION" +fi -docker tag "dokploy/dokploy:${VERSION}" "dokploy/dokploy:latest" \ No newline at end of file +docker build --platform linux/amd64 --pull --rm -f 'Dockerfile' -t "dokploy/dokploy:${TAG}" . + +if [ "$BUILD_TYPE" != "canary" ]; then + # Tag the production build as latest + docker tag "dokploy/dokploy:${TAG}" "dokploy/dokploy:latest" +fi diff --git a/docker/canary.sh b/docker/canary.sh new file mode 100644 index 000000000..4c1b50f99 --- /dev/null +++ b/docker/canary.sh @@ -0,0 +1,90 @@ +#!/bin/bash + +if [ "$(id -u)" != "0" ]; then + echo "This script must be run as root" >&2 + exit 1 +fi + +# check if is Mac OS +if [ "$(uname)" = "Darwin" ]; then + echo "This script must be run on Linux" >&2 + exit 1 +fi + + +# check if is running inside a container +if [ -f /.dockerenv ]; then + echo "This script must be run on Linux" >&2 + exit 1 +fi + +# check if something is running on port 80 +if ss -tulnp | grep ':80 ' >/dev/null; then + echo "Error: something is already running on port 80" >&2 + exit 1 +fi + +# check if something is running on port 443 +if ss -tulnp | grep ':443 ' >/dev/null; then + echo "Error: something is already running on port 443" >&2 + exit 1 +fi + + + + + + +command_exists() { + command -v "$@" > /dev/null 2>&1 +} + +if command_exists docker; then + echo "Docker already installed" +else + curl -sSL https://get.docker.com | sh +fi + +docker swarm leave --force 2>/dev/null +docker swarm init --advertise-addr 127.0.0.1 --listen-addr 0.0.0.0; + +echo "Swarm initialized" + +docker network rm -f dokploy-network 2>/dev/null +docker network create --driver overlay --attachable dokploy-network + +echo "Network created" + +mkdir -p /etc/dokploy + +chmod -R 777 /etc/dokploy + +docker pull dokploy/dokploy:canary + +# Installation +docker service create \ + --name dokploy \ + --replicas 1 \ + --network dokploy-network \ + --mount type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock \ + --mount type=bind,source=/etc/dokploy,target=/etc/dokploy \ + --publish published=3000,target=3000,mode=host \ + --update-parallelism 1 \ + --update-order stop-first \ + -e RELEASE_TAG=canary \ + dokploy/dokploy:canary + + +public_ip=$(hostname -I | awk '{print $1}') + +GREEN="\033[0;32m" +YELLOW="\033[1;33m" +BLUE="\033[0;34m" +NC="\033[0m" # No Color + + +echo "" +printf "${GREEN}Congratulations, Dokploy is installed!${NC}\n" +printf "${BLUE}Wait 15 seconds for the server to start${NC}\n" +printf "${YELLOW}Please go to http://${public_ip}:3000${NC}\n\n" +echo "" diff --git a/docker/push.sh b/docker/push.sh index b1e044f0f..1e9fbecaf 100755 --- a/docker/push.sh +++ b/docker/push.sh @@ -1,6 +1,15 @@ #!/bin/bash -VERSION=$(node -p "require('./package.json').version") +# Determine the type of build based on the first script argument +BUILD_TYPE=${1:-production} -docker push "dokploy/dokploy:${VERSION}" -docker push "dokploy/dokploy:latest" \ No newline at end of file +if [ "$BUILD_TYPE" == "canary" ]; then + TAG="canary" + echo PUSHING CANARY + docker push "dokploy/dokploy:${TAG}" +else + echo "PUSHING PRODUCTION" + VERSION=$(node -p "require('./package.json').version") + docker push "dokploy/dokploy:${VERSION}" + docker push "dokploy/dokploy:latest" +fi diff --git a/package.json b/package.json index 5a6cdfd97..258f32bf7 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,8 @@ "db:clean": "dotenv tsx ./server/db/reset.ts", "docker:build": "./docker/build.sh", "docker:push": "./docker/push.sh", + "docker:build:canary": "./docker/build.sh canary", + "docker:push:canary": "./docker/push.sh canary", "version": "echo $(node -p \"require('./package.json').version\")" }, "dependencies": { @@ -130,6 +132,6 @@ }, "engines": { "node": "^18.18.0", - "pnpm": "^8.15.4" -} + "pnpm": ">=8.15.4" + } } diff --git a/server/api/services/settings.ts b/server/api/services/settings.ts index 9cfcf33d8..fb70fb82c 100644 --- a/server/api/services/settings.ts +++ b/server/api/services/settings.ts @@ -16,7 +16,7 @@ const updateIsAvailable = async () => { }; export const getDokployImage = () => { - return "dokploy/dokploy:latest"; + return `dokploy/dokploy:${process.env.RELEASE_TAG || "latest"}`; }; export const pullLatestRelease = async () => {