-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Ansible CD using github action to deploy project on staging vm #1123
Open
iknowright
wants to merge
11
commits into
pycontw:master
Choose a base branch
from
iknowright:staging
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0c83bd1
add cd
iknowright 263043d
update playbook to build docker-image
iknowright a0f03a1
use synchronize instead of copy
iknowright f273953
update staging files
iknowright e42879f
add documentation for CD pipeline
iknowright e166efc
rename compose file
iknowright f874de8
make cd server flexible
iknowright fd20849
add google storage json to cd
iknowright 2a30e2c
docs(cd): improve description for continuous deployment
iknowright b152d8f
Merge branch 'master' into staging
josix 03e30ef
Merge branch 'master' into staging
josix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
add documentation for CD pipeline
- Loading branch information
commit e42879fd25b1827ce6d10da544094e9fbbca361f
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Continuous Deployment on Staging Server | ||
|
||
The following describes how to setup continuous deployment for staging server. This setup presumes the site administrators have site deployment practices based on the docker production deployment [document/deploy_docker_prod.md](/document/deploy_docker_prod.md). | ||
|
||
## Requirements for Staging Server | ||
The staging server should have the following installed: | ||
- Docker 17.09+ (since we use `--chown` flag in the COPY directive) | ||
- Docker Compose | ||
- python3.6+ | ||
- [docker](https://pypi.org/project/docker/) SDK for python | ||
- [docker-compose](https://pypi.org/project/docker-compose/) SDK for python | ||
|
||
|
||
## Prerequisite for Site Administrators | ||
- Gather Container Environment Variables as mention in [document/deploy_docker_prod.md](/document/deploy_docker_prod.md). | ||
- Have a ssh user and secret file for accessing GCE instance (staging machine) | ||
- Secret file will be further encoded by base64 | ||
- Administrators github Ids | ||
- For CD workflow authorization | ||
|
||
## Settings for Github Actions Workflow | ||
After aboves steps, we have to add collected information to github actions setting. | ||
Please configure as the following in project's setting: | ||
|
||
| Level | Type | Name | Value (example) | Remarks | | ||
|-----------|------------|---------------|----------|------------| | ||
| Repository | secrets | PRODUCTION_DOT_ENV_FILE | `DATABASE_URL=...` | multiline support | | ||
| Repository | secrets | GCE_USERNAME | cd_user | user name for ssh {user_name}@staging.pycon.tw | | ||
| Repository | secrets | SSH_PRIVATE_KEY | `21xa312....` | base64 encoded of key-pair (`.pem` file) | | ||
| Repository | variables | PROJECT_ADMINS | `["github_user_1", "github_user_2"]` | For example `["josix"]` | | ||
|
||
Reference | ||
- [Create a secret for a repository](https://docs.github.com/en/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository) | ||
- [Create a variable for a repository](https://docs.github.com/en/actions/learn-github-actions/variables#creating-configuration-variables-for-a-repository) | ||
- Create base64 encoded string for `key.pem` | ||
- `base64 -i key.pem` (mac) | ||
- `cat key.pem | base64` (linux) | ||
|
||
## Review | ||
### Events that triggers the pipeline | ||
1. When the PR merges to `master` | ||
- no authorization needed, as PRs normally reviewed before merge | ||
2. Manually [trigger](https://docs.github.com/en/actions/managing-workflow-runs/manually-running-a-workflow#running-a-workflow) the CD workflow (By admins) | ||
- only for Administrator specify in repository's variable called *PROJECTS_ADMINS* | ||
|
||
Why? CD workflow will directly access to the GCE instance, should prevent unwanted deployments from PRs or push. (As a deployment guardian) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Overall the document looks great to me. Thanks @iknowright!
Here are some suggestions. If you think they would be beneficial, please feel free to adopt them.