Add ssh-config input (#11)

Closes #10
This commit is contained in:
Benoît Chantre 2021-05-01 11:32:31 +02:00 committed by GitHub
parent 4b3c564869
commit ad4e7856ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 5 deletions

@ -6,13 +6,15 @@
with: with:
private-key: ${{ secrets.PRIVATE_KEY }} private-key: ${{ secrets.PRIVATE_KEY }}
known-hosts: ${{ secrets.KNOWN_HOSTS }} known-hosts: ${{ secrets.KNOWN_HOSTS }}
ssh-config: ${{ secrets.SSH_CONFIG }}
dep: deploy prod -v dep: deploy prod -v
``` ```
## Inputs ## Inputs
- `private-key` - Required. A private key to accessing servers. - `private-key` - Required. A private key to accessing servers.
- `known-hosts` - Optional. Host fingerprints. If omitted `StrictHostKeyChecking=no` will be used. - `known-hosts` - Optional. Host fingerprints. If omitted `StrictHostKeyChecking=no` will be used unless `ssh-config` is provided.
- `ssh-config` - Optional. SSH configuration.
- `dep` - Required. Arguments to pass to Deployer command. - `dep` - Required. Arguments to pass to Deployer command.
## Deployer version ## Deployer version
@ -41,5 +43,6 @@ deploy:
with: with:
private-key: ${{ secrets.PRIVATE_KEY }} private-key: ${{ secrets.PRIVATE_KEY }}
known-hosts: ${{ secrets.KNOWN_HOSTS }} known-hosts: ${{ secrets.KNOWN_HOSTS }}
ssh-config: ${{ secrets.SSH_CONFIG }}
dep: deploy prod -v dep: deploy prod -v
``` ```

@ -8,6 +8,10 @@ inputs:
description: 'Known hosts' description: 'Known hosts'
required: false required: false
default: '' default: ''
ssh-config:
description: 'SSH configuration'
required: false
default: ''
dep: dep:
description: 'Deployer command' description: 'Deployer command'
required: false required: false

@ -26,12 +26,17 @@ function ssh() {
let privateKey = core.getInput('private-key').replace('/\r/g', '').trim() + '\n' let privateKey = core.getInput('private-key').replace('/\r/g', '').trim() + '\n'
execa.sync('ssh-add', ['-'], {input: privateKey}) execa.sync('ssh-add', ['-'], {input: privateKey})
let knownHosts = core.getInput('known-hosts') const knownHosts = core.getInput('known-hosts')
if (knownHosts === '') { if (knownHosts !== '') {
fs.appendFileSync(`${ssh}/config`, `StrictHostKeyChecking no`)
} else {
fs.appendFileSync(`${ssh}/known_hosts`, knownHosts) fs.appendFileSync(`${ssh}/known_hosts`, knownHosts)
fs.chmodSync(`${ssh}/known_hosts`, '644') fs.chmodSync(`${ssh}/known_hosts`, '644')
} else {
fs.appendFileSync(`${ssh}/config`, `StrictHostKeyChecking no`)
}
const sshConfig = core.getInput('ssh-config')
if (sshConfig !== '') {
fs.writeFile(`${ssh}/config`, sshConfig)
} }
} }