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
66 changes: 6 additions & 60 deletions .github/workflows/prod-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,74 +11,20 @@ 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 }}'
77 changes: 11 additions & 66 deletions .github/workflows/review-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,27 @@ 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
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
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'

- name: Push to dokku
uses: dokku/github-action@master
with:
Expand All @@ -57,39 +35,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
42 changes: 35 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,40 @@
# 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 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.

## Workflows

This repository demonstrates how to:

- 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. No deployment review is required.

### Review Apps

Each time a pull request is opened or updated a new review app is deployed. The review app will be deployed to url `http://github-actions-demo-app-${{ github.event.pull_request.number }}.dokku.proxima-web.com`.

You'll need to create the following following environments in the repository settings:

- production
- review

Take advantage of the [environment protection rules](https://docs.github.com/en/actions/reference/environments#environment-protection-rules) to enable deploy restrictions.

#### Screenshots

Pull request created, but deploy is awaiting approval:

GitHub Actions deploy workflow awaiting approval:

Approving the deploy workflow:

Deployment in progress:

Deployment successful:



## GitHub Secrets

Expand Down Expand Up @@ -29,11 +63,5 @@ Visit http://github-actions-demo-app.dokku.proxima-web.com/ to confirm the deplo

## Review Apps

Each time a pull request is opened a new review app is deployed.

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:

- production
- review

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.
2 changes: 1 addition & 1 deletion html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
</head>
<body>
<h1>github-actions-demo-app</h1>
<p>Version: 1</p>
<p>Version: 3</p>
</body>
</html>