diff --git a/.env.default b/.env.default new file mode 100644 index 0000000..7d59c08 --- /dev/null +++ b/.env.default @@ -0,0 +1,6 @@ +KEY_STORE= +KEY_PASS= +SDK_PATH=$HOME/sdk +PUBLISH_PATH=$HOME/public/puzzlez +BUILD_PATH=./build +TARGET_PATH=./target \ No newline at end of file diff --git a/.gitignore b/.gitignore index 88f146f..c502343 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ config.json /log /ansible/*.retry .npmrc +.env \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5122ea0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +FROM ubuntu:noble AS base +RUN apt update && apt install -y \ + nodejs \ + npm \ + openjdk-11-jre \ + protobuf-compiler \ + jq +RUN node -v +RUN npm -v + +FROM base AS builder +ENV GRADLE_USER_HOME=/sdk/gradle +WORKDIR /app +COPY package.json package-lock.json ./ +RUN npm ci +COPY gulpfile.js protohx.json ./ +COPY tasks ./tasks +COPY config.example.json ./config.example.json +RUN --mount=type=secret,id=KEY_STORE \ + cat /run/secrets/KEY_STORE > ./key.jks +RUN --mount=type=secret,id=KEY_PASS,env=KEY_PASS \ + jq --arg key_pass "$KEY_PASS" \ + '.SdkDir = "/sdk" | .PublishDir = "/app/publish" | .Key.store = "key.jks" | .Key.pass = $key_pass' \ + config.example.json > config.json +COPY src ./src +COPY dependencies ./dependencies +VOLUME ["/sdk", "/app/build", "/app/target", "/app/publish", "/app/src-gen"] +CMD ["npx", "gulp", "default"] diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..f6d8c4d --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,22 @@ +name: puzzlez +services: + builder: + container_name: puzzlez-builder + image: infernal-games/puzzlez-builder + build: + context: . + secrets: + - KEY_STORE + - KEY_PASS + volumes: + - ${SDK_PATH}:/sdk + - ${BUILD_PATH}:/app/build + - ${TARGET_PATH}:/app/target + - ${PUBLISH_PATH}:/app/publish + - ./src-gen:/app/src-gen + +secrets: + KEY_STORE: + file: $KEY_STORE + KEY_PASS: + environment: KEY_PASS diff --git a/gulpfile.js b/gulpfile.js index c365301..f1b8298 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,139 +1,139 @@ -const gulp = require('gulp'); -const gulpClean = require('gulp-clean'); -const Config = require('./config.json'); -const packageInfo = require('./package.json'); -const {System, Sdk, Haxe, Project} = require('gulp-haxetool'); -const dateformat = require('dateformat'); -const argv = require('yargs').argv; -const publish = require('./tasks/gulp-publish'); +const gulp = require("gulp"); +const gulpClean = require("gulp-clean"); +const Config = require("./config.json"); +const packageInfo = require("./package.json"); +const { System, Sdk, Haxe, Project } = require("gulp-haxetool"); +const dateformat = require("dateformat"); +const publish = require("./tasks/gulp-publish"); if (packageInfo.haxe) { - Haxe.VERSION = packageInfo.haxe; + Haxe.VERSION = packageInfo.haxe; } if (Config.SdkDir) { - Sdk.dir = Config.SdkDir; + Sdk.dir = Config.SdkDir; } if (Config.BuildDir) { - Haxe.buildDir = Config.BuildDir; + Haxe.buildDir = Config.BuildDir; } exports.clean = function clean() { - return gulp.src('target/*', {read: false}).pipe(gulpClean()); + return gulp.src("target/*", { read: false }).pipe(gulpClean()); }; -exports.generate = function generate() { - return new Haxe().haxelib(['run', 'protohx', 'generate', 'protohx.json']).then(({stdout}) => { - if (stdout.indexOf('FAIL') > -1) { - throw stdout; +exports.setup = function setup() { + const builder = Project.Builder.new( + app.config, + Project.Platform.ANDROID, + app.buildSystem, + ); + return builder.prepare(); +}; + +exports.generate = function generate() { + return exports.setup().then(() => + new Haxe() + .haxelib(["run", "protohx", "generate", "protohx.json"]) + .then(({ stdout }) => { + if (stdout.indexOf("FAIL") > -1) { + throw stdout; } - }); + }), + ); }; const config = new Project.Config({ - meta: { - title: 'Puzzle\'z', - filename: 'puzzlez', - icon: 'src/app/resources/icon.png', - pack: 'ru.m.puzzlez', - author: 'shmyga ', - company: 'MegaLoMania', - version: packageInfo.version + (Config.Develop ? '-SNAPSHOT' : ''), - }, - key: Config.Key, - libs: packageInfo.haxeDependencies, - macros: [ - `CompilationOption.set('build','${dateformat(new Date(), 'yyyy-mm-dd HH:MM:ss')}')`, - `CompilationOption.set('UNSPLASH_KEY','${Config.UnsplashKey}')`, - `CompilationOption.set('PIXABAY_KEY','${Config.PixabayKey}')`, - ], - flags: [ - 'proto_debug', - ] + meta: { + title: "Puzzle'z", + filename: "puzzlez", + icon: "src/app/resources/icon.png", + pack: "ru.m.puzzlez", + author: "shmyga ", + company: "MegaLoMania", + version: packageInfo.version + (Config.Develop ? "-SNAPSHOT" : ""), + }, + key: Config.Key, + libs: packageInfo.haxeDependencies, + macros: [ + `CompilationOption.set('build','${dateformat(new Date(), "yyyy-mm-dd HH:MM:ss")}')`, + `CompilationOption.set('UNSPLASH_KEY','${Config.UnsplashKey}')`, + `CompilationOption.set('PIXABAY_KEY','${Config.PixabayKey}')`, + ], + flags: ["proto_debug"], }); const app = new Project( - Project.BuildSystem.OPENFL, - [ - Project.Platform.FLASH, - Project.Platform.HTML5, - Project.Platform.LINUX, - Project.Platform.WINDOWS, - Project.Platform.ANDROID, + Project.BuildSystem.OPENFL, + [ + Project.Platform.FLASH, + Project.Platform.HTML5, + Project.Platform.LINUX, + Project.Platform.WINDOWS, + Project.Platform.ANDROID, + ], + config.branch({ + name: "app", + sources: ["src-gen/haxe", "src/common/haxe", "src/app/haxe"], + android: [ + { + path: "dependencies/android", + extensions: ["ru.m.android.FileUtil"], + }, ], - config.branch({ - name: 'app', - sources: [ - 'src-gen/haxe', - 'src/common/haxe', - 'src/app/haxe', - ], - android: [{ - path: 'dependencies/android', - extensions: ['ru.m.android.FileUtil'], - }], - assets: [ - 'src/app/resources', - ], - main: 'ru.m.puzzlez.PuzzlezApp', - meta: { - width: 1280, - height: 768, - }, - flags: [ - 'app', - ] - }), + assets: ["src/app/resources"], + main: "ru.m.puzzlez.PuzzlezApp", + meta: { + width: 1280, + height: 768, + }, + flags: ["app"], + }), ).bind(module, gulp); const server = new Project( - Project.BuildSystem.HAXE, - [ - Project.Platform.NEKO, - Project.Platform.CPP, - ], - config.branch({ - name: 'server', - sources: [ - 'src-gen/haxe', - 'src/common/haxe', - 'src/server/haxe', - ], - main: 'ru.m.puzzlez.PuzzlezServer', - }) + Project.BuildSystem.HAXE, + [Project.Platform.NEKO, Project.Platform.CPP], + config.branch({ + name: "server", + sources: ["src-gen/haxe", "src/common/haxe", "src/server/haxe"], + main: "ru.m.puzzlez.PuzzlezServer", + }), ).bind(module, gulp); -module.exports.publish = publish(packageInfo.name, packageInfo.version, Config.PublishDir, Config.PublishUrl); +module.exports.publish = publish( + packageInfo.name, + packageInfo.version, + Config.PublishDir, + Config.PublishUrl, +); const defaultSeries = [ - exports.clean, - exports.generate, - module.exports['app:flash:build'], - module.exports['app:flash:html'], - module.exports['app:html5:build'], + exports.clean, + exports.generate, + module.exports["app:flash:build"], + module.exports["app:flash:html"], + module.exports["app:html5:build"], ]; if (System.isLinux) { - defaultSeries.push( - module.exports['app:linux:build'], - module.exports['app:linux:archive'], - module.exports['app:linux:deb'], + defaultSeries.push( + module.exports["app:linux:build"], + module.exports["app:linux:archive"], + module.exports["app:linux:deb"], - module.exports['app:android:build'], - ); + module.exports["app:android:build"], + ); } if (System.isWindows) { - defaultSeries.push( - module.exports['app:windows:build'], - module.exports['app:windows:archive'], - module.exports['app:windows:installer'], - ); + defaultSeries.push( + module.exports["app:windows:build"], + module.exports["app:windows:archive"], + module.exports["app:windows:installer"], + ); } -defaultSeries.push( - exports.publish, -); +defaultSeries.push(exports.publish); module.exports.default = gulp.series(defaultSeries); diff --git a/scripts/build b/scripts/build new file mode 100755 index 0000000..bb4faf4 --- /dev/null +++ b/scripts/build @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +set -e +cd "$(dirname $(dirname "$0"))" || exit + +source .env +mkdir -p "$SDK_PATH" "$PUBLISH_PATH" "$BUILD_PATH" "$TARGET_PATH" "src-gen" +docker compose run --rm --user $(id -u):$(id -g) --build --remove-orphans builder \ No newline at end of file