├── Dockerfile ├── entrypoint.sh ├── action.yml └── README.md /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.6 2 | 3 | RUN apk add --no-cache bash git openssh-client 4 | 5 | COPY entrypoint.sh /entrypoint.sh 6 | RUN chmod +x /entrypoint.sh 7 | 8 | ENTRYPOINT ["/entrypoint.sh"] 9 | -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | SSH_PRIVATE_KEY=$1 4 | DOKKU_USER=$2 5 | DOKKU_HOST=$3 6 | DOKKU_APP_NAME=$4 7 | DOKKU_REMOTE_BRANCH=$5 8 | GIT_PUSH_FLAGS=$6 9 | SSH_PORT=$7 10 | COMMIT="${8:-$GITHUB_SHA}" 11 | 12 | # Setup the SSH environment 13 | mkdir -p ~/.ssh 14 | eval `ssh-agent -s` 15 | ssh-add - <<< "$SSH_PRIVATE_KEY" 16 | ssh-keyscan $DOKKU_HOST >> ~/.ssh/known_hosts 17 | 18 | # Setup the git environment 19 | git_repo="$DOKKU_USER@$DOKKU_HOST:$DOKKU_APP_NAME" 20 | cd "$GITHUB_WORKSPACE" 21 | git remote add deploy "$git_repo" 22 | 23 | # Prepare to push to Dokku git repository 24 | REMOTE_REF="$COMMIT:refs/heads/$DOKKU_REMOTE_BRANCH" 25 | 26 | GIT_COMMAND="git push deploy $REMOTE_REF $GIT_PUSH_FLAGS" 27 | echo "GIT_COMMAND=$GIT_COMMAND" 28 | 29 | # Push to Dokku git repository 30 | GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p $SSH_PORT" $GIT_COMMAND 31 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: "Dokku Deploy action" 2 | author: "Ido Berkovich" 3 | description: "Deploy to a dokku instance using Github actions" 4 | branding: 5 | icon: "upload-cloud" 6 | color: "green" 7 | inputs: 8 | ssh-private-key: 9 | description: "The ssh private key to the dokku instance. WARNING: use a secret! Do not pass a plain text value!" 10 | required: true 11 | dokku-user: 12 | description: "The user to use for ssh (Default: dokku)" 13 | required: false 14 | default: "dokku" 15 | dokku-host: 16 | description: "The dokku host to ssh into" 17 | required: true 18 | app-name: 19 | description: "The dokku app name" 20 | required: true 21 | remote-branch: 22 | description: "The branch to push on the remote repository (Default: master)" 23 | required: false 24 | default: "master" 25 | git-push-flags: 26 | description: "Additional flags to be passed to the git push command. Could be used to force push" 27 | required: false 28 | default: "" 29 | ssh-port: 30 | description: "Custom port for ssh host" 31 | required: false 32 | default: "22" 33 | commit: 34 | description: "Commit to push to dokku. Defaults to $GITHUB_SHA" 35 | required: false 36 | default: "" 37 | runs: 38 | using: "docker" 39 | image: "Dockerfile" 40 | args: 41 | - ${{ inputs.ssh-private-key }} 42 | - ${{ inputs.dokku-user }} 43 | - ${{ inputs.dokku-host }} 44 | - ${{ inputs.app-name }} 45 | - ${{ inputs.remote-branch }} 46 | - ${{ inputs.git-push-flags }} 47 | - ${{ inputs.ssh-port }} 48 | - ${{ inputs.commit }} 49 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # dokku-deploy-github-action 2 | 3 | This action makes deployment to Dokku as easy as possible! 4 | 5 | ## Inputs 6 | 7 | ### ssh-private-key 8 | 9 | The private ssh key used for Dokku deployments. Never use as plain text! Configure it as a secret in your repository by navigating to https://github.com/USERNAME/REPO/settings/secrets 10 | 11 | - Your private key must *not* have a passphrase 12 | 13 | **Required** 14 | 15 | ### dokku-user 16 | 17 | The user to use for ssh. If not specified, "dokku" user will be used. 18 | 19 | ### dokku-host 20 | 21 | The Dokku host to deploy to. 22 | 23 | ### app-name 24 | 25 | The Dokku app name to be deployed. 26 | 27 | ### remote-branch 28 | 29 | The branch to push on the remote repository. If not specified, `master` will be used. 30 | 31 | ### git-push-flags 32 | 33 | You may set additional flags that will be passed to the `git push` command. You might want to set this parameter to `--force` if you're pushing to Dokku from other places and encounter the following error: 34 | ``` 35 | error: failed to push some refs to 'dokku@mydokkuhost.com:mydokkurepo' 36 | hint: Updates were rejected because the remote contains work that you do 37 | hint: not have locally. This is usually caused by another repository pushing 38 | hint: to the same ref. You may want to first integrate the remote changes 39 | hint: (e.g., 'git pull ...') before pushing again. 40 | hint: See the 'Note about fast-forwards' in 'git push --help' for details. 41 | ``` 42 | 43 | ### ssh-port 44 | 45 | Port for ssh host. If not specified, `22` will be used. 46 | 47 | ### commit 48 | 49 | Commit to deploy. If not specified, `$GITHUB_SHA` (current commit) will be used. 50 | 51 | 52 | ## Example 53 | 54 | Note: `actions/checkout` must preceed this action in order for the repository data to be exposed for the action. 55 | It is recommended to pass `actions/checkout` the `fetch-depth: 0` parameter to avoid errors such as `shallow update not allowed` 56 | 57 | ``` 58 | steps: 59 | - uses: actions/checkout@v2 60 | with: 61 | fetch-depth: 0 62 | - id: deploy 63 | name: Deploy to dokku 64 | uses: idoberko2/dokku-deploy-github-action@v1 65 | with: 66 | ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} 67 | dokku-host: 'my-dokku-host.com' 68 | app-name: 'my-dokku-app' 69 | ``` 70 | --------------------------------------------------------------------------------