Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 6 additions & 61 deletions .github/workflows/prod-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,76 +9,21 @@ on:

jobs:
deploy:
name: Deploy to production
runs-on: ubuntu-latest

# deploy to the production environment
environment:
name: production
url: http://github-actions-demo-app.dokku.proxima-web.com

steps:
- name: Cloning repo
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Create deployment
id: create_deployment
uses: octokit/request-action@v2.0.26
with:
route: POST /repos/:repository/deployments
repository: ${{ github.repository }}
ref: ${{ github.sha }}
environment: production
required_contexts: '[]'
production_environment: true
auto_merge: false
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'

- name: Set deployment status to in progress
uses: octokit/request-action@v2.0.26
with:
route: POST /repos/:repository/deployments/:deployment/statuses
repository: ${{ github.repository }}
deployment: ${{ fromJson(steps.create_deployment.outputs.data).id }}
environment: production
environment_url: http://github-actions-demo-app.dokku.proxima-web.com
log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
state: in_progress
mediaType: '{"previews": ["flash", "ant-man"]}' # required for setting in_progress state and environment_url
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'

- name: Push to dokku
uses: dokku/github-action@master
with:
git_remote_url: 'ssh://dokku@dokku.proxima-web.com:22/github-actions-demo-app'
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}

- name: Set GitHub deployment status to success
id: successful_deployment
if: success()
uses: octokit/request-action@v2.0.26
with:
route: POST /repos/:repository/deployments/:deployment/statuses
repository: ${{ github.repository }}
deployment: ${{ fromJson(steps.create_deployment.outputs.data).id }}
environment: review
environment_url: http://github-actions-demo-app.dokku.proxima-web.com
log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
mediaType: '{"previews": ["ant-man"]}'
state: success
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'

- name: Set GitHub deployment status to failure
id: failed_deployment
uses: octokit/request-action@v2.0.26
if: failure()
with:
route: POST /repos/:repository/deployments/:deployment/statuses
repository: ${{ github.repository }}
deployment: ${{ fromJson(steps.create_deployment.outputs.data).id }}
environment: review
environment_url: http://github-actions-demo-app.dokku.proxima-web.com
log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
mediaType: '{"previews": ["ant-man"]}'
state: failure
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
96 changes: 33 additions & 63 deletions .github/workflows/review-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,51 @@ name: 'Deploy Review App'

# yamllint disable-line rule:truthy
on:
# onl run this workflow on pull request events
pull_request
# only run this workflow on pull request events
pull_request:
types: [opened, synchronize, closed]

jobs:
review_app:
runs-on: ubuntu-latest
# only run when a pull request is opened
if: github.event_name == 'pull_request'
environment: review
# only run when a pull request is opened or synchronized
if: github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'synchronize')

# deploy to the review environment
environment:
name: review
url: http://github-actions-demo-app-${{ github.event.pull_request.number }}.dokku.proxima-web.com

steps:
- name: Cloning repo
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Create deployment
id: create_deployment
uses: octokit/request-action@v2.0.26
with:
route: POST /repos/:repository/deployments
repository: ${{ github.repository }}
ref: ${{ github.event.pull_request.head.ref }}
environment: review
required_contexts: '[]'
production_environment: true
auto_merge: false
- name: Dump GitHub context
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'

- name: Set deployment status to in progress
uses: octokit/request-action@v2.0.26
with:
route: POST /repos/:repository/deployments/:deployment/statuses
repository: ${{ github.repository }}
deployment: ${{ fromJson(steps.create_deployment.outputs.data).id }}
environment: review
environment_url: http://github-actions-demo-app-${{ github.event.pull_request.number }}.dokku.proxima-web.com
log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
state: in_progress
mediaType: '{"previews": ["flash", "ant-man"]}' # required for setting in_progress state and environment_url
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: echo "$GITHUB_CONTEXT"
- name: Dump job context
env:
JOB_CONTEXT: ${{ toJSON(job) }}
run: echo "$JOB_CONTEXT"
- name: Dump steps context
env:
STEPS_CONTEXT: ${{ toJSON(steps) }}
run: echo "$STEPS_CONTEXT"
- name: Dump runner context
env:
RUNNER_CONTEXT: ${{ toJSON(runner) }}
run: echo "$RUNNER_CONTEXT"
- name: Dump strategy context
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
STRATEGY_CONTEXT: ${{ toJSON(strategy) }}
run: echo "$STRATEGY_CONTEXT"
- name: Dump matrix context
env:
MATRIX_CONTEXT: ${{ toJSON(matrix) }}
run: echo "$MATRIX_CONTEXT"

