Revert "v1.0.2 (#8)" (#9)

This reverts commit b91bfa21b3.
This commit is contained in:
Andras Bacsai
2021-03-30 22:15:37 +02:00
committed by GitHub
parent 73d3d43215
commit a1cccd479e
18 changed files with 124 additions and 180 deletions

View File

@@ -14,11 +14,15 @@ https://andrasbacsai.com/farewell-netlify-and-heroku-after-3-days-of-coding
# FAQ # FAQ
Q: What is a buildpack? Q: What does Buildpack means?
A: It defines your application's final form. A: It defines your application's final form. Static means that it will be hosted as a static site in the end. (see next question below 👇)
`Static` means that it will be hosted as a static site.
`NodeJs` means that it will be started as a node application. ---
Q: How can I build a static site, like Next.js, Sapper (prerendered), etc ?
A: Use `static` builder and set your `Build command`.
# Screenshots # Screenshots

View File

@@ -1,10 +1,9 @@
const { docker } = require('../../docker') const { docker } = require('../../docker')
const { execShellAsync } = require('../../common') const { execShellAsync, delay } = require('../../common')
const Deployment = require('../../../models/Deployment') const Deployment = require('../../../models/Deployment')
async function purgeOldThings () { async function purgeOldThings () {
try { try {
// TODO: Tweak this, because it deletes coolify-base, so the upgrade will be slow
await docker.engine.pruneImages() await docker.engine.pruneImages()
await docker.engine.pruneContainers() await docker.engine.pruneContainers()
} catch (error) { } catch (error) {

View File

@@ -1,8 +1,7 @@
const { uniqueNamesGenerator, adjectives, colors, animals } = require('unique-names-generator') const { uniqueNamesGenerator, adjectives, colors, animals } = require('unique-names-generator')
const cuid = require('cuid') const cuid = require('cuid')
const crypto = require('crypto')
const { execShellAsync } = require('../common') const { execShellAsync } = require('../common')
const crypto = require('crypto')
function getUniq () { function getUniq () {
return uniqueNamesGenerator({ dictionaries: [adjectives, animals, colors], length: 2 }) return uniqueNamesGenerator({ dictionaries: [adjectives, animals, colors], length: 2 })
@@ -16,24 +15,6 @@ function setDefaultConfiguration (configuration) {
const shaBase = JSON.stringify({ repository: configuration.repository }) const shaBase = JSON.stringify({ repository: configuration.repository })
const sha256 = crypto.createHash('sha256').update(shaBase).digest('hex') const sha256 = crypto.createHash('sha256').update(shaBase).digest('hex')
const baseServiceConfiguration = {
replicas: 1,
restart_policy: {
condition: 'any',
max_attempts: 3
},
update_config: {
parallelism: 1,
delay: '10s',
order: 'start-first'
},
rollback_config: {
parallelism: 1,
delay: '10s',
order: 'start-first'
}
}
configuration.build.container.name = sha256.slice(0, 15) configuration.build.container.name = sha256.slice(0, 15)
configuration.general.nickname = nickname configuration.general.nickname = nickname
@@ -53,9 +34,6 @@ function setDefaultConfiguration (configuration) {
if (!configuration.build.directory) configuration.build.directory = '/' if (!configuration.build.directory) configuration.build.directory = '/'
} }
configuration.build.container.baseSHA = crypto.createHash('sha256').update(JSON.stringify(baseServiceConfiguration)).digest('hex')
configuration.baseServiceConfiguration = baseServiceConfiguration
return configuration return configuration
} catch (error) { } catch (error) {
throw { error, type: 'server' } throw { error, type: 'server' }

View File

@@ -1,9 +1,9 @@
const yaml = require('js-yaml') const yaml = require('js-yaml')
const fs = require('fs').promises
const { execShellAsync } = require('../../common') const { execShellAsync } = require('../../common')
const { docker } = require('../../docker') const { docker } = require('../../docker')
const { saveAppLog } = require('../../logging') const { saveAppLog } = require('../../logging')
const { deleteSameDeployments } = require('../cleanup') const { deleteSameDeployments } = require('../cleanup')
const fs = require('fs').promises
module.exports = async function (configuration, configChanged, imageChanged) { module.exports = async function (configuration, configChanged, imageChanged) {
try { try {
@@ -12,11 +12,6 @@ module.exports = async function (configuration, configChanged, imageChanged) {
generateEnvs[secret.name] = secret.value generateEnvs[secret.name] = secret.value
} }
const containerName = configuration.build.container.name const containerName = configuration.build.container.name
// Only save SHA256 of it in the configuration label
const baseServiceConfiguration = configuration.baseServiceConfiguration
delete configuration.baseServiceConfiguration
const stack = { const stack = {
version: '3.8', version: '3.8',
services: { services: {
@@ -25,7 +20,23 @@ module.exports = async function (configuration, configChanged, imageChanged) {
networks: [`${docker.network}`], networks: [`${docker.network}`],
environment: generateEnvs, environment: generateEnvs,
deploy: { deploy: {
...baseServiceConfiguration, replicas: 1,
restart_policy: {
condition: 'on-failure',
delay: '5s',
max_attempts: 1,
window: '120s'
},
update_config: {
parallelism: 1,
delay: '10s',
order: 'start-first'
},
rollback_config: {
parallelism: 1,
delay: '10s',
order: 'start-first'
},
labels: [ labels: [
'managedBy=coolify', 'managedBy=coolify',
'type=application', 'type=application',
@@ -60,10 +71,8 @@ module.exports = async function (configuration, configChanged, imageChanged) {
} }
} }
} }
console.log(stack)
await saveAppLog('### Publishing.', configuration) await saveAppLog('### Publishing.', configuration)
await fs.writeFile(`${configuration.general.workdir}/stack.yml`, yaml.dump(stack)) await fs.writeFile(`${configuration.general.workdir}/stack.yml`, yaml.dump(stack))
// TODO: Compare stack.yml with the currently running one to upgrade if something changes, like restart_policy
if (configChanged) { if (configChanged) {
// console.log('configuration changed') // console.log('configuration changed')
await execShellAsync( await execShellAsync(
@@ -82,7 +91,6 @@ module.exports = async function (configuration, configChanged, imageChanged) {
await saveAppLog('### Published done!', configuration) await saveAppLog('### Published done!', configuration)
} catch (error) { } catch (error) {
console.log(error)
await saveAppLog(`Error occured during deployment: ${error.message}`, configuration) await saveAppLog(`Error occured during deployment: ${error.message}`, configuration)
throw { error, type: 'server' } throw { error, type: 'server' }
} }

View File

@@ -60,10 +60,6 @@ module.exports = async function (fastify) {
foundDomain = true foundDomain = true
} }
if (running.repository.id === configuration.repository.id && running.repository.branch === configuration.repository.branch) { if (running.repository.id === configuration.repository.id && running.repository.branch === configuration.repository.branch) {
// Base service configuration changed
if (!running.build.container.baseSHA || running.build.container.baseSHA !== configuration.build.container.baseSHA) {
configChanged = true
}
const state = await execShellAsync(`docker stack ps ${running.build.container.name} --format '{{ json . }}'`) const state = await execShellAsync(`docker stack ps ${running.build.container.name} --format '{{ json . }}'`)
const isError = state.split('\n').filter(n => n).map(s => JSON.parse(s)).filter(n => n.DesiredState !== 'Running') const isError = state.split('\n').filter(n => n).map(s => JSON.parse(s)).filter(n => n.DesiredState !== 'Running')
if (isError.length > 0) forceUpdate = true if (isError.length > 0) forceUpdate = true

View File

@@ -3,10 +3,10 @@ const { saveServerLog } = require('../../../libs/logging')
module.exports = async function (fastify) { module.exports = async function (fastify) {
fastify.get('/', async (request, reply) => { fastify.get('/', async (request, reply) => {
const upgradeP1 = await execShellAsync('bash ./upgrade.sh upgrade-p1') const upgradeP1 = await execShellAsync('bash ./install.sh upgrade-phase-1')
await saveServerLog({ event: upgradeP1, type: 'UPGRADE-P-1' }) await saveServerLog({ event: upgradeP1, type: 'UPGRADE-P-1' })
reply.code(200).send('I\'m trying, okay?') reply.code(200).send('I\'m trying, okay?')
const upgradeP2 = await execShellAsync('bash ./upgrade.sh upgrade-p2') const upgradeP2 = await execShellAsync('bash ./install.sh upgrade-phase-2')
await saveServerLog({ event: upgradeP2, type: 'UPGRADE-P-2' }) await saveServerLog({ event: upgradeP2, type: 'UPGRADE-P-2' })
}) })
} }

View File

@@ -1,68 +1,43 @@
#!/bin/bash #!/bin/bash
echo '
##############################
#### Pulling Git Updates #####
##############################'
GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" git pull GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" git pull
echo "#### Building base image."
docker build -t coolify-base -f install/Dockerfile-base .
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo ' echo '#### Ooops something not okay!'
####################################
#### Ooops something not okay! #####
####################################'
exit 1 exit 1
fi fi
echo ' echo "#### Checking configuration."
##############################
#### Building Base Image #####
##############################'
docker build --label coolify-reserve=true -t coolify-base -f install/Dockerfile-base .
if [ $? -ne 0 ]; then
echo '
####################################
#### Ooops something not okay! #####
####################################'
exit 1
fi
echo '
##################################
#### Checking configuration. #####
##################################'
docker run --rm -w /usr/src/app coolify-base node install/install.js --check docker run --rm -w /usr/src/app coolify-base node install/install.js --check
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo ' echo '#### Missing configuration.'
##################################
#### Missing configuration ! #####
##################################'
exit 1 exit 1
fi fi
case "$1" in case "$1" in
"all") "all")
echo ' echo "#### Rebuild everything."
#################################
#### Rebuilding everything. #####
#################################'
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v /data/coolify:/data/coolify -u root -w /usr/src/app coolify-base node install/install.js --type all docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v /data/coolify:/data/coolify -u root -w /usr/src/app coolify-base node install/install.js --type all
;; ;;
"coolify") "coolify")
echo ' echo "#### Rebuild coolify."
##############################
#### Rebuilding Coolify. #####
##############################'
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v /data/coolify:/data/coolify -u root -w /usr/src/app coolify-base node install/install.js --type coolify docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v /data/coolify:/data/coolify -u root -w /usr/src/app coolify-base node install/install.js --type coolify
;; ;;
"proxy") "proxy")
echo ' echo "#### Rebuild proxy."
############################
#### Rebuilding Proxy. #####
############################'
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v /data/coolify:/data/coolify -u root -w /usr/src/app coolify-base node install/install.js --type proxy docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v /data/coolify:/data/coolify -u root -w /usr/src/app coolify-base node install/install.js --type proxy
;; ;;
"upgrade-phase-1")
echo "#### Rebuild coolify from frontend request phase 1."
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v /data/coolify:/data/coolify -u root -w /usr/src/app coolify-base node install/install.js --type upgrade
;;
"upgrade-phase-2")
echo "#### Rebuild coolify from frontend request phase 2."
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v /data/coolify:/data/coolify -u root -w /usr/src/app coolify-base node install/update.js --type upgrade
;;
*) *)
echo "Use 'all' to build & deploy proxy+coolify, 'coolify' to build & deploy only coolify, 'proxy' to build & deploy only proxy."
exit 1 exit 1
;; ;;
esac esac

View File

@@ -35,7 +35,7 @@ if (program.check) {
} else if (program.type === 'proxy') { } else if (program.type === 'proxy') {
shell.exec('docker service rm coollabs-coolify_proxy') shell.exec('docker service rm coollabs-coolify_proxy')
} }
shell.exec('set -a && source .env && set +a && envsubst < install/coolify-template.yml | docker stack deploy -c - coollabs-coolify', { silent: !program.debug, shell: '/bin/bash' }) if (program.type !== 'upgrade') shell.exec('set -a && source .env && set +a && envsubst < install/coolify-template.yml | docker stack deploy -c - coollabs-coolify', { silent: !program.debug, shell: '/bin/bash' })
} }
function checkConfig () { function checkConfig () {

View File

@@ -15,12 +15,7 @@ if (user !== 'root') {
console.error(`Please run as root! Current user: ${user}`) console.error(`Please run as root! Current user: ${user}`)
process.exit(1) process.exit(1)
} }
if (program.type === 'upgrade-p1') { if (program.type === 'upgrade') {
shell.exec(`docker network create ${process.env.DOCKER_NETWORK} --driver overlay`, { silent: !program.debug })
shell.exec('docker build -t coolify -f install/Dockerfile .')
}
if (program.type === 'upgrade-p2') {
shell.exec('docker service rm coollabs-coolify_coolify') shell.exec('docker service rm coollabs-coolify_coolify')
shell.exec('set -a && source .env && set +a && envsubst < install/coolify-template.yml | docker stack deploy -c - coollabs-coolify', { silent: !program.debug, shell: '/bin/bash' }) shell.exec('set -a && source .env && set +a && envsubst < install/coolify-template.yml | docker stack deploy -c - coollabs-coolify', { silent: !program.debug, shell: '/bin/bash' })
} }

View File

@@ -20,7 +20,6 @@
"@zerodevx/svelte-toast": "^0.1.4", "@zerodevx/svelte-toast": "^0.1.4",
"axios": "^0.21.0", "axios": "^0.21.0",
"commander": "^6.2.1", "commander": "^6.2.1",
"compare-versions": "^3.6.0",
"cuid": "^2.1.8", "cuid": "^2.1.8",
"dayjs": "^1.10.4", "dayjs": "^1.10.4",
"deepmerge": "^4.2.2", "deepmerge": "^4.2.2",

6
pnpm-lock.yaml generated
View File

@@ -3,7 +3,6 @@ dependencies:
'@zerodevx/svelte-toast': 0.1.4 '@zerodevx/svelte-toast': 0.1.4
axios: 0.21.1 axios: 0.21.1
commander: 6.2.1 commander: 6.2.1
compare-versions: 3.6.0
cuid: 2.1.8 cuid: 2.1.8
dayjs: 1.10.4 dayjs: 1.10.4
deepmerge: 4.2.2 deepmerge: 4.2.2
@@ -1189,10 +1188,6 @@ packages:
dev: true dev: true
resolution: resolution:
integrity: sha1-3dgA2gxmEnOTzKWVDqloo6rxJTs= integrity: sha1-3dgA2gxmEnOTzKWVDqloo6rxJTs=
/compare-versions/3.6.0:
dev: false
resolution:
integrity: sha512-W6Af2Iw1z4CB7q4uU4hv646dW9GQuBM+YpC0UvUCWSD8w90SJjp+ujJuXaEMtAXBtSqGfMPuFOVn4/+FlaqfBA==
/concat-map/0.0.1: /concat-map/0.0.1:
resolution: resolution:
integrity: sha1-2Klr13/Wjfd5OnMDajug1UBdR3s= integrity: sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=
@@ -6754,7 +6749,6 @@ specifiers:
'@zerodevx/svelte-toast': ^0.1.4 '@zerodevx/svelte-toast': ^0.1.4
axios: ^0.21.0 axios: ^0.21.0
commander: ^6.2.1 commander: ^6.2.1
compare-versions: ^3.6.0
cuid: ^2.1.8 cuid: ^2.1.8
dayjs: ^1.10.4 dayjs: ^1.10.4
deepmerge: ^4.2.2 deepmerge: ^4.2.2

View File

@@ -8,8 +8,8 @@
> >
<label for="buildPack">Build Pack</label> <label for="buildPack">Build Pack</label>
<select id="buildPack" bind:value="{$application.build.pack}"> <select id="buildPack" bind:value="{$application.build.pack}">
<option selected class="font-bold">Static</option> <option selected class="font-medium">static</option>
<option class="font-bold">Node.js</option> <option class="font-medium">nodejs</option>
</select> </select>
</div> </div>
<div <div
@@ -45,5 +45,62 @@
: '3000'}" : '3000'}"
/> />
{/if} {/if}
<!-- {#if config.buildPack === "static"}
<div class="text-base font-bold text-white pt-2">
Preview Deploys
</div>
<button
type="button"
on:click="{() =>
(config.previewDeploy = !config.previewDeploy)}"
aria-pressed="false"
class="relative inline-flex flex-shrink-0 h-6 w-11 border-2 border-transparent rounded-full cursor-pointer transition-colors ease-in-out duration-200 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-black"
class:bg-green-600="{config.previewDeploy}"
class:bg-coolgray-300="{!config.previewDeploy}"
>
<span class="sr-only">Use setting</span>
<span
class="pointer-events-none relative inline-block h-5 w-5 rounded-full bg-white shadow transform ring-0 transition ease-in-out duration-200"
class:translate-x-5="{config.previewDeploy}"
class:translate-x-0="{!config.previewDeploy}"
>
<span
class="ease-in duration-200 absolute inset-0 h-full w-full flex items-center justify-center transition-opacity"
class:opacity-0="{config.previewDeploy}"
class:opacity-100="{!config.previewDeploy}"
aria-hidden="true"
>
<svg
class="bg-white h-3 w-3 text-red-600"
fill="none"
viewBox="0 0 12 12"
>
<path
d="M4 8l2-2m0 0l2-2M6 6L4 4m2 2l2 2"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"></path>
</svg>
</span>
<span
class="ease-out duration-100 absolute inset-0 h-full w-full flex items-center justify-center transition-opacity"
aria-hidden="true"
class:opacity-100="{config.previewDeploy}"
class:opacity-0="{!config.previewDeploy}"
>
<svg
class="bg-white h-3 w-3 text-green-600"
fill="currentColor"
viewBox="0 0 12 12"
>
<path
d="M3.707 5.293a1 1 0 00-1.414 1.414l1.414-1.414zM5 8l-.707.707a1 1 0 001.414 0L5 8zm4.707-3.293a1 1 0 00-1.414-1.414l1.414 1.414zm-7.414 2l2 2 1.414-1.414-2-2-1.414 1.414zm3.414 2l4-4-1.414-1.414-4 4 1.414 1.414z"
></path>
</svg>
</span>
</span>
</button>
{/if} -->
</div> </div>
</div> </div>

View File

@@ -17,7 +17,7 @@
<select id="branch" bind:value="{$application.repository.branch}"> <select id="branch" bind:value="{$application.repository.branch}">
<option disabled selected>Select a branch</option> <option disabled selected>Select a branch</option>
{#each branches as branch} {#each branches as branch}
<option value="{branch.name}" class="font-bold">{branch.name}</option> <option value="{branch.name}" class="font-medium">{branch.name}</option>
{/each} {/each}
</select> </select>
</div> </div>

View File

@@ -23,7 +23,7 @@
> >
<option selected disabled>Select a repository</option> <option selected disabled>Select a repository</option>
{#each repositories as repo} {#each repositories as repo}
<option value="{repo.id}" class="font-bold"> <option value="{repo.id}" class="font-medium">
{repo.owner.login} {repo.owner.login}
/ /
{repo.name} {repo.name}

View File

@@ -19,9 +19,8 @@
initConf, initConf,
} from "@store"; } from "@store";
import { toast } from "@zerodevx/svelte-toast"; import { toast } from "@zerodevx/svelte-toast";
import { onMount } from "svelte";
import compareVersions from 'compare-versions';
import packageJson from "../../package.json"; import packageJson from "../../package.json";
import { onMount } from "svelte";
let upgradeAvailable = false; let upgradeAvailable = false;
let upgradeDisabled = false; let upgradeDisabled = false;
@@ -74,14 +73,18 @@
} }
} }
async function checkUpgrade() { async function checkUpgrade() {
const branch = process.env.NODE_ENV === 'production' && window.location.hostname !== 'test.andrasbacsai.dev' ? 'main' : 'next'
latest = await window latest = await window
.fetch( .fetch(
`https://raw.githubusercontent.com/coollabsio/coolify/${branch}/package.json`, "https://raw.githubusercontent.com/coollabsio/coolify/main/package.json",
{ cache: "no-cache" }, { cache: "no-cache" },
) )
.then(r => r.json()); .then(r => r.json());
return compareVersions(latest.version,packageJson.version) if (
latest.version.split(".").join("") >
packageJson.version.split(".").join("")
) {
return true;
}
} }
</script> </script>
@@ -211,24 +214,24 @@
<div <div
class="cursor-pointer text-xs font-bold text-warmGray-400 py-2 hover:bg-warmGray-700 w-full text-center" class="cursor-pointer text-xs font-bold text-warmGray-400 py-2 hover:bg-warmGray-700 w-full text-center"
> >
{packageJson.version} v{packageJson.version}
</div> </div>
</div> </div>
</nav> </nav>
{/if} {/if}
{#if upgradeAvailable} {#if upgradeAvailable}
<footer <footer
class="absolute bottom-0 right-0 p-4 px-6 w-auto rounded-tl text-white " class="absolute top-0 right-0 p-2 w-auto rounded-tl text-white "
> >
<div class="flex items-center"> <div class="flex items-center">
<div></div> <div></div>
<div class="flex-1"></div> <div class="flex-1"></div>
{#if !upgradeDisabled} {#if !upgradeDisabled}
<button <button
class="bg-gradient-to-r from-purple-500 via-pink-500 to-red-500 text-xs font-bold rounded px-2 py-2" class="bg-gradient-to-r from-purple-500 via-pink-500 to-red-500 font-bold text-xs rounded px-2 py-2"
disabled="{upgradeDisabled}" disabled="{upgradeDisabled}"
on:click="{upgrade}" on:click="{upgrade}"
>New version available, <br>click here to upgrade!</button >New version available. <br>Click here to upgrade!</button
> >
{:else if upgradeDone} {:else if upgradeDone}
<button <button

View File

@@ -49,7 +49,6 @@
async function deploy() { async function deploy() {
try { try {
$application.build.pack = $application.build.pack.replace('.','').toLowerCase()
toast.push("Checking inputs."); toast.push("Checking inputs.");
await $fetch(`/api/v1/application/check`, { await $fetch(`/api/v1/application/check`, {
body: $application, body: $application,

View File

@@ -125,8 +125,7 @@ export const application = writable({
}, },
container: { container: {
name: null, name: null,
tag: null, tag: null
baseSHA: null
} }
}, },
publish: { publish: {

View File

@@ -1,62 +0,0 @@
#!/bin/bash
case "$1" in
"upgrade-p1")
echo '
##############################
#### Pulling Git Updates #####
##############################'
GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" git pull
if [ $? -ne 0 ]; then
echo '
####################################
#### Ooops something not okay! #####
####################################'
exit 1
fi
echo '
##############################
#### Building Base Image #####
##############################'
docker build --label coolify-reserve=true -t coolify-base -f install/Dockerfile-base .
if [ $? -ne 0 ]; then
echo '
####################################
#### Ooops something not okay! #####
####################################'
exit 1
fi
echo '
##################################
#### Checking configuration. #####
##################################'
docker run --rm -w /usr/src/app coolify-base node install/install.js --check
if [ $? -ne 0 ]; then
echo '
#################################
#### Missing configuration! #####
#################################'
exit 1
fi
echo '
################################
#### Upgrading Coolify P1. #####
################################'
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v /data/coolify:/data/coolify -u root -w /usr/src/app coolify-base node install/upgrade.js --type upgrade-p1
;;
"upgrade-p2")
echo '
################################
#### Upgrading Coolify P2. #####
################################'
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v /data/coolify:/data/coolify -u root -w /usr/src/app coolify-base node install/upgrade.js --type upgrade-p2
;;
*)
exit 1
;;
esac