Skip to content

Commit 7d550ae

Browse files
author
Jose Diaz-Gonzalez
committed
Initial commit
0 parents  commit 7d550ae

File tree

8 files changed

+165
-0
lines changed

8 files changed

+165
-0
lines changed

Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM alpine:3.12.1
2+
3+
RUN apk --no-cache add git==2.26.2-r0 openssh==8.3_p1-r0 && \
4+
mkdir -p ~/.ssh
5+
6+
COPY bin /bin

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Olivier Brassard
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# dokku github-action
2+
3+
Easily deploy an app to your Dokku Instance from GitHub
4+
5+
### Requirements
6+
7+
Please note that this action is compatible with `dokku >= 0.11.6`.
8+
9+
## Inputs
10+
11+
#### `deploy_branch`
12+
13+
Optional. The branch to be deployed when pushing to Dokku (default to `master`). Useful when a [custom deploy branch](http://dokku.viewdocs.io/dokku/deployment/methods/git/#changing-the-deploy-branch) is set on Dokku.
14+
15+
Example Value: `develop`
16+
17+
#### `remote_url`
18+
19+
**Required**. The dokku app's git repository url **(in SSH format)**.
20+
21+
Example Value: `ssh://dokku@dokku.myhost.ca:22/appname`
22+
23+
#### `ssh_key`
24+
25+
**Required**. A private ssh key that has push access to your Dokku instance.
26+
27+
Example Value:
28+
29+
```
30+
-----BEGIN OPENSSH PRIVATE KEY-----
31+
MIIEogIBAAKCAQEAjLdCs9kQkimyfOSa8IfXf4gmexWWv6o/IcjmfC6YD9LEC4He
32+
qPPZtAKoonmd86k8jbrSbNZ/4OBelbYO0pmED90xyFRLlzLr/99ZcBtilQ33MNAh
33+
...
34+
SvhOFcCPizxFeuuJGYQhNlxVBWPj1Jl6ni6rBoHmbBhZCPCnhmenlBPVJcnUczyy
35+
zrrvVLniH+UTjreQkhbFVqLPnL44+LIo30/oQJPISLxMYmZnuwudPN6O6ubyb8MK
36+
-----END OPENSSH PRIVATE KEY-----
37+
38+
```
39+
40+
> :bulb: Tip : It is recommended to use [Encrypted Secrets](https://docs.github.com/en/free-pro-team@latest/actions/reference/encrypted-secrets) to store sensitive information such as SSH Keys.
41+
42+
## Example usage
43+
44+
This action is particularly useful when triggered by new pushes:
45+
46+
```yml
47+
name: 'Deploy to my Dokku instance'
48+
49+
on:
50+
push:
51+
branches:
52+
- master
53+
54+
jobs:
55+
deploy:
56+
runs-on: ubuntu-latest
57+
steps:
58+
59+
- name: Cancel Previous Runs # Optional step
60+
uses: styfle/cancel-workflow-action@0.4.0
61+
with:
62+
access_token: ${{ github.token }}
63+
64+
- name: Cloning repo # This step is required
65+
uses: actions/checkout@v2
66+
with:
67+
fetch-depth: 0 # This is required or you will get an error regarding shallow pushes from Dokku
68+
69+
- name: Push to dokku
70+
uses: obrassard/action-dokku-deploy@v1.0.3
71+
with:
72+
deploy_branch: 'master'
73+
remote_url: 'ssh://dokku@dokku.myhost.ca:22/appname'
74+
ssh_key: ${{ secrets.SSH_KEY }}
75+
```

action.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# action.yml
2+
name: 'Dokku'
3+
description: 'Deploys an app via git push to a Dokku instance'
4+
author: 'Dokku'
5+
branding:
6+
icon: 'upload-cloud'
7+
color: 'blue'
8+
inputs:
9+
deploy_branch:
10+
description: 'The branch to be deployed when pushing to Dokku (default: master)'
11+
required: false
12+
default: "master"
13+
remote_url:
14+
description: "The dokku app's git repository url (in SSH format)"
15+
required: true
16+
ssh_key:
17+
description: 'A private SSH key that has push acces to your Dokku instance'
18+
required: true
19+
runs:
20+
using: 'docker'
21+
image: 'Dockerfile'
22+
entrypoint: '/bin/entrypoint'
23+
post-entrypoint: '/bin/dokku-unlock'
24+
post-if: cancelled()
25+
env:
26+
SSH_PRIVATE_KEY : ${{ inputs.ssh_key }}
27+
REMOTE_URL : ${{ inputs.remote_url }}
28+
DEPLOY_BRANCH : ${{ inputs.deploy_branch }}

bin/dokku-unlock

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh -l
2+
3+
. "/bin/setup-ssh"
4+
5+
echo ""
6+
log-info "Unlocking Dokku deployment";
7+
8+
app=$(echo $REMOTE_URL | sed -e 's/.*\///')
9+
ssh -p ${ssh_port:=22} dokku@$ssh_host apps:unlock $app

bin/entrypoint

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh -l
2+
3+
. "/bin/setup-ssh"
4+
5+
echo ""
6+
log-info "Pushing to Dokku Host";
7+
8+
git push $REMOTE_URL $GITHUB_SHA:refs/heads/$DEPLOY_BRANCH --force
9+
10+
[ $? -eq 0 ] || exit 1

bin/log-info

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh -l
2+
3+
echo -e "\u001b[32m${@}\u001b[0m";

bin/setup-ssh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/sh -l
2+
3+
log-info "Setting up SSH Key"
4+
5+
mkdir -p /root/.ssh
6+
echo "$SSH_PRIVATE_KEY" | tr -d '\r' > /root/.ssh/id_rsa
7+
chmod 600 /root/.ssh/id_rsa
8+
ssh_host=$(echo $REMOTE_URL | sed -e 's/.*@//' -e 's/[:/].*//')
9+
# Extract port number. Defaults to port 22.
10+
ssh_port=$(echo $REMOTE_URL | sed -e 's/.*@//' -e 's/\/.*//' -ne 's/.*:\([0-9]*\)/\1/p')
11+
ssh-keyscan -H -p "${ssh_port:=22}" "$ssh_host" >> /root/.ssh/known_hosts
12+
eval "$(ssh-agent -s)"
13+
ssh-add /root/.ssh/id_rsa

0 commit comments

Comments
 (0)