Use nodejs image to build js related docker images
This commit is contained in:
parent
9bc12ab6d7
commit
3d8d50d172
@ -14,26 +14,29 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
FROM thingsboard/base
|
FROM node:16.13.1-buster-slim
|
||||||
|
|
||||||
ARG TARGETPLATFORM
|
COPY start-js-executor.sh /tmp/
|
||||||
|
|
||||||
COPY start-js-executor.sh ${pkg.name}.deb ${pkg.name}-arm64.deb /tmp/
|
|
||||||
|
|
||||||
RUN chmod a+x /tmp/*.sh \
|
RUN chmod a+x /tmp/*.sh \
|
||||||
&& mv /tmp/start-js-executor.sh /usr/bin
|
&& mv /tmp/start-js-executor.sh /usr/bin
|
||||||
|
|
||||||
RUN if [ "$TARGETPLATFORM" = "linux/arm64" ]; \
|
ENV NODE_ENV production
|
||||||
then yes | dpkg -i /tmp/${pkg.name}-arm64.deb; \
|
|
||||||
else yes | dpkg -i /tmp/${pkg.name}.deb; \
|
|
||||||
fi
|
|
||||||
RUN rm /tmp/${pkg.name}.deb
|
|
||||||
RUN rm /tmp/${pkg.name}-arm64.deb
|
|
||||||
|
|
||||||
RUN systemctl --no-reload disable --now ${pkg.name}.service > /dev/null 2>&1 || :
|
WORKDIR ${pkg.installFolder}
|
||||||
|
|
||||||
RUN chmod 555 ${pkg.installFolder}/bin/${pkg.name}
|
COPY ["src/package.json", "src/yarn.lock", "./"]
|
||||||
|
|
||||||
USER ${pkg.user}
|
COPY package/linux/conf ./conf
|
||||||
|
COPY package/linux/conf ./config
|
||||||
|
COPY src/api ./api
|
||||||
|
COPY src/queue ./queue
|
||||||
|
COPY src/server.js ./
|
||||||
|
|
||||||
|
RUN chown -R node:node ${pkg.installFolder}
|
||||||
|
|
||||||
|
RUN yarn install --production && yarn cache clean --all
|
||||||
|
|
||||||
|
USER node
|
||||||
|
|
||||||
CMD ["start-js-executor.sh"]
|
CMD ["start-js-executor.sh"]
|
||||||
|
|||||||
@ -20,12 +20,10 @@ echo "Starting '${project.name}' ..."
|
|||||||
|
|
||||||
CONF_FOLDER="${pkg.installFolder}/conf"
|
CONF_FOLDER="${pkg.installFolder}/conf"
|
||||||
|
|
||||||
mainfile=${pkg.installFolder}/bin/${pkg.name}
|
|
||||||
configfile=${pkg.name}.conf
|
configfile=${pkg.name}.conf
|
||||||
identity=${pkg.name}
|
|
||||||
|
|
||||||
source "${CONF_FOLDER}/${configfile}"
|
source "${CONF_FOLDER}/${configfile}"
|
||||||
|
|
||||||
cd ${pkg.installFolder}/bin
|
cd ${pkg.installFolder}
|
||||||
|
|
||||||
exec /bin/sh -c "$mainfile"
|
exec /bin/sh -c "node server.js"
|
||||||
|
|||||||
@ -21,13 +21,10 @@ let _projectRoot = null;
|
|||||||
|
|
||||||
|
|
||||||
(async() => {
|
(async() => {
|
||||||
await fse.move(path.join(projectRoot(), 'target', 'thingsboard-js-executor-linux-x64'),
|
await fse.move(path.join(projectRoot(), 'target', 'thingsboard-js-executor-linux'),
|
||||||
path.join(targetPackageDir('linux'), 'bin', 'tb-js-executor'),
|
path.join(targetPackageDir('linux'), 'bin', 'tb-js-executor'),
|
||||||
{overwrite: true});
|
{overwrite: true});
|
||||||
await fse.move(path.join(projectRoot(), 'target', 'thingsboard-js-executor-linux-arm64'),
|
await fse.move(path.join(projectRoot(), 'target', 'thingsboard-js-executor-win.exe'),
|
||||||
path.join(targetPackageDir('linux'), 'bin-arm64', 'tb-js-executor'),
|
|
||||||
{overwrite: true});
|
|
||||||
await fse.move(path.join(projectRoot(), 'target', 'thingsboard-js-executor-win-x64.exe'),
|
|
||||||
path.join(targetPackageDir('windows'), 'bin', 'tb-js-executor.exe'),
|
path.join(targetPackageDir('windows'), 'bin', 'tb-js-executor.exe'),
|
||||||
{overwrite: true});
|
{overwrite: true});
|
||||||
})();
|
})();
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
"main": "server.js",
|
"main": "server.js",
|
||||||
"bin": "server.js",
|
"bin": "server.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"install": "pkg -t node12-linux-x64,node12-linux-arm64,node12-win-x64 --out-path ./target . && node install.js",
|
"pkg": "pkg -t node12-linux-x64,node12-win-x64 --out-path ./target . && node install.js",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1",
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
"start": "nodemon server.js",
|
"start": "nodemon server.js",
|
||||||
"start-prod": "NODE_ENV=production nodemon server.js"
|
"start-prod": "NODE_ENV=production nodemon server.js"
|
||||||
@ -27,9 +27,6 @@
|
|||||||
"winston": "^3.3.3",
|
"winston": "^3.3.3",
|
||||||
"winston-daily-rotate-file": "^4.5.0"
|
"winston-daily-rotate-file": "^4.5.0"
|
||||||
},
|
},
|
||||||
"engines": {
|
|
||||||
"node": ">=12.0.0 <14.0.0"
|
|
||||||
},
|
|
||||||
"nyc": {
|
"nyc": {
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"test",
|
"test",
|
||||||
|
|||||||
@ -84,6 +84,15 @@
|
|||||||
<arguments>install</arguments>
|
<arguments>install</arguments>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>yarn pkg</id>
|
||||||
|
<goals>
|
||||||
|
<goal>yarn</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<arguments>run pkg</arguments>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
@ -93,6 +102,61 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-resources-plugin</artifactId>
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>copy-src-api</id>
|
||||||
|
<phase>process-resources</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>copy-resources</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<outputDirectory>${project.build.directory}/src/api</outputDirectory>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>api</directory>
|
||||||
|
<filtering>false</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>copy-src-queue</id>
|
||||||
|
<phase>process-resources</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>copy-resources</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<outputDirectory>${project.build.directory}/src/queue</outputDirectory>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>queue</directory>
|
||||||
|
<filtering>false</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>copy-src-root</id>
|
||||||
|
<phase>process-resources</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>copy-resources</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<outputDirectory>${project.build.directory}/src</outputDirectory>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>${basedir}</directory>
|
||||||
|
<includes>
|
||||||
|
<include>server.js</include>
|
||||||
|
<include>package.json</include>
|
||||||
|
<include>yarn.lock</include>
|
||||||
|
</includes>
|
||||||
|
<filtering>false</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.thingsboard</groupId>
|
<groupId>org.thingsboard</groupId>
|
||||||
|
|||||||
@ -14,26 +14,28 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
FROM thingsboard/base
|
FROM node:16.13.1-buster-slim
|
||||||
|
|
||||||
ARG TARGETPLATFORM
|
COPY start-web-ui.sh /tmp/
|
||||||
|
|
||||||
COPY start-web-ui.sh ${pkg.name}.deb ${pkg.name}-arm64.deb /tmp/
|
|
||||||
|
|
||||||
RUN chmod a+x /tmp/*.sh \
|
RUN chmod a+x /tmp/*.sh \
|
||||||
&& mv /tmp/start-web-ui.sh /usr/bin
|
&& mv /tmp/start-web-ui.sh /usr/bin
|
||||||
|
|
||||||
RUN if [ "$TARGETPLATFORM" = "linux/arm64" ]; \
|
ENV NODE_ENV production
|
||||||
then yes | dpkg -i /tmp/${pkg.name}-arm64.deb; \
|
|
||||||
else yes | dpkg -i /tmp/${pkg.name}.deb; \
|
|
||||||
fi
|
|
||||||
RUN rm /tmp/${pkg.name}.deb
|
|
||||||
RUN rm /tmp/${pkg.name}-arm64.deb
|
|
||||||
|
|
||||||
RUN systemctl --no-reload disable --now ${pkg.name}.service > /dev/null 2>&1 || :
|
WORKDIR ${pkg.installFolder}
|
||||||
|
|
||||||
RUN chmod 555 ${pkg.installFolder}/bin/${pkg.name}
|
COPY ["src/package.json", "src/yarn.lock", "./"]
|
||||||
|
|
||||||
USER ${pkg.user}
|
COPY package/linux/conf ./conf
|
||||||
|
COPY package/linux/conf ./config
|
||||||
|
COPY web ./web
|
||||||
|
COPY src/server.js ./
|
||||||
|
|
||||||
|
RUN chown -R node:node ${pkg.installFolder}
|
||||||
|
|
||||||
|
RUN yarn install --production && yarn cache clean --all
|
||||||
|
|
||||||
|
USER node
|
||||||
|
|
||||||
CMD ["start-web-ui.sh"]
|
CMD ["start-web-ui.sh"]
|
||||||
|
|||||||
@ -20,12 +20,10 @@ echo "Starting '${project.name}' ..."
|
|||||||
|
|
||||||
CONF_FOLDER="${pkg.installFolder}/conf"
|
CONF_FOLDER="${pkg.installFolder}/conf"
|
||||||
|
|
||||||
mainfile=${pkg.installFolder}/bin/${pkg.name}
|
|
||||||
configfile=${pkg.name}.conf
|
configfile=${pkg.name}.conf
|
||||||
identity=${pkg.name}
|
|
||||||
|
|
||||||
source "${CONF_FOLDER}/${configfile}"
|
source "${CONF_FOLDER}/${configfile}"
|
||||||
|
|
||||||
cd ${pkg.installFolder}/bin
|
cd ${pkg.installFolder}
|
||||||
|
|
||||||
exec /bin/sh -c "$mainfile"
|
exec /bin/sh -c "node server.js"
|
||||||
|
|||||||
@ -21,13 +21,10 @@ let _projectRoot = null;
|
|||||||
|
|
||||||
|
|
||||||
(async() => {
|
(async() => {
|
||||||
await fse.move(path.join(projectRoot(), 'target', 'thingsboard-web-ui-linux-x64'),
|
await fse.move(path.join(projectRoot(), 'target', 'thingsboard-web-ui-linux'),
|
||||||
path.join(targetPackageDir('linux'), 'bin', 'tb-web-ui'),
|
path.join(targetPackageDir('linux'), 'bin', 'tb-web-ui'),
|
||||||
{overwrite: true});
|
{overwrite: true});
|
||||||
await fse.move(path.join(projectRoot(), 'target', 'thingsboard-web-ui-linux-arm64'),
|
await fse.move(path.join(projectRoot(), 'target', 'thingsboard-web-ui-win.exe'),
|
||||||
path.join(targetPackageDir('linux'), 'bin-arm64', 'tb-web-ui'),
|
|
||||||
{overwrite: true});
|
|
||||||
await fse.move(path.join(projectRoot(), 'target', 'thingsboard-web-ui-win-x64.exe'),
|
|
||||||
path.join(targetPackageDir('windows'), 'bin', 'tb-web-ui.exe'),
|
path.join(targetPackageDir('windows'), 'bin', 'tb-web-ui.exe'),
|
||||||
{overwrite: true});
|
{overwrite: true});
|
||||||
})();
|
})();
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
"main": "server.js",
|
"main": "server.js",
|
||||||
"bin": "server.js",
|
"bin": "server.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"install": "pkg -t node12-linux-x64,node12-linux-arm64,node12-win-x64 --out-path ./target . && node install.js",
|
"pkg": "pkg -t node12-linux-x64,node12-win-x64 --out-path ./target . && node install.js",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1",
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
"start": "WEB_FOLDER=./target/web nodemon server.js",
|
"start": "WEB_FOLDER=./target/web nodemon server.js",
|
||||||
"start-prod": "NODE_ENV=production nodemon server.js"
|
"start-prod": "NODE_ENV=production nodemon server.js"
|
||||||
@ -22,9 +22,6 @@
|
|||||||
"winston": "^3.3.3",
|
"winston": "^3.3.3",
|
||||||
"winston-daily-rotate-file": "^4.5.0"
|
"winston-daily-rotate-file": "^4.5.0"
|
||||||
},
|
},
|
||||||
"engines": {
|
|
||||||
"node": ">=12.0.0 <14.0.0"
|
|
||||||
},
|
|
||||||
"nyc": {
|
"nyc": {
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"test",
|
"test",
|
||||||
|
|||||||
@ -93,6 +93,15 @@
|
|||||||
<arguments>install</arguments>
|
<arguments>install</arguments>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>yarn pkg</id>
|
||||||
|
<goals>
|
||||||
|
<goal>yarn</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<arguments>run pkg</arguments>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
@ -140,6 +149,29 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-resources-plugin</artifactId>
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>copy-src-root</id>
|
||||||
|
<phase>process-resources</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>copy-resources</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<outputDirectory>${project.build.directory}/src</outputDirectory>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>${basedir}</directory>
|
||||||
|
<includes>
|
||||||
|
<include>server.js</include>
|
||||||
|
<include>package.json</include>
|
||||||
|
<include>yarn.lock</include>
|
||||||
|
</includes>
|
||||||
|
<filtering>false</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.thingsboard</groupId>
|
<groupId>org.thingsboard</groupId>
|
||||||
|
|||||||
@ -36,6 +36,12 @@ ospackage {
|
|||||||
user pkgUser
|
user pkgUser
|
||||||
permissionGroup pkgUser
|
permissionGroup pkgUser
|
||||||
|
|
||||||
|
// Copy the executable file
|
||||||
|
from("${buildDir}/package/linux/bin/${pkgName}") {
|
||||||
|
fileMode 0500
|
||||||
|
into "bin"
|
||||||
|
}
|
||||||
|
|
||||||
// Copy the init file
|
// Copy the init file
|
||||||
from("${buildDir}/package/linux/init/template") {
|
from("${buildDir}/package/linux/init/template") {
|
||||||
fileMode 0500
|
fileMode 0500
|
||||||
@ -72,17 +78,9 @@ buildRpm {
|
|||||||
preUninstall file("${buildDir}/control/rpm/prerm")
|
preUninstall file("${buildDir}/control/rpm/prerm")
|
||||||
postUninstall file("${buildDir}/control/rpm/postrm")
|
postUninstall file("${buildDir}/control/rpm/postrm")
|
||||||
|
|
||||||
into pkgInstallFolder
|
|
||||||
|
|
||||||
user pkgUser
|
user pkgUser
|
||||||
permissionGroup pkgUser
|
permissionGroup pkgUser
|
||||||
|
|
||||||
// Copy the executable file
|
|
||||||
from("${buildDir}/package/linux/bin/${pkgName}") {
|
|
||||||
fileMode 0500
|
|
||||||
into "bin"
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copy the system unit files
|
// Copy the system unit files
|
||||||
from("${buildDir}/control/template.service") {
|
from("${buildDir}/control/template.service") {
|
||||||
addParentDirs = false
|
addParentDirs = false
|
||||||
@ -113,17 +111,9 @@ buildDeb {
|
|||||||
preUninstall file("${buildDir}/control/deb/prerm")
|
preUninstall file("${buildDir}/control/deb/prerm")
|
||||||
postUninstall file("${buildDir}/control/deb/postrm")
|
postUninstall file("${buildDir}/control/deb/postrm")
|
||||||
|
|
||||||
into pkgInstallFolder
|
|
||||||
|
|
||||||
user pkgUser
|
user pkgUser
|
||||||
permissionGroup pkgUser
|
permissionGroup pkgUser
|
||||||
|
|
||||||
// Copy the executable file
|
|
||||||
from("${buildDir}/package/linux/bin/${pkgName}") {
|
|
||||||
fileMode 0500
|
|
||||||
into "bin"
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copy the system unit files
|
// Copy the system unit files
|
||||||
from("${buildDir}/control/template.service") {
|
from("${buildDir}/control/template.service") {
|
||||||
addParentDirs = false
|
addParentDirs = false
|
||||||
@ -136,46 +126,3 @@ buildDeb {
|
|||||||
|
|
||||||
link("/etc/${pkgName}/conf", "${pkgInstallFolder}/conf")
|
link("/etc/${pkgName}/conf", "${pkgInstallFolder}/conf")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Same as the buildRpm task
|
|
||||||
task buildDebArm64(type: Deb) {
|
|
||||||
|
|
||||||
arch = "arm64"
|
|
||||||
|
|
||||||
archiveFileName = "${pkgName}-arm64.deb"
|
|
||||||
|
|
||||||
configurationFile("${pkgInstallFolder}/conf/${pkgName}.conf")
|
|
||||||
configurationFile("${pkgInstallFolder}/conf/custom-environment-variables.yml")
|
|
||||||
configurationFile("${pkgInstallFolder}/conf/default.yml")
|
|
||||||
configurationFile("${pkgInstallFolder}/conf/logger.js")
|
|
||||||
|
|
||||||
preInstall file("${buildDir}/control/deb/preinst")
|
|
||||||
postInstall file("${buildDir}/control/deb/postinst")
|
|
||||||
preUninstall file("${buildDir}/control/deb/prerm")
|
|
||||||
postUninstall file("${buildDir}/control/deb/postrm")
|
|
||||||
|
|
||||||
into pkgInstallFolder
|
|
||||||
|
|
||||||
user pkgUser
|
|
||||||
permissionGroup pkgUser
|
|
||||||
|
|
||||||
// Copy the executable file
|
|
||||||
from("${buildDir}/package/linux/bin-arm64/${pkgName}") {
|
|
||||||
fileMode 0500
|
|
||||||
into "bin"
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copy the system unit files
|
|
||||||
from("${buildDir}/control/template.service") {
|
|
||||||
addParentDirs = false
|
|
||||||
fileMode 0644
|
|
||||||
into "/lib/systemd/system"
|
|
||||||
rename { String filename ->
|
|
||||||
"${pkgName}.service"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
link("/etc/${pkgName}/conf", "${pkgInstallFolder}/conf")
|
|
||||||
}
|
|
||||||
|
|
||||||
buildDeb.finalizedBy buildDebArm64
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user