Use nodejs image to build js related docker images

This commit is contained in:
Igor Kulikov 2021-12-14 17:29:03 +02:00
parent 9bc12ab6d7
commit 3d8d50d172
11 changed files with 143 additions and 111 deletions

View File

@ -14,26 +14,29 @@
# limitations under the License.
#
FROM thingsboard/base
FROM node:16.13.1-buster-slim
ARG TARGETPLATFORM
COPY start-js-executor.sh ${pkg.name}.deb ${pkg.name}-arm64.deb /tmp/
COPY start-js-executor.sh /tmp/
RUN chmod a+x /tmp/*.sh \
&& mv /tmp/start-js-executor.sh /usr/bin
RUN if [ "$TARGETPLATFORM" = "linux/arm64" ]; \
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
ENV NODE_ENV production
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"]

View File

@ -20,12 +20,10 @@ echo "Starting '${project.name}' ..."
CONF_FOLDER="${pkg.installFolder}/conf"
mainfile=${pkg.installFolder}/bin/${pkg.name}
configfile=${pkg.name}.conf
identity=${pkg.name}
source "${CONF_FOLDER}/${configfile}"
cd ${pkg.installFolder}/bin
cd ${pkg.installFolder}
exec /bin/sh -c "$mainfile"
exec /bin/sh -c "node server.js"

View File

@ -21,13 +21,10 @@ let _projectRoot = null;
(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'),
{overwrite: true});
await fse.move(path.join(projectRoot(), 'target', 'thingsboard-js-executor-linux-arm64'),
path.join(targetPackageDir('linux'), 'bin-arm64', 'tb-js-executor'),
{overwrite: true});
await fse.move(path.join(projectRoot(), 'target', 'thingsboard-js-executor-win-x64.exe'),
await fse.move(path.join(projectRoot(), 'target', 'thingsboard-js-executor-win.exe'),
path.join(targetPackageDir('windows'), 'bin', 'tb-js-executor.exe'),
{overwrite: true});
})();

View File

@ -6,7 +6,7 @@
"main": "server.js",
"bin": "server.js",
"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",
"start": "nodemon server.js",
"start-prod": "NODE_ENV=production nodemon server.js"
@ -27,9 +27,6 @@
"winston": "^3.3.3",
"winston-daily-rotate-file": "^4.5.0"
},
"engines": {
"node": ">=12.0.0 <14.0.0"
},
"nyc": {
"exclude": [
"test",

View File

@ -84,6 +84,15 @@
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>yarn pkg</id>
<goals>
<goal>yarn</goal>
</goals>
<configuration>
<arguments>run pkg</arguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
@ -93,6 +102,61 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<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>
<groupId>org.thingsboard</groupId>

View File

@ -14,26 +14,28 @@
# limitations under the License.
#
FROM thingsboard/base
FROM node:16.13.1-buster-slim
ARG TARGETPLATFORM
COPY start-web-ui.sh ${pkg.name}.deb ${pkg.name}-arm64.deb /tmp/
COPY start-web-ui.sh /tmp/
RUN chmod a+x /tmp/*.sh \
&& mv /tmp/start-web-ui.sh /usr/bin
RUN if [ "$TARGETPLATFORM" = "linux/arm64" ]; \
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
ENV NODE_ENV production
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"]

View File

@ -20,12 +20,10 @@ echo "Starting '${project.name}' ..."
CONF_FOLDER="${pkg.installFolder}/conf"
mainfile=${pkg.installFolder}/bin/${pkg.name}
configfile=${pkg.name}.conf
identity=${pkg.name}
source "${CONF_FOLDER}/${configfile}"
cd ${pkg.installFolder}/bin
cd ${pkg.installFolder}
exec /bin/sh -c "$mainfile"
exec /bin/sh -c "node server.js"

View File

@ -21,13 +21,10 @@ let _projectRoot = null;
(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'),
{overwrite: true});
await fse.move(path.join(projectRoot(), 'target', 'thingsboard-web-ui-linux-arm64'),
path.join(targetPackageDir('linux'), 'bin-arm64', 'tb-web-ui'),
{overwrite: true});
await fse.move(path.join(projectRoot(), 'target', 'thingsboard-web-ui-win-x64.exe'),
await fse.move(path.join(projectRoot(), 'target', 'thingsboard-web-ui-win.exe'),
path.join(targetPackageDir('windows'), 'bin', 'tb-web-ui.exe'),
{overwrite: true});
})();

View File

@ -6,7 +6,7 @@
"main": "server.js",
"bin": "server.js",
"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",
"start": "WEB_FOLDER=./target/web nodemon server.js",
"start-prod": "NODE_ENV=production nodemon server.js"
@ -22,9 +22,6 @@
"winston": "^3.3.3",
"winston-daily-rotate-file": "^4.5.0"
},
"engines": {
"node": ">=12.0.0 <14.0.0"
},
"nyc": {
"exclude": [
"test",

View File

@ -93,6 +93,15 @@
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>yarn pkg</id>
<goals>
<goal>yarn</goal>
</goals>
<configuration>
<arguments>run pkg</arguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
@ -140,6 +149,29 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<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>
<groupId>org.thingsboard</groupId>

View File

@ -36,6 +36,12 @@ ospackage {
user pkgUser
permissionGroup pkgUser
// Copy the executable file
from("${buildDir}/package/linux/bin/${pkgName}") {
fileMode 0500
into "bin"
}
// Copy the init file
from("${buildDir}/package/linux/init/template") {
fileMode 0500
@ -72,17 +78,9 @@ buildRpm {
preUninstall file("${buildDir}/control/rpm/prerm")
postUninstall file("${buildDir}/control/rpm/postrm")
into pkgInstallFolder
user pkgUser
permissionGroup pkgUser
// Copy the executable file
from("${buildDir}/package/linux/bin/${pkgName}") {
fileMode 0500
into "bin"
}
// Copy the system unit files
from("${buildDir}/control/template.service") {
addParentDirs = false
@ -113,17 +111,9 @@ buildDeb {
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/${pkgName}") {
fileMode 0500
into "bin"
}
// Copy the system unit files
from("${buildDir}/control/template.service") {
addParentDirs = false
@ -136,46 +126,3 @@ buildDeb {
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