mirror of
https://github.com/caprover/caprover
synced 2025-12-13 06:45:48 +00:00
Added edge config and also updated the deploy script
This commit is contained in:
@@ -1,49 +1,89 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const exec = require('child_process').exec;
|
||||
const request = require('request');
|
||||
const execOriginal = require('child_process').exec;
|
||||
const requestOriginal = require('request');
|
||||
|
||||
const version = require('./src/utils/CaptainConstants').version;
|
||||
const publishedNameOnDockerHub = require('./src/utils/CaptainConstants').publishedNameOnDockerHub;
|
||||
function exec(command) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
execOriginal(command, function (err, stdout, stderr) {
|
||||
|
||||
console.log(version);
|
||||
console.log(' ');
|
||||
|
||||
|
||||
exec('git status', function (err, stdout, stderr) {
|
||||
if (stderr) {
|
||||
console.log('stderr');
|
||||
console.log(stderr);
|
||||
}
|
||||
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return;
|
||||
reject(err)
|
||||
return
|
||||
}
|
||||
|
||||
var l1 = 'On branch master';
|
||||
var l2 = 'Your branch is up to date with \'origin/master\'';
|
||||
var l3 = 'nothing to commit, working tree clean';
|
||||
|
||||
if (stdout.indexOf(l1) < 0 || stdout.indexOf(l2) < 0 || stdout.indexOf(l3) < 0) {
|
||||
console.log('Make sure you are on master branch, in sync with remote, and your working directory is clean');
|
||||
return;
|
||||
resolve(stdout)
|
||||
})
|
||||
})
|
||||
}
|
||||
fetchTagsFromHub();
|
||||
});
|
||||
|
||||
function fetchTagsFromHub() {
|
||||
|
||||
var URL = 'https://hub.docker.com/v2/repositories/' + publishedNameOnDockerHub + '/tags';
|
||||
|
||||
request(URL, function (error, response, body) {
|
||||
|
||||
function request(url) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
requestOriginal(url, function (error, response, body) {
|
||||
if (body) {
|
||||
body = JSON.parse(body);
|
||||
}
|
||||
|
||||
if (error || !body || !body.results || !body.results.length) {
|
||||
if (error || !body) {
|
||||
console.log('Error while fetching tags from Docker Hub!');
|
||||
console.log(error);
|
||||
reject(error);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
resolve(body)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
const publishedNameOnDockerHub = 'caprover/caprover';
|
||||
let version = ''
|
||||
|
||||
exec('npm run build')
|
||||
.then(function (data) {
|
||||
data = (data + '').trim()
|
||||
console.log('----------')
|
||||
console.log(data)
|
||||
console.log('----------')
|
||||
if (!data.startsWith('> caprover@0.0.0') || !data.endsWith('rm -rf ./built && npx tsc')) {
|
||||
console.log('Unexpected output:')
|
||||
throw new Error(data)
|
||||
}
|
||||
|
||||
version = require('./built/utils/CaptainConstants').configs.version;
|
||||
|
||||
return exec('git status')
|
||||
})
|
||||
.then(function (data) {
|
||||
var l1 = 'On branch master';
|
||||
var l2 = 'Your branch is up to date with \'origin/master\'';
|
||||
var l3 = 'nothing to commit, working tree clean';
|
||||
|
||||
if (data.indexOf(l1) < 0 || data.indexOf(l2) < 0 || data.indexOf(l3) < 0) {
|
||||
console.log('Make sure you are on master branch, in sync with remote, and your working directory is clean');
|
||||
throw new Error(data)
|
||||
}
|
||||
|
||||
var URL = 'https://hub.docker.com/v2/repositories/' + publishedNameOnDockerHub + '/tags';
|
||||
|
||||
return request(URL)
|
||||
|
||||
})
|
||||
.then(function (body) {
|
||||
|
||||
if (!body.results || !body.results.length) {
|
||||
console.log('Error while fetching tags from Docker Hub!');
|
||||
throw error;
|
||||
}
|
||||
|
||||
var highestTag = '';
|
||||
var highestTagValue = 0;
|
||||
|
||||
@@ -77,40 +117,26 @@ function fetchTagsFromHub() {
|
||||
}
|
||||
}
|
||||
|
||||
if (!isVersionValid || !highestTagValue) {
|
||||
console.log('The version you are pushing is not valid!');
|
||||
return;
|
||||
if (!isVersionValid || !highestTagValue || !version) {
|
||||
throw new Error('The version you are pushing is not valid! ' + version);
|
||||
}
|
||||
|
||||
console.log('Pushing ' + version);
|
||||
|
||||
buildAndPush();
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function buildAndPush() {
|
||||
|
||||
var t1 = publishedNameOnDockerHub + ':' + 'latest';
|
||||
var t2 = publishedNameOnDockerHub + ':' + version;
|
||||
let command = 'docker build -t ' + t1 + ' -t ' + t2 + ' -f dockerfile-captain.release . && docker push ' + t1 + ' && docker push ' + t2;
|
||||
exec(command, function (err, stdout, stderr) {
|
||||
|
||||
if (err) {
|
||||
console.log('ERROR');
|
||||
console.log(err);
|
||||
}
|
||||
|
||||
return exec(`docker build -t ${t1} -t ${t2} -f dockerfile-captain.release . && docker push ${t1} && docker push ${t2}`)
|
||||
})
|
||||
.then(function (stdout) {
|
||||
if (stdout) {
|
||||
console.log('stdout');
|
||||
console.log(stdout);
|
||||
}
|
||||
if (stderr) {
|
||||
console.log('stderr');
|
||||
console.log(stderr);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
})
|
||||
.catch(function (err) {
|
||||
console.error(err)
|
||||
process.exit(1)
|
||||
})
|
||||
4
dev-scripts/build_and_push_edge.sh
Executable file
4
dev-scripts/build_and_push_edge.sh
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
|
||||
docker build -t caprover/caprover-edge:latest -f dockerfile-captain.edge .
|
||||
docker push caprover/caprover-edge:latest
|
||||
28
dockerfile-captain.edge
Normal file
28
dockerfile-captain.edge
Normal file
@@ -0,0 +1,28 @@
|
||||
FROM node:10
|
||||
RUN mkdir -p /usr/src/app
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
|
||||
# Build backend code
|
||||
|
||||
COPY package.json /usr/src/app/
|
||||
RUN npm install && npm cache clean --force
|
||||
COPY . /usr/src/app
|
||||
RUN npm run build
|
||||
RUN mv edge-overrride.json overrride.json
|
||||
|
||||
|
||||
# Build frontend code
|
||||
|
||||
RUN git clone https://github.com/githubsaturn/caprover-frontend.git && \
|
||||
cd caprover-frontend && \
|
||||
npm install && npm cache clean --force && \
|
||||
npm run build &&
|
||||
mv ./build ../dist-frontend
|
||||
|
||||
|
||||
ENV NODE_ENV production
|
||||
ENV PORT 3000
|
||||
EXPOSE 3000
|
||||
|
||||
CMD ["npm" , "start"]
|
||||
4
edge-override.json
Normal file
4
edge-override.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"publishedNameOnDockerHub": "caprover/caprover-edge",
|
||||
"version": "0.0.1"
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
"dev": "echo 'RECOMPILING' && npx madge --circular --extensions ts ./ && rm -rf ./built && npx tsc && sudo ./dev-scripts/dev-reset-service.sh",
|
||||
"clean": "sudo ./dev-scripts/dev-clean-run-as-dev.sh",
|
||||
"tslint": "tslint -c tslint.json -p tsconfig.json",
|
||||
"build": "npx tsc",
|
||||
"build": "rm -rf ./built && npx tsc",
|
||||
"test": "jest"
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
Reference in New Issue
Block a user