From 8459b46cd09cc96e856308e54ee78a265bb2c00b Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Fri, 11 Jun 2021 18:24:59 +0200 Subject: [PATCH] Tools: Allow building Docker image from CI --- .eslintignore | 3 ++ .github/scripts/run_ci.sh | 6 ++++ .github/workflows/github-actions-main.yml | 22 +++++++++++++ .gitignore | 3 ++ package.json | 1 + packages/server/package-lock.json | 2 +- packages/server/package.json | 2 +- packages/tools/buildServerDocker.ts | 39 +++++++++++++++++++++++ packages/tools/release-server.ts | 14 ++------ readme/changelog_server.md | 7 ++++ 10 files changed, 85 insertions(+), 14 deletions(-) create mode 100644 packages/tools/buildServerDocker.ts diff --git a/.eslintignore b/.eslintignore index 708d9a9d6..2780b675c 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1604,6 +1604,9 @@ packages/renderer/pathUtils.js.map packages/renderer/utils.d.ts packages/renderer/utils.js packages/renderer/utils.js.map +packages/tools/buildServerDocker.d.ts +packages/tools/buildServerDocker.js +packages/tools/buildServerDocker.js.map packages/tools/generate-database-types.d.ts packages/tools/generate-database-types.js packages/tools/generate-database-types.js.map diff --git a/.github/scripts/run_ci.sh b/.github/scripts/run_ci.sh index 45bb09dc3..da01b6320 100755 --- a/.github/scripts/run_ci.sh +++ b/.github/scripts/run_ci.sh @@ -122,7 +122,13 @@ fi cd "$ROOT_DIR/packages/app-desktop" if [[ $GIT_TAG_NAME = v* ]]; then + echo "Building and publishing desktop application..." USE_HARD_LINKS=false npm run dist +elif [[ $GIT_TAG_NAME = server-v* ]] && [[ $IS_LINUX = 1 ]]; then + echo "Building Docker Image..." + cd "$ROOT_DIR" + npm run buildServerDocker -- --tag-name $GIT_TAG_NAME else + echo "Building but *not* publishing desktop application..." USE_HARD_LINKS=false npm run dist -- --publish=never fi diff --git a/.github/workflows/github-actions-main.yml b/.github/workflows/github-actions-main.yml index acbd03f6d..7f1190be5 100644 --- a/.github/workflows/github-actions-main.yml +++ b/.github/workflows/github-actions-main.yml @@ -12,6 +12,7 @@ jobs: # exist) since otherwise it will make the whole build fails, even though # it might work without update. libsecret-1-dev is required for keytar - # https://github.com/atom/node-keytar + - name: Install Linux dependencies if: runner.os == 'Linux' run: | @@ -19,11 +20,32 @@ jobs: sudo apt-get install -y gettext sudo apt-get install -y libsecret-1-dev + - name: Install Docker Engine + if: runner.os == 'Linux' + run: | + sudo apt-get install -y apt-transport-https + sudo apt-get install -y ca-certificates + sudo apt-get install -y curl + sudo apt-get install -y gnupg + sudo apt-get install -y lsb-release + curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg + echo \ + "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \ + $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null + sudo apt-get update || true + sudo apt-get install -y docker-ce docker-ce-cli containerd.io + - uses: actions/checkout@v2 - uses: olegtarasov/get-tag@v2.1 - uses: actions/setup-node@v2 with: node-version: '12' + + - uses: docker/login-action@v1 + if: runner.os == 'Linux' + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Run script... env: diff --git a/.gitignore b/.gitignore index c53761af9..296939af1 100644 --- a/.gitignore +++ b/.gitignore @@ -1590,6 +1590,9 @@ packages/renderer/pathUtils.js.map packages/renderer/utils.d.ts packages/renderer/utils.js packages/renderer/utils.js.map +packages/tools/buildServerDocker.d.ts +packages/tools/buildServerDocker.js +packages/tools/buildServerDocker.js.map packages/tools/generate-database-types.d.ts packages/tools/generate-database-types.js packages/tools/generate-database-types.js.map diff --git a/package.json b/package.json index e91141016..bb2683a77 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "releaseIOS": "node packages/tools/release-ios.js", "releasePluginGenerator": "node packages/tools/release-plugin-generator.js", "releaseServer": "node packages/tools/release-server.js", + "buildServerDocker": "node packages/tools/buildServerDocker.js", "setupNewRelease": "node ./packages/tools/setupNewRelease", "test-ci": "lerna run test-ci --stream", "test": "lerna run test --stream", diff --git a/packages/server/package-lock.json b/packages/server/package-lock.json index adf33dcf5..4604f09a9 100644 --- a/packages/server/package-lock.json +++ b/packages/server/package-lock.json @@ -1,6 +1,6 @@ { "name": "@joplin/server", - "version": "2.0.6", + "version": "2.0.7", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/packages/server/package.json b/packages/server/package.json index 1024cbf8a..17b9b6b96 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -1,6 +1,6 @@ { "name": "@joplin/server", - "version": "2.0.6", + "version": "2.0.7", "private": true, "scripts": { "start-dev": "nodemon --config nodemon.json --ext ts,js,mustache,css,tsx dist/app.js --env dev", diff --git a/packages/tools/buildServerDocker.ts b/packages/tools/buildServerDocker.ts new file mode 100644 index 000000000..4813a8eee --- /dev/null +++ b/packages/tools/buildServerDocker.ts @@ -0,0 +1,39 @@ +import { execCommand2, rootDir } from './tool-utils'; + +function getVersionFromTag(tagName: string): string { + if (tagName.indexOf('server-') !== 0) throw new Error(`Invalid tag: ${tagName}`); + const s = tagName.split('-'); + return s[1]; +} + +function getIsPreRelease(tagName: string): boolean { + return tagName.indexOf('-beta') > 0; +} + +async function main() { + const argv = require('yargs').argv; + if (!argv.tagName) throw new Error('--tag-name not provided'); + + const tagName = argv.tagName; + const imageVersion = getVersionFromTag(tagName); + const isPreRelease = getIsPreRelease(tagName); + + process.chdir(rootDir); + console.info(`Running from: ${process.cwd()}`); + + console.info('tagName:', tagName); + console.info('imageVersion:', imageVersion); + console.info('isPreRelease:', isPreRelease); + + await execCommand2(`docker build -t "joplin/server:${imageVersion}" -f Dockerfile.server .`); + await execCommand2(`docker tag "joplin/server:${imageVersion}" "joplin/server:latest"`); + await execCommand2(`docker push joplin/server:${imageVersion}`); + + if (!isPreRelease) await execCommand2('docker push joplin/server:latest'); +} + +main().catch((error) => { + console.error('Fatal error'); + console.error(error); + process.exit(1); +}); diff --git a/packages/tools/release-server.ts b/packages/tools/release-server.ts index c9da192d4..5b1aed315 100644 --- a/packages/tools/release-server.ts +++ b/packages/tools/release-server.ts @@ -11,18 +11,8 @@ async function main() { process.chdir(serverDir); const version = (await execCommand2('npm version patch')).trim(); - const versionShort = version.substr(1); - const imageVersion = versionShort + (isPreRelease ? '-beta' : ''); - const tagName = `server-${version}`; - - process.chdir(rootDir); - console.info(`Running from: ${process.cwd()}`); - - await execCommand2(`docker build -t "joplin/server:${imageVersion}" -f Dockerfile.server .`); - await execCommand2(`docker tag "joplin/server:${imageVersion}" "joplin/server:latest"`); - await execCommand2(`docker push joplin/server:${imageVersion}`); - - if (!isPreRelease) await execCommand2('docker push joplin/server:latest'); + const versionSuffix = isPreRelease ? '-beta' : ''; + const tagName = `server-${version}${versionSuffix}`; const changelogPath = `${rootDir}/readme/changelog_server.md`; await completeReleaseWithChangelog(changelogPath, version, tagName, 'Server', isPreRelease); diff --git a/readme/changelog_server.md b/readme/changelog_server.md index 81cdbc5ff..4dd808a86 100644 --- a/readme/changelog_server.md +++ b/readme/changelog_server.md @@ -1,5 +1,12 @@ # Joplin Server Changelog +## [server-v2.0.7](https://github.com/laurent22/joplin/releases/tag/server-v2.0.7) (Pre-release) - 2021-06-11T15:34:30Z + +- New: Add navbar on login and sign up page (7a3a208) +- New: Added option to enable or disable stack traces (5614eb9) +- Improved: Handle custom user content URLs (a36b13d) +- Fixed: Fixed error when creating user (594084e) + ## [server-v2.0.6](https://github.com/laurent22/joplin/releases/tag/server-v2.0.6) (Pre-release) - 2021-06-07T17:27:27Z - New: Add Stripe integration (770af6a)