- name: Push to dokku
uses: dokku/github-action@master
Expand All @@ -57,39 +60,6 @@ jobs:
review_app_name: github-actions-demo-app-${{ github.event.pull_request.number }}
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}

- name: Set GitHub deployment status to success
id: successful_deployment
if: success()
uses: octokit/request-action@v2.0.26
with:
route: POST /repos/:repository/deployments/:deployment/statuses
repository: ${{ github.repository }}
deployment: ${{ fromJson(steps.create_deployment.outputs.data).id }}
environment: review
environment_url: http://github-actions-demo-app-${{ github.event.pull_request.number }}.dokku.proxima-web.com
log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
mediaType: '{"previews": ["ant-man"]}'
state: success
auto_inactive: false
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'

- name: Set GitHub deployment status to failure
id: failed_deployment
uses: octokit/request-action@v2.0.26
if: failure()
with:
route: POST /repos/:repository/deployments/:deployment/statuses
repository: ${{ github.repository }}
deployment: ${{ fromJson(steps.create_deployment.outputs.data).id }}
environment: review
environment_url: http://github-actions-demo-app-${{ github.event.pull_request.number }}.dokku.proxima-web.com
log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
mediaType: '{"previews": ["ant-man"]}'
state: failure
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'

destroy_review_app:
runs-on: ubuntu-latest
# only run when a pull request is closed
Expand Down
58 changes: 35 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,51 @@
# Dokku GitHub Action Example

An example repo showing how to use the official [dokku GitHub action](https://github.com/dokku/github-action) to deploy your app with continuous delivery.
How to use the official [dokku GitHub action](https://github.com/dokku/github-action) to deploy your app using continuous delivery with GitHub Actions and GitHub Deploys.

## GitHub Secrets
GitHub Deploys is still in public beta but it's stablish and is a useful mechanism to manage your deployment workflows. You can use [environment protection rules](https://docs.github.com/en/actions/reference/environments#environment-protection-rules) to give you granular control over [who can deploy](https://docs.github.com/en/actions/managing-workflow-runs/reviewing-deployments) and to where.

The following secrets must be set:
## Workflows

- `SSH_PRIVATE_KEY`
This repository demonstrates how to:

You'll see reference to a secret called `GITHUB_TOKEN` in the workflow files, but there's no need to manually set this yourself as this is set by GitHub Actions.
- Deploy `review` apps to a `review` environment when a pull request is created or updated.
- Deploy a `production` app to a `production` environment on changes to the main/master branch.

If you want to see debug information, you can create a secret called `ACTIONS_STEP_DEBUG` with a value of `true`.
You'll need to create the following following environments in the repository settings:

## dokku Setup
- production
- review

```bash
# on server
dokku apps:create github-actions-demo-app
```
Take advantage of the [environment protection rules](https://docs.github.com/en/actions/reference/environments#environment-protection-rules) to enable deploy restrictions.

```bash
# on local
git remote add dokku dokku@dokku.proxima-web.com:github-actions-demo-app
git push dokku
```
### Review Apps

Visit http://github-actions-demo-app.dokku.proxima-web.com/ to confirm the deployment was successful.
Each time a pull request is opened or updated a new review app is deployed to url `http://github-actions-demo-app-${{ github.event.pull_request.number }}.dokku.proxima-web.com`.

## Review Apps
#### Screenshots

Each time a pull request is opened a new review app is deployed.
The following screenshots shows the deploy workflow when the `review` environment requires reviewers:

The [example workflow](./.github/workflows/review-app.yml) uses [GitHub Deploys](https://docs.github.com/en/rest/reference/repos#deployments) and requires the following [environments](https://docs.github.com/en/actions/reference/environments) to be created:
##### Pull request created, but deploy is awaiting approval

- production
- review
<img src="./screenshots/awaiting-approval.png" style="max-width:600px" />

##### GitHub Actions deploy workflow awaiting approval

<img src="./screenshots/github-actions-review.png" style="max-width:600px" />

##### Approving the deploy workflow

<img src="./screenshots/github-actions-approve-deploy.png" style="max-width:600px" />

##### Deployment in progress

<img src="./screenshots/deploy-started.png" style="max-width:600px" />

##### Deployment successful

<img src="./screenshots/successful-deploy.png" style="max-width:600px" />

### Production App

You can add new environments in your repo settings. You can also take advantage of [environment protection rules](https://docs.github.com/en/actions/reference/environments#environment-protection-rules) to request reviews before deployments can take place.
Each time the main/master branch is created or updated a new production app is deployed to `http://github-actions-demo-app.dokku.proxima-web.com`.
Binary file added screenshots/awaiting-approval.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/deploy-started.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/github-actions-approve-deploy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/github-actions-review.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/successful-deploy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.