v1.0.3 - Simple PHP support! 🎉 (#15)

- Basic PHP support.
- Cosmetic things here and there.
- Fix publish directory option.
This commit is contained in:
Andras Bacsai 2021-04-02 15:05:23 +02:00 committed by GitHub
parent 767c65ab10
commit 5573187d43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 6593 additions and 140 deletions

View File

@ -41,7 +41,15 @@ function setDefaultConfiguration (configuration) {
configuration.general.workdir = `/tmp/${deployId}`
if (!configuration.publish.path) configuration.publish.path = '/'
if (!configuration.publish.port) configuration.publish.port = configuration.build.pack === 'static' ? 80 : 3000
if (!configuration.publish.port) {
if (configuration.build.pack === 'php') {
configuration.publish.port = 80
} else if (configuration.build.pack === 'static') {
configuration.publish.port = 80
} else if (configuration.build.pack === 'nodejs') {
configuration.publish.port = 3000
}
}
if (configuration.build.pack === 'static') {
if (!configuration.build.command.installation) configuration.build.command.installation = 'yarn install'

View File

@ -64,16 +64,11 @@ module.exports = async function (configuration, configChanged, imageChanged) {
await saveAppLog('### Publishing.', configuration)
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) {
// console.log('configuration changed')
await execShellAsync(
`cat ${configuration.general.workdir}/stack.yml | docker stack deploy --prune -c - ${containerName}`
)
} else if (imageChanged) {
if (imageChanged) {
// console.log('image changed')
await execShellAsync(`docker service update --image ${configuration.build.container.name}:${configuration.build.container.tag} ${configuration.build.container.name}_${configuration.build.container.name}`)
} else {
// console.log('new deployment or force deployment')
// console.log('new deployment or force deployment or config changed')
await deleteSameDeployments(configuration)
await execShellAsync(
`cat ${configuration.general.workdir}/stack.yml | docker stack deploy --prune -c - ${containerName}`

View File

@ -1,4 +1,5 @@
const static = require('./static')
const nodejs = require('./nodejs')
const php = require('./php')
module.exports = { static, nodejs }
module.exports = { static, nodejs, php }

View File

@ -10,9 +10,13 @@ module.exports = async function (configuration) {
WORKDIR /usr/src/app
`
if (configuration.build.command.build) {
dockerFile += `COPY --from=${configuration.build.container.name}:${configuration.build.container.tag} /usr/src/app/${configuration.build.directory} /usr/src/app`
dockerFile += `COPY --from=${configuration.build.container.name}:${configuration.build.container.tag} /usr/src/app/${configuration.publish.directory} /usr/src/app`
} else {
dockerFile += 'COPY . ./'
if (configuration.publish.directory) {
dockerFile += `COPY .${configuration.publish.directory} ./`
} else {
dockerFile += 'COPY ./'
}
}
if (configuration.build.command.installation) {
dockerFile += `

24
api/packs/php/index.js Normal file
View File

@ -0,0 +1,24 @@
const fs = require('fs').promises
const { streamEvents, docker } = require('../../libs/docker')
module.exports = async function (configuration) {
let dockerFile = `# production stage
FROM php:apache
`
if (configuration.publish.directory) {
dockerFile += `COPY ${configuration.publish.directory} /var/www/html`
} else {
dockerFile += 'COPY . /var/www/html'
}
dockerFile += `
EXPOSE 80
CMD ["apache2-foreground"]`
await fs.writeFile(`${configuration.general.workdir}/Dockerfile`, dockerFile)
const stream = await docker.engine.buildImage(
{ src: ['.'], context: configuration.general.workdir },
{ t: `${configuration.build.container.name}:${configuration.build.container.tag}` }
)
await streamEvents(stream, configuration)
}

View File

@ -10,9 +10,13 @@ module.exports = async function (configuration) {
COPY nginx.conf /etc/nginx/nginx.conf
`
if (configuration.build.command.build) {
dockerFile += `COPY --from=${configuration.build.container.name}:${configuration.build.container.tag} /usr/src/app/${configuration.build.directory} /usr/share/nginx/html`
dockerFile += `COPY --from=${configuration.build.container.name}:${configuration.build.container.tag} /usr/src/app/${configuration.publish.directory} /usr/share/nginx/html`
} else {
dockerFile += 'COPY . /usr/share/nginx/html'
if (configuration.publish.directory) {
dockerFile += `COPY .${configuration.publish.directory} /usr/share/nginx/html`
} else {
dockerFile += 'COPY . /usr/share/nginx/html'
}
}
dockerFile += `

View File

@ -4,51 +4,57 @@ const ServerLog = require('../../../models/Logs/Server')
module.exports = async function (fastify) {
fastify.get('/', async (request, reply) => {
const latestDeployments = await Deployment.aggregate([
{
$sort: { createdAt: -1 }
},
{
$group:
try {
const latestDeployments = await Deployment.aggregate([
{
_id: {
repoId: '$repoId',
branch: '$branch'
},
createdAt: { $last: '$createdAt' },
progress: { $first: '$progress' }
$sort: { createdAt: -1 }
},
{
$group:
{
_id: {
repoId: '$repoId',
branch: '$branch'
},
createdAt: { $last: '$createdAt' },
progress: { $first: '$progress' }
}
}
}
])
])
const serverLogs = await ServerLog.find()
const services = await docker.engine.listServices()
const serverLogs = await ServerLog.find()
const services = await docker.engine.listServices()
let applications = services.filter(r => r.Spec.Labels.managedBy === 'coolify' && r.Spec.Labels.type === 'application' && r.Spec.Labels.configuration)
let databases = services.filter(r => r.Spec.Labels.managedBy === 'coolify' && r.Spec.Labels.type === 'database' && r.Spec.Labels.configuration)
applications = applications.map(r => {
if (JSON.parse(r.Spec.Labels.configuration)) {
const configuration = JSON.parse(r.Spec.Labels.configuration)
const status = latestDeployments.find(l => configuration.repository.id === l._id.repoId && configuration.repository.branch === l._id.branch)
if (status && status.progress) r.progress = status.progress
let applications = services.filter(r => r.Spec.Labels.managedBy === 'coolify' && r.Spec.Labels.type === 'application' && r.Spec.Labels.configuration)
let databases = services.filter(r => r.Spec.Labels.managedBy === 'coolify' && r.Spec.Labels.type === 'database' && r.Spec.Labels.configuration)
applications = applications.map(r => {
if (JSON.parse(r.Spec.Labels.configuration)) {
const configuration = JSON.parse(r.Spec.Labels.configuration)
const status = latestDeployments.find(l => configuration.repository.id === l._id.repoId && configuration.repository.branch === l._id.branch)
if (status && status.progress) r.progress = status.progress
r.Spec.Labels.configuration = configuration
return r
}
return {}
})
databases = databases.map(r => {
const configuration = r.Spec.Labels.configuration ? JSON.parse(r.Spec.Labels.configuration) : null
r.Spec.Labels.configuration = configuration
return r
})
applications = [...new Map(applications.map(item => [item.Spec.Labels.configuration.publish.domain, item])).values()]
return {
serverLogs,
applications: {
deployed: applications
},
databases: {
deployed: databases
}
}
return {}
})
databases = databases.map(r => {
const configuration = r.Spec.Labels.configuration ? JSON.parse(r.Spec.Labels.configuration) : null
r.Spec.Labels.configuration = configuration
return r
})
applications = [...new Map(applications.map(item => [item.Spec.Labels.configuration.publish.domain, item])).values()]
return {
serverLogs,
applications: {
deployed: applications
},
databases: {
deployed: databases
} catch (error) {
if (error.code === 'ENOENT' && error.errno === -2) {
throw new Error(`Docker service unavailable at ${error.address}.`)
}
}
})

View File

@ -31,7 +31,7 @@ if (process.env.NODE_ENV === 'production') {
fastify.register(require('./app'), { prefix: '/api/v1' })
fastify.setErrorHandler(async (error, request, reply) => {
console.log(error)
console.log({ error })
if (error.statusCode) {
reply.status(error.statusCode).send({ message: error.message } || { message: 'Something is NOT okay. Are you okay?' })
} else {

View File

@ -1,7 +1,7 @@
{
"name": "coolify",
"description": "An open-source, hassle-free, self-hostable Heroku & Netlify alternative.",
"version": "1.0.2",
"version": "1.0.3",
"license": "AGPL-3.0",
"scripts": {
"lint": "standard",

View File

@ -1,10 +1,11 @@
<script>
import { application} from "@store";
import { application } from "@store";
</script>
<div class="grid grid-cols-1 space-y-2 max-w-2xl md:mx-auto mx-6 text-center">
<div class="grid grid-cols-1 max-w-2xl md:mx-auto mx-6 text-center">
<label for="buildCommand">Build Command</label>
<input
class="mb-6"
id="buildCommand"
bind:value="{$application.build.command.build}"
placeholder="eg: yarn build"
@ -12,11 +13,17 @@
<label for="installCommand">Install Command</label>
<input
class="mb-6"
id="installCommand"
bind:value="{$application.build.command.installation}"
placeholder="eg: yarn install"
/>
<label for="baseDir">Base Directory</label>
<input id="baseDir" bind:value="{$application.build.directory}" placeholder="/" />
<input
id="baseDir"
class="mb-6"
bind:value="{$application.build.directory}"
placeholder="/"
/>
</div>

View File

@ -3,47 +3,54 @@
</script>
<div>
<div
class="grid grid-cols-1 text-sm space-y-2 max-w-2xl md:mx-auto mx-6 pb-6 auto-cols-max"
>
<label for="buildPack">Build Pack</label>
<select id="buildPack" bind:value="{$application.build.pack}">
<option selected class="font-bold">Static</option>
<option class="font-bold">Node.js</option>
</select>
</div>
<div
class="grid grid-cols-2 space-y-2 max-w-2xl md:mx-auto mx-6 justify-center items-center"
>
<label for="Domain">Domain</label>
<input
class:placeholder-red-500="{$application.publish.domain == null || $application.publish.domain == ''}"
class:border-red-500="{$application.publish.domain == null || $application.publish.domain == ''}"
id="Domain"
bind:value="{$application.publish.domain}"
placeholder="eg: coollabs.io (without www)"
/>
<label for="Path">Path Prefix</label>
<input
id="Path"
bind:value="{$application.publish.path}"
placeholder="/"
/>
<label for="publishDir">Publish Directory</label>
<input
id="publishDir"
bind:value="{$application.publish.directory}"
placeholder="/"
/>
{#if $application.build.pack !== "static"}
<label for="Port">Port</label>
<div
class="grid grid-cols-1 text-sm max-w-2xl md:mx-auto mx-6 pb-6 auto-cols-max "
>
<label for="buildPack">Build Pack</label>
<select id="buildPack" bind:value="{$application.build.pack}">
<option selected class="font-bold">static</option>
<option class="font-bold">nodejs</option>
<option class="font-bold">php</option>
</select>
</div>
<div
class="grid grid-cols-1 max-w-2xl md:mx-auto mx-6 justify-center items-center"
>
<div class="grid grid-flow-col gap-2 items-center pb-6">
<div class="grid grid-flow-row">
<label for="Domain" class="">Domain</label>
<input
id="Port"
bind:value="{$application.publish.port}"
placeholder="{$application.build.pack === 'static'
? '80'
: '3000'}"
class:placeholder-red-500="{$application.publish.domain == null ||
$application.publish.domain == ''}"
class:border-red-500="{$application.publish.domain == null ||
$application.publish.domain == ''}"
id="Domain"
bind:value="{$application.publish.domain}"
placeholder="eg: coollabs.io (without www)"
/>
{/if}
</div>
<div class="grid grid-flow-row">
<label for="Path">Path</label>
<input
id="Path"
bind:value="{$application.publish.path}"
placeholder="/"
/>
</div>
</div>
</div>
<label for="publishDir">Publish Directory</label>
<input
id="publishDir"
bind:value="{$application.publish.directory}"
placeholder="/"
/>
{#if $application.build.pack === "nodejs"}
<label for="Port" class="pt-6">Port</label>
<input
id="Port"
bind:value="{$application.publish.port}"
placeholder="{$application.build.pack === 'static' ? '80' : '3000'}"
/>
{/if}
</div>
</div>

View File

@ -9,35 +9,38 @@
async function saveSecret() {
if (secret.name && secret.value) {
const found = $application.publish.secrets.find(
s => s.name === secret.name,
);
if (!found) {
$application.publish.secrets = [
...$application.publish.secrets,
{
name: secret.name,
value: secret.value,
},
];
secret = {
name: null,
value: null
s => s.name === secret.name,
);
if (!found) {
$application.publish.secrets = [
...$application.publish.secrets,
{
name: secret.name,
value: secret.value,
},
];
secret = {
name: null,
value: null,
};
} else {
foundSecret = found;
}
} else {
foundSecret = found;
}
}
}
async function removeSecret(name) {
$application.publish.secrets = [...$application.publish.secrets.filter(s => s.name !== name)]
foundSecret = null
$application.publish.secrets = [
...$application.publish.secrets.filter(s => s.name !== name),
];
}
</script>
<div class="space-y-2 max-w-2xl md:mx-auto mx-6 text-center">
<div class="text-left text-base font-bold tracking-tight text-warmGray-400">New Secret</div>
<div class="max-w-2xl md:mx-auto mx-6 text-center">
<div class="text-left text-base font-bold tracking-tight text-warmGray-400">
New Secret
</div>
<div class="grid md:grid-flow-col grid-flow-row gap-2">
<input id="secretName" bind:value="{secret.name}" placeholder="Name" />
<input id="secretValue" bind:value="{secret.value}" placeholder="Value" />
@ -47,26 +50,28 @@
>
</div>
{#if $application.publish.secrets.length > 0}
{#each $application.publish.secrets as s}
<div class="grid md:grid-flow-col grid-flow-row gap-2">
<input
id="{s.name}"
value="{s.name}"
disabled
class="bg-transparent border-transparent"
class:border-red-600="{foundSecret && foundSecret.name === s.name}"
/>
<input
id="{s.createdAt}"
value="ENCRYPTED"
disabled
class="bg-transparent border-transparent"
/>
<button
class="button w-20 bg-red-600 hover:bg-red-500 text-white"
on:click="{() => removeSecret(s.name)}">Delete</button
>
</div>
{/each}
<div class="py-4">
{#each $application.publish.secrets as s}
<div class="grid md:grid-flow-col grid-flow-row gap-2">
<input
id="{s.name}"
value="{s.name}"
disabled
class="border-2 bg-transparent border-transparent"
class:border-red-600="{foundSecret && foundSecret.name === s.name}"
/>
<input
id="{s.createdAt}"
value="SAVED"
disabled
class="bg-transparent border-transparent"
/>
<button
class="button w-20 bg-red-600 hover:bg-red-500 text-white"
on:click="{() => removeSecret(s.name)}">Delete</button
>
</div>
{/each}
</div>
{/if}
</div>

View File

@ -81,7 +81,7 @@
{ cache: "no-cache" },
)
.then(r => r.json());
return compareVersions(latest.version,packageJson.version)
return compareVersions(latest.version,packageJson.version) === 1 ? true : false
}
</script>

View File

@ -98,6 +98,10 @@
d="M224 508c-6.7 0-13.5-1.8-19.4-5.2l-61.7-36.5c-9.2-5.2-4.7-7-1.7-8 12.3-4.3 14.8-5.2 27.9-12.7 1.4-.8 3.2-.5 4.6.4l47.4 28.1c1.7 1 4.1 1 5.7 0l184.7-106.6c1.7-1 2.8-3 2.8-5V149.3c0-2.1-1.1-4-2.9-5.1L226.8 37.7c-1.7-1-4-1-5.7 0L36.6 144.3c-1.8 1-2.9 3-2.9 5.1v213.1c0 2 1.1 4 2.9 4.9l50.6 29.2c27.5 13.7 44.3-2.4 44.3-18.7V167.5c0-3 2.4-5.3 5.4-5.3h23.4c2.9 0 5.4 2.3 5.4 5.3V378c0 36.6-20 57.6-54.7 57.6-10.7 0-19.1 0-42.5-11.6l-48.4-27.9C8.1 389.2.7 376.3.7 362.4V149.3c0-13.8 7.4-26.8 19.4-33.7L204.6 9c11.7-6.6 27.2-6.6 38.8 0l184.7 106.7c12 6.9 19.4 19.8 19.4 33.7v213.1c0 13.8-7.4 26.7-19.4 33.7L243.4 502.8c-5.9 3.4-12.6 5.2-19.4 5.2zm149.1-210.1c0-39.9-27-50.5-83.7-58-57.4-7.6-63.2-11.5-63.2-24.9 0-11.1 4.9-25.9 47.4-25.9 37.9 0 51.9 8.2 57.7 33.8.5 2.4 2.7 4.2 5.2 4.2h24c1.5 0 2.9-.6 3.9-1.7s1.5-2.6 1.4-4.1c-3.7-44.1-33-64.6-92.2-64.6-52.7 0-84.1 22.2-84.1 59.5 0 40.4 31.3 51.6 81.8 56.6 60.5 5.9 65.2 14.8 65.2 26.7 0 20.6-16.6 29.4-55.5 29.4-48.9 0-59.6-12.3-63.2-36.6-.4-2.6-2.6-4.5-5.3-4.5h-23.9c-3 0-5.3 2.4-5.3 5.3 0 31.1 16.9 68.2 97.8 68.2 58.4-.1 92-23.2 92-63.4z"
></path>
</svg>
{:else if application.Spec.Labels.configuration.build.pack === "php"}
<svg viewBox="0 0 128 128" class="text-white w-14 h-14 absolute top-0 left-0 -m-6">
<path fill="#6181B6" d="M64 33.039c-33.74 0-61.094 13.862-61.094 30.961s27.354 30.961 61.094 30.961 61.094-13.862 61.094-30.961-27.354-30.961-61.094-30.961zm-15.897 36.993c-1.458 1.364-3.077 1.927-4.86 2.507-1.783.581-4.052.461-6.811.461h-6.253l-1.733 10h-7.301l6.515-34h14.04c4.224 0 7.305 1.215 9.242 3.432 1.937 2.217 2.519 5.364 1.747 9.337-.319 1.637-.856 3.159-1.614 4.515-.759 1.357-1.75 2.624-2.972 3.748zm21.311 2.968l2.881-14.42c.328-1.688.208-2.942-.361-3.555-.57-.614-1.782-1.025-3.635-1.025h-5.79l-3.731 19h-7.244l6.515-33h7.244l-1.732 9h6.453c4.061 0 6.861.815 8.402 2.231s2.003 3.356 1.387 6.528l-3.031 15.241h-7.358zm40.259-11.178c-.318 1.637-.856 3.133-1.613 4.488-.758 1.357-1.748 2.598-2.971 3.722-1.458 1.364-3.078 1.927-4.86 2.507-1.782.581-4.053.461-6.812.461h-6.253l-1.732 10h-7.301l6.514-34h14.041c4.224 0 7.305 1.215 9.241 3.432 1.935 2.217 2.518 5.418 1.746 9.39zM95.919 54h-5.001l-2.727 14h4.442c2.942 0 5.136-.29 6.576-1.4 1.442-1.108 2.413-2.828 2.918-5.421.484-2.491.264-4.434-.66-5.458-.925-1.024-2.774-1.721-5.548-1.721zM38.934 54h-5.002l-2.727 14h4.441c2.943 0 5.136-.29 6.577-1.4 1.441-1.108 2.413-2.828 2.917-5.421.484-2.491.264-4.434-.66-5.458s-2.772-1.721-5.546-1.721z"></path>
</svg>
{/if}
<div
class="text-xs font-bold text-center w-full text-warmGray-300 group-hover:text-white"

6388
yarn.lock Normal file

File diff suppressed because it is too large Load Diff