Skip to content
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

Integrate with Github Actions #346

Merged
merged 35 commits into from
Sep 8, 2020
Merged

Integrate with Github Actions #346

merged 35 commits into from
Sep 8, 2020

Conversation

yong-jie
Copy link
Member

@yong-jie yong-jie commented Aug 3, 2020

Problem

I think there is value in trying out github actions as our CI provider, with the main reason being support for concurrent builds without hoarding travis' concurrent builds limit.

Approach

Traditionally, our CI/CD pipeline consists of the following steps done in sequence:

Lint -> Test -> Build -> Push to ECR -> Deploy to EB

With Github Actions, we can do Lint, Test and Build+Push concurrently, before Deploying to EB after the previous 3 jobs have finished. This an optimistic approach because it builds and pushes the docker image to ECR without checking if Lint and Test have passed. Here is the primary tradeoff:

Pros:

  • Overall time to deployment drastically reduces because the build step happens concurrently with tests.

Cons:

  • Potentially wasted computation if either Lint or Test builds fail.

Rationale:

  • Tests and lint rarely fails in the deployment merge because we would have undergone both the release checklist and all other checks before merging into release.
  • This approach is still safe because the final deployment step still waits for all of Lint, Test, and Build+Push to pass before executing.

Things to note

Syntax is lacking
The Github Actions syntax is still in its early phases of development and is missing some quality-of-life configuration options. This means I had to rely on some workarounds to get some things done.

An example is the dedicated job called gatekeep which helps determine whether the build & deploy jobs need to be executed. The workaround is necessary because I can't utilise the env context inside the if statements for jobs, so something like if: branch == env.STAGING || branch == env.PRODUCTION is not possible.

gatekeep:
name: Determine if Build & Deploy is needed
outputs:
proceed: ${{ steps.determine_proceed.outputs.proceed }}
runs-on: ubuntu-18.04
steps:
- shell: python
id: determine_proceed
run: |
import os
ref = os.environ['GITHUB_REF']
prod = os.environ['PRODUCTION_BRANCH']
stage = os.environ['STAGING_BRANCH']
if ref == prod or ref == stage:
print('::set-output name=proceed::true')
else:
print('::set-output name=proceed::false')

Weak env var selection mechanism
Our builds use different versions of env vars depending on the branch that the Github Action is being run on. At present, I could not find a nice way to select variants of env vars depending on the branch, so I have resorted to using scripts to set our necessary EB env vars.

- name: Select Elastic Beanstalk variables
shell: python
run: |
import os
branch = os.environ['GITHUB_REF']
staging = os.environ['STAGING_BRANCH']
production = os.environ['PRODUCTION_BRANCH']
eb_app_staging = os.environ['EB_APP_STAGING']
eb_env_staging = os.environ['EB_ENV_STAGING']
eb_app_production = os.environ['EB_APP_PRODUCTION']
eb_env_production = os.environ['EB_ENV_PRODUCTION']
if branch == staging:
print('::set-output name=eb_app::' + eb_app_staging)
print('::set-output name=eb_env::' + eb_env_staging)
elif branch == production:
print('::set-output name=eb_app::' + eb_app_production)
print('::set-output name=eb_env::' + eb_env_production)
id: select_eb_vars

Lack of inter-workflow dependency/message-passing
It's a universally good practice to split blocks of logic/code into different files. This is not yet supported in Github Actions and I am lumping both CI and CD into a single workflow file for the time being.

List of things done

  • Build (tsc)
  • Lint
  • Test
  • Integrate with Coveralls
  • Build (Docker)
  • Send to ECR
  • Set up conditional jobs
  • Deploy to EB

@yong-jie yong-jie force-pushed the gh-actions1 branch 2 times, most recently from 8a778db to 6501fb4 Compare September 7, 2020 08:08
@yong-jie yong-jie marked this pull request as ready for review September 8, 2020 05:28
Copy link
Contributor

@LoneRifle LoneRifle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm otherwise; please:

  • review comments
  • figure out if we can immediately replace Travis

.github/workflows/ci.yml Outdated Show resolved Hide resolved
@yong-jie yong-jie merged commit f22bbec into develop Sep 8, 2020
@yong-jie yong-jie deleted the gh-actions1 branch September 8, 2020 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants