From e1f2c29d6b8d9009e46862aa5f535e1228fd1314 Mon Sep 17 00:00:00 2001 From: Leandro Facchinetti Date: Fri, 20 Mar 2020 01:37:31 -0400 Subject: [PATCH] . --- .github/workflows/main.yml | 12 +++++++++ package.json | 5 ++++ src/tasks.ts | 53 ++------------------------------------ 3 files changed, 19 insertions(+), 51 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b04bd37..42024cc 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,3 +8,15 @@ jobs: with: node-version: "13.x" - run: npm install-ci-test + - uses: webfactory/ssh-agent@v0.2.0 + with: + ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} + if: github.ref == 'ref/head/master' + - run: | + ssh -A root@204.48.21.111 'ssh git@github.com' + if: github.ref == 'ref/head/master' +# - run: | +# mkdir ~/.ssh +# echo "${{ secrets.SECRET_PRIVATE_DEPLOY_KEY }}" > ~/.ssh/id_rsa +# chmod 600 ~/.ssh/id_rsa +# ssh-add diff --git a/package.json b/package.json index 76c59f8..3206de5 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,11 @@ "ref": "origin/master", "repo": "git@github.com:leafac/www.kill-the-newsletter.com.git", "path": "/root/www.kill-the-newsletter.com", + "pre-setup-documentation": [ + "https://github.com/nodesource/distributions#debinstall", + "https://certbot.eff.org/docs/install.html" + ], + "pre-setup": "ssh -o StrictHostKeyChecking=no git@github.com; apt-get update; apt-get install -y build-essential software-properties-common; curl -sL https://deb.nodesource.com/setup_13.x | bash -; add-apt-repository universe; add-apt-repository ppa:certbot/certbot; apt-get install -y nodejs certbot", "ssh_options": [ "ForwardAgent=yes", "StrictHostKeyChecking=no" diff --git a/src/tasks.ts b/src/tasks.ts index 4fa9e83..7fed643 100644 --- a/src/tasks.ts +++ b/src/tasks.ts @@ -1,54 +1,5 @@ -import child_process from "child_process"; - -switch (process.argv[2]) { - case "provision": - child_process.execSync(`ssh-add`); - - // https://github.com/nodesource/distributions#debinstall - // https://certbot.eff.org/docs/install.html - exec(`apt-get update`); - exec(`apt-get install -y build-essential software-properties-common`); - exec(`curl -sL https://deb.nodesource.com/setup_13.x | bash -`); - exec(`add-apt-repository universe`); - exec(`add-apt-repository ppa:certbot/certbot`); - exec(`apt-get install -y nodejs certbot`); - - exec(`git clone git@github.com:leafac/www.kill-the-newsletter.com.git`); - break; - case "deploy": - child_process.execSync(`ssh-add`); - - execInFolder(`git pull origin master`); - execInFolder(`npm ci`); + // execInFolder(`git pull origin master`); + // execInFolder(`npm ci`); // TODO: rsync // TODO: $ pm2 startup OR $ pm2 save // TODO: $ pm2 start env.js --watch --ignore-watch="node_modules" - break; - default: - console.error( - `Unknown invocation: ${JSON.stringify(process.argv, undefined, 2)}` - ); - process.exit(1); -} - -function exec(command: string): void { - console.log("$", command); - child_process.execFileSync( - "ssh", - ["-tA", "root@kill-the-newsletter.com", command], - { stdio: "inherit" } - ); -} - -function execInFolder(command: string): void { - exec(`cd www.kill-the-newsletter.com && env NODE_ENV=production ${command}`); -} - -// - run: | -// mkdir ~/.ssh -// echo "${{ secrets.SECRET_PRIVATE_DEPLOY_KEY }}" > ~/.ssh/id_rsa -// chmod 600 ~/.ssh/id_rsa - -// https://github.com/webfactory/ssh-agent - -// root 'apt-get install -y curl file git'