From 3a8c9619205f8e00900065a4f2541e59db973060 Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Sun, 15 Mar 2020 09:35:34 +0100 Subject: [PATCH] docker build --- .github/workflows/build-app.yaml | 27 +++++------- .github/workflows/build-docker.yaml | 50 ++++++++++++++++++++++ app/src/electron.js | 1 - docker/Dockerfile | 17 ++++++++ package.json | 9 ++++ packages/api/src/main.js | 13 ++++-- yarn.lock | 64 +++++++++++++++++++++++++++-- 7 files changed, 155 insertions(+), 26 deletions(-) create mode 100644 .github/workflows/build-docker.yaml create mode 100644 docker/Dockerfile diff --git a/.github/workflows/build-app.yaml b/.github/workflows/build-app.yaml index 7fe83f00e..01c00d845 100644 --- a/.github/workflows/build-app.yaml +++ b/.github/workflows/build-app.yaml @@ -1,7 +1,12 @@ -name: Electron app +name: Docker image on: [push] +# on: +# push: +# branches: +# - production + jobs: build: @@ -27,21 +32,9 @@ jobs: - name: yarn install run: | yarn install - - name: Publish + - name: Prepare docker image run: | - yarn run build:app - - name: Cleanup artifacts + yarn run prepare:docker + - name: Build docker image run: | - npx rimraf "app/dist/!(*.exe|*.deb|*.AppImage|*.dmg)" - - name: Upload artifacts - uses: actions/upload-artifact@v1 - with: - name: ${{ matrix.os }} - path: app/dist - - name: Release - uses: softprops/action-gh-release@v1 - if: startsWith(github.ref, 'refs/tags/') - with: - files: "app/dist/**" - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + docker build ./docker diff --git a/.github/workflows/build-docker.yaml b/.github/workflows/build-docker.yaml new file mode 100644 index 000000000..fbe2f1cc1 --- /dev/null +++ b/.github/workflows/build-docker.yaml @@ -0,0 +1,50 @@ +name: Electron app + +on: + push: + branches: + - production + +jobs: + build: + + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: [ubuntu-18.04] + # os: [macOS-10.14, windows-2016, ubuntu-18.04] + + steps: + - name: Context + env: + GITHUB_CONTEXT: ${{ toJson(github) }} + run: echo "$GITHUB_CONTEXT" + - uses: actions/checkout@v1 + with: + fetch-depth: 1 + - name: Use Node.js 10.x + uses: actions/setup-node@v1 + with: + node-version: 10.x + - name: yarn install + run: | + yarn install + - name: Publish + run: | + yarn run build:app + - name: Cleanup artifacts + run: | + npx rimraf "app/dist/!(*.exe|*.deb|*.AppImage|*.dmg)" + - name: Upload artifacts + uses: actions/upload-artifact@v1 + with: + name: ${{ matrix.os }} + path: app/dist + - name: Release + uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/') + with: + files: "app/dist/**" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/app/src/electron.js b/app/src/electron.js index d27fb04ba..3818e15e2 100644 --- a/app/src/electron.js +++ b/app/src/electron.js @@ -17,7 +17,6 @@ function createWindow() { mainWindow = new BrowserWindow({ width: 800, height: 600 }); const apiProcess = fork(path.join(__dirname, '../packages/api/dist/bundle.js')); - console.log('API PROCESS', apiProcess); const startUrl = process.env.ELECTRON_START_URL || diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 000000000..66c4b7151 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,17 @@ +# base image +FROM node:10 + +# set working directory +WORKDIR /home/jenasoft/dbgate + +COPY . . + +RUN yarn +RUN yarn build:api +RUN yarn build:web + +# start app +WORKDIR /home/jenasoft/raftcz-frontend/build +EXPOSE 5000 +# CMD yarn start +CMD serve -s diff --git a/package.json b/package.json index e526e05be..2c54437c9 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,12 @@ "build:filterparser": "yarn workspace @dbgate/filterparser build", "build:lib": "yarn build:sqltree && yarn build:filterparser && yarn build:datalib", "build:app": "cd app && yarn install && yarn build", + "build:api": "yarn workspace @dbgate/api build", + "build:web": "yarn workspace @dbgate/web build", + + "copy:docker:build": "copyfiles packages/api/dist/* docker -f && copyfiles packages/web/build/* docker -u 2 && copyfiles \"packages/web/build/**/*\" docker -u 2", + "prepare:docker": "yarn build:web && yarn build:api && yarn copy:docker:build", + "prepare": "yarn build:lib", "start": "concurrently --kill-others-on-fail \"yarn start:api\" \"yarn start:web\"", "lib": "concurrently --kill-others-on-fail \"yarn start:sqltree\" \"yarn start:filterparser\" \"yarn start:datalib\"", @@ -27,5 +33,8 @@ "concurrently": "^5.1.0", "patch-package": "^6.2.1", "socket.io": "^2.3.0" + }, + "devDependencies": { + "copyfiles": "^2.2.0" } } diff --git a/packages/api/src/main.js b/packages/api/src/main.js index 62c78be98..68859603b 100644 --- a/packages/api/src/main.js +++ b/packages/api/src/main.js @@ -3,6 +3,7 @@ const bodyParser = require('body-parser'); const http = require('http'); const cors = require('cors'); const io = require('socket.io'); +const fs = require('fs'); const useController = require('./utility/useController'); const connections = require('./controllers/connections'); @@ -22,15 +23,19 @@ function start() { app.use(cors()); app.use(bodyParser.json()); - app.get('/', (req, res) => { - res.send('DbGate API'); - }); - useController(app, '/connections', connections); useController(app, '/server-connections', serverConnections); useController(app, '/database-connections', databaseConnections); useController(app, '/tables', tables); + if (fs.existsSync(`${__dirname}/build`)) { + app.use(express.static(`${__dirname}/build`)); + } else { + app.get('/', (req, res) => { + res.send('DbGate API'); + }); + } + server.listen(3000); } diff --git a/yarn.lock b/yarn.lock index eaba924b4..4d7b4d293 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3308,6 +3308,18 @@ copy-descriptor@^0.1.0: resolved "https://registry.yarnpkg.com/copy-descriptor/-/copy-descriptor-0.1.1.tgz#676f6eb3c39997c2ee1ac3a924fd6124748f578d" integrity sha1-Z29us8OZl8LuGsOpJP1hJHSPV40= +copyfiles@^2.2.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/copyfiles/-/copyfiles-2.2.0.tgz#d9fc6c06f299337fb7eeb7ea5887e9d7188d9d47" + integrity sha512-iJbHJI+8OKqsq+4JF0rqgRkZzo++jqO6Wf4FUU1JM41cJF6JcY5968XyF4tm3Kkm7ZOMrqlljdm8N9oyY5raGw== + dependencies: + glob "^7.0.5" + minimatch "^3.0.3" + mkdirp "^0.5.1" + noms "0.0.0" + through2 "^2.0.1" + yargs "^13.2.4" + core-js-compat@^3.6.2: version "3.6.4" resolved "https://registry.yarnpkg.com/core-js-compat/-/core-js-compat-3.6.4.tgz#938476569ebb6cda80d339bcf199fae4f16fff17" @@ -5182,7 +5194,7 @@ glob-to-regexp@^0.3.0: resolved "https://registry.yarnpkg.com/glob-to-regexp/-/glob-to-regexp-0.3.0.tgz#8c5a1494d2066c570cc3bfe4496175acc4d502ab" integrity sha1-jFoUlNIGbFcMw7/kSWF1rMTVAqs= -glob@^7.0.3, glob@^7.1.1, glob@^7.1.2, glob@^7.1.3, glob@^7.1.4, glob@^7.1.6: +glob@^7.0.3, glob@^7.0.5, glob@^7.1.1, glob@^7.1.2, glob@^7.1.3, glob@^7.1.4, glob@^7.1.6: version "7.1.6" resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.6.tgz#141f33b81a7c2492e125594307480c46679278a6" integrity sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA== @@ -6181,6 +6193,11 @@ is-wsl@^1.1.0: resolved "https://registry.yarnpkg.com/is-wsl/-/is-wsl-1.1.0.tgz#1f16e4aa22b04d1336b66188a66af3c600c3a66d" integrity sha1-HxbkqiKwTRM2tmGIpmrzxgDDpm0= +isarray@0.0.1: + version "0.0.1" + resolved "https://registry.yarnpkg.com/isarray/-/isarray-0.0.1.tgz#8a18acfca9a8f4177e09abfc6038939b05d1eedf" + integrity sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8= + isarray@1.0.0, isarray@^1.0.0, isarray@~1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11" @@ -7357,7 +7374,7 @@ minimalistic-crypto-utils@^1.0.0, minimalistic-crypto-utils@^1.0.1: resolved "https://registry.yarnpkg.com/minimalistic-crypto-utils/-/minimalistic-crypto-utils-1.0.1.tgz#f6c00c1c0b082246e5c4d99dfb8c7c083b2b582a" integrity sha1-9sAMHAsIIkblxNmd+4x8CDsrWCo= -minimatch@3.0.4, minimatch@^3.0.4: +minimatch@3.0.4, minimatch@^3.0.3, minimatch@^3.0.4: version "3.0.4" resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" integrity sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA== @@ -7670,6 +7687,14 @@ nodemon@^2.0.2: undefsafe "^2.0.2" update-notifier "^2.5.0" +noms@0.0.0: + version "0.0.0" + resolved "https://registry.yarnpkg.com/noms/-/noms-0.0.0.tgz#da8ebd9f3af9d6760919b27d9cdc8092a7332859" + integrity sha1-2o69nzr51nYJGbJ9nNyAkqczKFk= + dependencies: + inherits "^2.0.1" + readable-stream "~1.0.31" + nopt@~1.0.10: version "1.0.10" resolved "https://registry.yarnpkg.com/nopt/-/nopt-1.0.10.tgz#6ddd21bd2a31417b92727dd585f8a6f37608ebee" @@ -9600,6 +9625,16 @@ readable-stream@^3.0.1, readable-stream@^3.0.6, readable-stream@^3.1.1, readable string_decoder "^1.1.1" util-deprecate "^1.0.1" +readable-stream@~1.0.31: + version "1.0.34" + resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-1.0.34.tgz#125820e34bc842d2f2aaafafe4c2916ee32c157c" + integrity sha1-Elgg40vIQtLyqq+v5MKRbuMsFXw= + dependencies: + core-util-is "~1.0.0" + inherits "~2.0.1" + isarray "0.0.1" + string_decoder "~0.10.x" + readdirp@^2.2.1: version "2.2.1" resolved "https://registry.yarnpkg.com/readdirp/-/readdirp-2.2.1.tgz#0e87622a3325aa33e892285caf8b4e846529a525" @@ -10725,6 +10760,11 @@ string_decoder@^1.0.0, string_decoder@^1.1.1: dependencies: safe-buffer "~5.2.0" +string_decoder@~0.10.x: + version "0.10.31" + resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-0.10.31.tgz#62e203bc41766c6c28c9fc84301dab1c5310fa94" + integrity sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ= + string_decoder@~1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.1.1.tgz#9cf1611ba62685d7030ae9e4ba34149c3af03fc8" @@ -11007,7 +11047,7 @@ throat@^4.0.0: resolved "https://registry.yarnpkg.com/throat/-/throat-4.1.0.tgz#89037cbc92c56ab18926e6ba4cbb200e15672a6a" integrity sha1-iQN8vJLFarGJJua6TLsgDhVnKmo= -through2@^2.0.0: +through2@^2.0.0, through2@^2.0.1: version "2.0.5" resolved "https://registry.yarnpkg.com/through2/-/through2-2.0.5.tgz#01c1e39eb31d07cb7d03a96a70823260b23132cd" integrity sha512-/mrRod8xqpA+IHSLyGCQ2s8SPHiCDEeQJSep1jqLYeEUClOFG2Qsh+4FU6G9VeqpZnGW/Su8LQGc4YKni5rYSQ== @@ -12119,7 +12159,7 @@ yargs-parser@^11.1.1: camelcase "^5.0.0" decamelize "^1.2.0" -yargs-parser@^13.1.0: +yargs-parser@^13.1.0, yargs-parser@^13.1.2: version "13.1.2" resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-13.1.2.tgz#130f09702ebaeef2650d54ce6e3e5706f7a4fb38" integrity sha512-3lbsNRf/j+A4QuSZfDRA7HRSfWrzO0YjqTJd5kjAq37Zep1CEgaYmrH9Q3GwPiB9cHyd1Y1UwggGhJGoxipbzg== @@ -12178,6 +12218,22 @@ yargs@13.2.4: y18n "^4.0.0" yargs-parser "^13.1.0" +yargs@^13.2.4: + version "13.3.2" + resolved "https://registry.yarnpkg.com/yargs/-/yargs-13.3.2.tgz#ad7ffefec1aa59565ac915f82dccb38a9c31a2dd" + integrity sha512-AX3Zw5iPruN5ie6xGRIDgqkT+ZhnRlZMLMHAs8tg7nRruy2Nb+i5o9bwghAogtM08q1dpr2LVoS8KSTMYpWXUw== + dependencies: + cliui "^5.0.0" + find-up "^3.0.0" + get-caller-file "^2.0.1" + require-directory "^2.1.1" + require-main-filename "^2.0.0" + set-blocking "^2.0.0" + string-width "^3.0.0" + which-module "^2.0.0" + y18n "^4.0.0" + yargs-parser "^13.1.2" + yargs@^13.3.0: version "13.3.0" resolved "https://registry.yarnpkg.com/yargs/-/yargs-13.3.0.tgz#4c657a55e07e5f2cf947f8a366567c04a0dedc83"