diff --git a/.drone.yml b/.drone.yml index 7d5d1de..2481cd9 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,7 +1,5 @@ kind: pipeline name: ssh-test -clone: - depth: 1 steps: - name: ssh image: appleboy/drone-ssh @@ -12,434 +10,56 @@ steps: from_secret: ssh_key script: - cd /home/core/staging && ls - when: - branch: - - master +trigger: + branch: + - master + event: + - push + - tag + - promote + - rollback --- kind: pipeline -name: backend-auth -clone: - depth: 1 +name: call-self steps: - - name: submodule - image: plugins/git + - name: regenrate + image: 'node:12-alpine' + commands: + - yarn install + - yarn generate + - name: push-or-fail + image: appleboy/drone-git-push settings: - recursive: true - submodule_override: - backend-auth: 'https://git.makerforce.io/beep/backend-auth.git' - backend-bite: 'https://git.makerforce.io/beep/backend-bite.git' - backend-core: 'https://git.makerforce.io/beep/backend-core.git' - backend-heartbeat: 'https://git.makerforce.io/beep/backend-heartbeat.git' - backend-login: 'https://git.makerforce.io/beep/backend-login.git' - backend-protobuf: 'https://git.makerforce.io/beep/backend-protobuf.git' - backend-publish: 'https://git.makerforce.io/beep/backend-publish.git' - backend-signal: 'https://git.makerforce.io/beep/backend-signal.git' - backend-store: 'https://git.makerforce.io/beep/backend-store.git' - backend-subscribe: 'https://git.makerforce.io/beep/backend-subscribe.git' - backend-transcription: 'https://git.makerforce.io/beep/backend-transcription.git' - when: - branch: - - master - - name: docker - image: plugins/docker - settings: - registry: registry.makerforce.io - repo: registry.makerforce.io/beep/backend-auth - context: backend-auth - dockerfile: backend-auth/Dockerfile - auto_tag: true - username: - from_secret: docker_username - password: - from_secret: docker_password - when: - branch: - - master ---- -kind: pipeline -name: backend-bite -clone: - depth: 1 -steps: - - name: submodule - image: plugins/git - settings: - recursive: true - submodule_override: - backend-auth: 'https://git.makerforce.io/beep/backend-auth.git' - backend-bite: 'https://git.makerforce.io/beep/backend-bite.git' - backend-core: 'https://git.makerforce.io/beep/backend-core.git' - backend-heartbeat: 'https://git.makerforce.io/beep/backend-heartbeat.git' - backend-login: 'https://git.makerforce.io/beep/backend-login.git' - backend-protobuf: 'https://git.makerforce.io/beep/backend-protobuf.git' - backend-publish: 'https://git.makerforce.io/beep/backend-publish.git' - backend-signal: 'https://git.makerforce.io/beep/backend-signal.git' - backend-store: 'https://git.makerforce.io/beep/backend-store.git' - backend-subscribe: 'https://git.makerforce.io/beep/backend-subscribe.git' - backend-transcription: 'https://git.makerforce.io/beep/backend-transcription.git' - when: - branch: - - master - - name: docker - image: plugins/docker - settings: - registry: registry.makerforce.io - repo: registry.makerforce.io/beep/backend-bite - context: backend-bite - dockerfile: backend-bite/Dockerfile - auto_tag: true - username: - from_secret: docker_username - password: - from_secret: docker_password - when: - branch: - - master ---- -kind: pipeline -name: backend-core -clone: - depth: 1 -steps: - - name: submodule - image: plugins/git - settings: - recursive: true - submodule_override: - backend-auth: 'https://git.makerforce.io/beep/backend-auth.git' - backend-bite: 'https://git.makerforce.io/beep/backend-bite.git' - backend-core: 'https://git.makerforce.io/beep/backend-core.git' - backend-heartbeat: 'https://git.makerforce.io/beep/backend-heartbeat.git' - backend-login: 'https://git.makerforce.io/beep/backend-login.git' - backend-protobuf: 'https://git.makerforce.io/beep/backend-protobuf.git' - backend-publish: 'https://git.makerforce.io/beep/backend-publish.git' - backend-signal: 'https://git.makerforce.io/beep/backend-signal.git' - backend-store: 'https://git.makerforce.io/beep/backend-store.git' - backend-subscribe: 'https://git.makerforce.io/beep/backend-subscribe.git' - backend-transcription: 'https://git.makerforce.io/beep/backend-transcription.git' - when: - branch: - - master - - name: docker - image: plugins/docker - settings: - registry: registry.makerforce.io - repo: registry.makerforce.io/beep/backend-core - context: backend-core - dockerfile: backend-core/Dockerfile - auto_tag: true - username: - from_secret: docker_username - password: - from_secret: docker_password - when: - branch: - - master ---- -kind: pipeline -name: backend-heartbeat -clone: - depth: 1 -steps: - - name: submodule - image: plugins/git - settings: - recursive: true - submodule_override: - backend-auth: 'https://git.makerforce.io/beep/backend-auth.git' - backend-bite: 'https://git.makerforce.io/beep/backend-bite.git' - backend-core: 'https://git.makerforce.io/beep/backend-core.git' - backend-heartbeat: 'https://git.makerforce.io/beep/backend-heartbeat.git' - backend-login: 'https://git.makerforce.io/beep/backend-login.git' - backend-protobuf: 'https://git.makerforce.io/beep/backend-protobuf.git' - backend-publish: 'https://git.makerforce.io/beep/backend-publish.git' - backend-signal: 'https://git.makerforce.io/beep/backend-signal.git' - backend-store: 'https://git.makerforce.io/beep/backend-store.git' - backend-subscribe: 'https://git.makerforce.io/beep/backend-subscribe.git' - backend-transcription: 'https://git.makerforce.io/beep/backend-transcription.git' - when: - branch: - - master - - name: docker - image: plugins/docker - settings: - registry: registry.makerforce.io - repo: registry.makerforce.io/beep/backend-heartbeat - context: backend-heartbeat - dockerfile: backend-heartbeat/Dockerfile - auto_tag: true - username: - from_secret: docker_username - password: - from_secret: docker_password - when: - branch: - - master ---- -kind: pipeline -name: backend-login -clone: - depth: 1 -steps: - - name: submodule - image: plugins/git - settings: - recursive: true - submodule_override: - backend-auth: 'https://git.makerforce.io/beep/backend-auth.git' - backend-bite: 'https://git.makerforce.io/beep/backend-bite.git' - backend-core: 'https://git.makerforce.io/beep/backend-core.git' - backend-heartbeat: 'https://git.makerforce.io/beep/backend-heartbeat.git' - backend-login: 'https://git.makerforce.io/beep/backend-login.git' - backend-protobuf: 'https://git.makerforce.io/beep/backend-protobuf.git' - backend-publish: 'https://git.makerforce.io/beep/backend-publish.git' - backend-signal: 'https://git.makerforce.io/beep/backend-signal.git' - backend-store: 'https://git.makerforce.io/beep/backend-store.git' - backend-subscribe: 'https://git.makerforce.io/beep/backend-subscribe.git' - backend-transcription: 'https://git.makerforce.io/beep/backend-transcription.git' - when: - branch: - - master - - name: docker - image: plugins/docker - settings: - registry: registry.makerforce.io - repo: registry.makerforce.io/beep/backend-login - context: backend-login - dockerfile: backend-login/Dockerfile - auto_tag: true - username: - from_secret: docker_username - password: - from_secret: docker_password - when: - branch: - - master ---- -kind: pipeline -name: backend-publish -clone: - depth: 1 -steps: - - name: submodule - image: plugins/git - settings: - recursive: true - submodule_override: - backend-auth: 'https://git.makerforce.io/beep/backend-auth.git' - backend-bite: 'https://git.makerforce.io/beep/backend-bite.git' - backend-core: 'https://git.makerforce.io/beep/backend-core.git' - backend-heartbeat: 'https://git.makerforce.io/beep/backend-heartbeat.git' - backend-login: 'https://git.makerforce.io/beep/backend-login.git' - backend-protobuf: 'https://git.makerforce.io/beep/backend-protobuf.git' - backend-publish: 'https://git.makerforce.io/beep/backend-publish.git' - backend-signal: 'https://git.makerforce.io/beep/backend-signal.git' - backend-store: 'https://git.makerforce.io/beep/backend-store.git' - backend-subscribe: 'https://git.makerforce.io/beep/backend-subscribe.git' - backend-transcription: 'https://git.makerforce.io/beep/backend-transcription.git' - when: - branch: - - master - - name: docker - image: plugins/docker - settings: - registry: registry.makerforce.io - repo: registry.makerforce.io/beep/backend-publish - context: backend-publish - dockerfile: backend-publish/Dockerfile - auto_tag: true - username: - from_secret: docker_username - password: - from_secret: docker_password - when: - branch: - - master ---- -kind: pipeline -name: backend-signal -clone: - depth: 1 -steps: - - name: submodule - image: plugins/git - settings: - recursive: true - submodule_override: - backend-auth: 'https://git.makerforce.io/beep/backend-auth.git' - backend-bite: 'https://git.makerforce.io/beep/backend-bite.git' - backend-core: 'https://git.makerforce.io/beep/backend-core.git' - backend-heartbeat: 'https://git.makerforce.io/beep/backend-heartbeat.git' - backend-login: 'https://git.makerforce.io/beep/backend-login.git' - backend-protobuf: 'https://git.makerforce.io/beep/backend-protobuf.git' - backend-publish: 'https://git.makerforce.io/beep/backend-publish.git' - backend-signal: 'https://git.makerforce.io/beep/backend-signal.git' - backend-store: 'https://git.makerforce.io/beep/backend-store.git' - backend-subscribe: 'https://git.makerforce.io/beep/backend-subscribe.git' - backend-transcription: 'https://git.makerforce.io/beep/backend-transcription.git' - when: - branch: - - master - - name: docker - image: plugins/docker - settings: - registry: registry.makerforce.io - repo: registry.makerforce.io/beep/backend-signal - context: backend-signal - dockerfile: backend-signal/Dockerfile - auto_tag: true - username: - from_secret: docker_username - password: - from_secret: docker_password - when: - branch: - - master ---- -kind: pipeline -name: backend-store -clone: - depth: 1 -steps: - - name: submodule - image: plugins/git - settings: - recursive: true - submodule_override: - backend-auth: 'https://git.makerforce.io/beep/backend-auth.git' - backend-bite: 'https://git.makerforce.io/beep/backend-bite.git' - backend-core: 'https://git.makerforce.io/beep/backend-core.git' - backend-heartbeat: 'https://git.makerforce.io/beep/backend-heartbeat.git' - backend-login: 'https://git.makerforce.io/beep/backend-login.git' - backend-protobuf: 'https://git.makerforce.io/beep/backend-protobuf.git' - backend-publish: 'https://git.makerforce.io/beep/backend-publish.git' - backend-signal: 'https://git.makerforce.io/beep/backend-signal.git' - backend-store: 'https://git.makerforce.io/beep/backend-store.git' - backend-subscribe: 'https://git.makerforce.io/beep/backend-subscribe.git' - backend-transcription: 'https://git.makerforce.io/beep/backend-transcription.git' - when: - branch: - - master - - name: docker - image: plugins/docker - settings: - registry: registry.makerforce.io - repo: registry.makerforce.io/beep/backend-store - context: backend-store - dockerfile: backend-store/Dockerfile - auto_tag: true - username: - from_secret: docker_username - password: - from_secret: docker_password - when: - branch: - - master ---- -kind: pipeline -name: backend-subscribe -clone: - depth: 1 -steps: - - name: submodule - image: plugins/git - settings: - recursive: true - submodule_override: - backend-auth: 'https://git.makerforce.io/beep/backend-auth.git' - backend-bite: 'https://git.makerforce.io/beep/backend-bite.git' - backend-core: 'https://git.makerforce.io/beep/backend-core.git' - backend-heartbeat: 'https://git.makerforce.io/beep/backend-heartbeat.git' - backend-login: 'https://git.makerforce.io/beep/backend-login.git' - backend-protobuf: 'https://git.makerforce.io/beep/backend-protobuf.git' - backend-publish: 'https://git.makerforce.io/beep/backend-publish.git' - backend-signal: 'https://git.makerforce.io/beep/backend-signal.git' - backend-store: 'https://git.makerforce.io/beep/backend-store.git' - backend-subscribe: 'https://git.makerforce.io/beep/backend-subscribe.git' - backend-transcription: 'https://git.makerforce.io/beep/backend-transcription.git' - when: - branch: - - master - - name: docker - image: plugins/docker - settings: - registry: registry.makerforce.io - repo: registry.makerforce.io/beep/backend-subscribe - context: backend-subscribe - dockerfile: backend-subscribe/Dockerfile - auto_tag: true - username: - from_secret: docker_username - password: - from_secret: docker_password - when: - branch: - - master ---- -kind: pipeline -name: backend-transcription -clone: - depth: 1 -steps: - - name: submodule - image: plugins/git - settings: - recursive: true - submodule_override: - backend-auth: 'https://git.makerforce.io/beep/backend-auth.git' - backend-bite: 'https://git.makerforce.io/beep/backend-bite.git' - backend-core: 'https://git.makerforce.io/beep/backend-core.git' - backend-heartbeat: 'https://git.makerforce.io/beep/backend-heartbeat.git' - backend-login: 'https://git.makerforce.io/beep/backend-login.git' - backend-protobuf: 'https://git.makerforce.io/beep/backend-protobuf.git' - backend-publish: 'https://git.makerforce.io/beep/backend-publish.git' - backend-signal: 'https://git.makerforce.io/beep/backend-signal.git' - backend-store: 'https://git.makerforce.io/beep/backend-store.git' - backend-subscribe: 'https://git.makerforce.io/beep/backend-subscribe.git' - backend-transcription: 'https://git.makerforce.io/beep/backend-transcription.git' - when: - branch: - - master - - name: docker - image: plugins/docker - settings: - registry: registry.makerforce.io - repo: registry.makerforce.io/beep/backend-transcription - context: backend-transcription - dockerfile: backend-transcription/Dockerfile - auto_tag: true - username: - from_secret: docker_username - password: - from_secret: docker_password - when: - branch: - - master + remote_name: origin + branch: '${DRONE_SOURCE_BRANCH}' + key: + from_secret: push_ssh_key + commit: true + commit_message: '[SKIP CI] Automatically updating .drone.yml' + failure: ignore +trigger: + branch: + - master + event: + - pull_request --- kind: pipeline name: deploy -clone: - depth: 1 steps: - name: submodule image: plugins/git settings: recursive: true submodule_override: - backend-auth: 'https://git.makerforce.io/beep/backend-auth.git' - backend-bite: 'https://git.makerforce.io/beep/backend-bite.git' backend-core: 'https://git.makerforce.io/beep/backend-core.git' - backend-heartbeat: 'https://git.makerforce.io/beep/backend-heartbeat.git' - backend-login: 'https://git.makerforce.io/beep/backend-login.git' - backend-protobuf: 'https://git.makerforce.io/beep/backend-protobuf.git' - backend-publish: 'https://git.makerforce.io/beep/backend-publish.git' - backend-signal: 'https://git.makerforce.io/beep/backend-signal.git' backend-store: 'https://git.makerforce.io/beep/backend-store.git' - backend-subscribe: 'https://git.makerforce.io/beep/backend-subscribe.git' backend-transcription: 'https://git.makerforce.io/beep/backend-transcription.git' - when: - branch: - - master + backend-login: 'https://git.makerforce.io/beep/backend-login.git' + backend-heartbeat: 'https://git.makerforce.io/beep/backend-heartbeat.git' + backend-auth: 'https://git.makerforce.io/beep/backend-auth.git' + backend-pictures: 'https://git.makerforce.io/beep/backend-pictures.git' + backend-permissions: 'https://git.makerforce.io/beep/backend-permissions.git' + backend-webrtc: 'https://git.makerforce.io/beep/backend-webrtc.git' - name: copy-docker-compose image: appleboy/drone-scp settings: @@ -451,9 +71,6 @@ steps: - docker-compose.staging.yml - traefik.staging.toml target: /home/core/staging - when: - branch: - - master - name: copy-migrations image: appleboy/drone-scp settings: @@ -464,9 +81,6 @@ steps: source: - backend-core/postgres/* target: /home/core/staging - when: - branch: - - master - name: docker-compose-up image: appleboy/drone-ssh settings: @@ -481,25 +95,17 @@ steps: - >- cd /home/core/staging && /home/core/docker-compose -f docker-compose.staging.yml up -d - when: - branch: - - master - name: slack image: plugins/slack settings: webhook: from_secret: slack_webhook_beep - when: - branch: - - master -depends_on: - - backend-auth - - backend-bite - - backend-core - - backend-heartbeat - - backend-login - - backend-publish - - backend-signal - - backend-store - - backend-subscribe - - backend-transcription +trigger: + branch: + - master + event: + - push + - tag + - promote + - rollback +depends_on: [] diff --git a/backend-core b/backend-core index 59c8e4a..1064edc 160000 --- a/backend-core +++ b/backend-core @@ -1 +1 @@ -Subproject commit 59c8e4a907d6e09f89c4f3c7ba7bc71200bb7e5e +Subproject commit 1064edce60d2b78546035991455a289b79494896 diff --git a/backend-store b/backend-store index a79fb70..ec70263 160000 --- a/backend-store +++ b/backend-store @@ -1 +1 @@ -Subproject commit a79fb707d73d5dbf8b6993880baa6cd8528172d1 +Subproject commit ec7026385b65e7a9cd97fe8930a9252f9be21fb6 diff --git a/backend-webrtc b/backend-webrtc index 1c6137a..f7d9197 160000 --- a/backend-webrtc +++ b/backend-webrtc @@ -1 +1 @@ -Subproject commit 1c6137af6f7e32c8f6d8c947b514837dd76b25ca +Subproject commit f7d9197940119f964d21583d8077c6fec0e1a0d3 diff --git a/drone_gen.js b/drone_gen.js index 81e3529..1ffeffb 100644 --- a/drone_gen.js +++ b/drone_gen.js @@ -2,11 +2,11 @@ const fs = require('fs'); const path = require('path'); const cwd = process.cwd(); const yaml = require('js-yaml'); +const ini = require('ini'); +const gitmodules = ini.parse(fs.readFileSync('.gitmodules', 'utf-8')); +const submodules = Object.values(gitmodules).map(m => m.path); const folders = fs.readdirSync(cwd, { withFileTypes: true }); -const submodules = folders.filter(f => - f.isDirectory() && fs.readdirSync(path.join(cwd, f.name)).includes('.git') -).map(f => f.name); const dockers = folders.filter(f => f.isDirectory() && fs.readdirSync(path.join(cwd, f.name)).includes('Dockerfile') ).map(f => f.name); @@ -20,7 +20,7 @@ const yamls = dockers.map(f => ({ kind: 'pipeline', name: f, clone: { - depth: 1, + depth: 32, }, steps: [ { @@ -30,9 +30,6 @@ const yamls = dockers.map(f => ({ recursive: true, submodule_override, }, - when: { - branch: ['master'], - }, }, { name: 'docker', @@ -50,19 +47,17 @@ const yamls = dockers.map(f => ({ from_secret: 'docker_password', }, }, - when: { - branch: ['master'], - }, }, ], + trigger: { + branch: ["master"], + event: ["push", "tag", "promote", "rollback"], + }, })) const sshTest = { kind: 'pipeline', name: 'ssh-test', - clone: { - depth: 1, - }, steps: [ { name: 'ssh', @@ -77,19 +72,50 @@ const sshTest = { 'cd /home/core/staging && ls' ], }, - when: { - branch: ['master'], - }, }, ], + trigger: { + branch: ["master"], + event: ["push", "tag", "promote", "rollback"], + }, +}; + +const callSelf = { + kind: 'pipeline', + name: 'call-self', + steps: [ + { + name: 'regenrate', + image: 'node:12-alpine', + commands: [ + 'yarn install', + 'yarn generate', + ], + }, + { + name: 'push-or-fail', + image: 'appleboy/drone-git-push', + settings: { + remote_name: 'origin', + branch: '${DRONE_SOURCE_BRANCH}', + key: { + from_secret: 'push_ssh_key', + }, + commit: true, + commit_message: '[SKIP CI] Automatically updating .drone.yml', + }, + failure: 'ignore', + }, + ], + trigger: { + branch: ["master"], + event: ["pull_request"], + }, }; const deploy = { kind: 'pipeline', name: 'deploy', - clone: { - depth: 1, - }, steps: [ { name: 'submodule', @@ -98,9 +124,6 @@ const deploy = { recursive: true, submodule_override, }, - when: { - branch: ['master'], - }, }, { name: 'copy-docker-compose', @@ -117,9 +140,6 @@ const deploy = { ], target: '/home/core/staging', }, - when: { - branch: ['master'], - }, }, { name: 'copy-migrations', @@ -135,9 +155,6 @@ const deploy = { ], target: '/home/core/staging', }, - when: { - branch: ['master'], - }, }, { name: 'docker-compose-up', @@ -153,9 +170,6 @@ const deploy = { 'cd /home/core/staging && /home/core/docker-compose -f docker-compose.staging.yml up -d', ], }, - when: { - branch: ['master'], - }, }, { name: 'slack', @@ -165,15 +179,16 @@ const deploy = { from_secret: 'slack_webhook_beep', }, }, - when: { - branch: ['master'], - }, }, ], + trigger: { + branch: ["master"], + event: ["push", "tag", "promote", "rollback"], + }, depends_on: dockers, }; -const droneyml = [].concat(sshTest).concat(yamls).concat(deploy).map(yaml.safeDump).join('---\n'); +const droneyml = [].concat(sshTest).concat(callSelf).concat(yamls).concat(deploy).map(yaml.safeDump).join('---\n'); fs.writeFileSync(path.join(cwd, '.drone.yml'), droneyml); console.log('Written to .drone.yml'); diff --git a/package.json b/package.json index b77f5da..b751b28 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "generate": "node drone_gen.js" }, "dependencies": { + "ini": "^1.3.5", "js-yaml": "^3.13.0" } } diff --git a/yarn.lock b/yarn.lock index 876ae29..5f26931 100644 --- a/yarn.lock +++ b/yarn.lock @@ -14,6 +14,11 @@ esprima@^4.0.0: resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.1.tgz#13b04cdb3e6c5d19df91ab6987a8695619b0aa71" integrity sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A== +ini@^1.3.5: + version "1.3.5" + resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.5.tgz#eee25f56db1c9ec6085e0c22778083f596abf927" + integrity sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw== + js-yaml@^3.13.0: version "3.13.0" resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.13.0.tgz#38ee7178ac0eea2c97ff6d96fff4b18c7d8cf98e"