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

48 refactor ci pipeline #49

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
b5cf280
refactor: remove unused test job
victorggonzalez Aug 30, 2022
54792c3
feat: cache dependencies to speed up workflow
victorggonzalez Aug 30, 2022
ec2d8d3
fix: typo
victorggonzalez Aug 30, 2022
8e02221
feat: cache only for development branches
victorggonzalez Aug 30, 2022
be1dde0
refactor: remove unused test job
victorggonzalez Aug 30, 2022
fd864ad
refactor: restore-key approach
victorggonzalez Aug 30, 2022
ce30bc7
refactor: adapt job structure
victorggonzalez Aug 30, 2022
9c475e1
feat: cache dependencies to speed up workflow
victorggonzalez Aug 30, 2022
c4a1ecd
refactor: remove unused test job
victorggonzalez Aug 30, 2022
1a5a7a9
refactor: remove CD unused test job
victorggonzalez Aug 30, 2022
3419d96
feat: add concurrency control
victorggonzalez Aug 30, 2022
ec772ad
refactor: test new approach
victorggonzalez Aug 31, 2022
2c18f71
fix: add missing cache step
victorggonzalez Aug 31, 2022
e2a9605
test: conditional behavior
victorggonzalez Aug 31, 2022
b6174ee
fix: test improve cache behavior
victorggonzalez Sep 1, 2022
a048c4d
fix: deprecated yarn flag
victorggonzalez Sep 1, 2022
7874cc4
fix: invalid command
victorggonzalez Sep 1, 2022
b795324
refactor: final cache approach
victorggonzalez Sep 1, 2022
b6a3a8d
refactor: caller workflow for ci approach
victorggonzalez Sep 1, 2022
b9d89f0
refactor: cache dependencies
victorggonzalez Sep 3, 2022
1ba6f4f
refactor: adapt caller workflow to new approach
victorggonzalez Sep 6, 2022
cd671c8
fix: remove unnecessary test inputs
victorggonzalez Sep 6, 2022
66fdf7e
refactor: add test job and inputs
victorggonzalez Sep 6, 2022
dc24770
refactor: library ci workflow
victorggonzalez Sep 6, 2022
32d7c09
fix: deploy condition to avoid always executing
victorggonzalez Sep 6, 2022
bbd548d
refactor: ci workflow for ecs backend
victorggonzalez Sep 6, 2022
7482ec6
refactor: build phase for ci pipeline
victorggonzalez Sep 7, 2022
596f553
fix: unnecessary condition
victorggonzalez Sep 7, 2022
ebac525
style: fix comments
victorggonzalez Sep 7, 2022
a3ce6db
refactor: ci workflow for ecs explorer
victorggonzalez Sep 7, 2022
e042668
fix: include changes after review
victorggonzalez Sep 20, 2022
6938232
style: include comments
victorggonzalez Sep 20, 2022
3a5d66b
fix: update caller workflows
victorggonzalez Sep 20, 2022
95147ce
fix: change input variable requirement
victorggonzalez Sep 20, 2022
44398dc
fix: add condition for push event
victorggonzalez Sep 20, 2022
9e977fb
fix: change input type
victorggonzalez Sep 20, 2022
5a5170f
fix: typo
victorggonzalez Sep 20, 2022
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
19 changes: 1 addition & 18 deletions .github/workflows/cdelivery-ecs-backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ env:
# Allows to increase Node's max heap size
NODE_OPTIONS: '--max_old_space_size=8192'

# This workflow is made up of two jobs that run sequentially, called: build-deploy and test
# This workflow is made up of one job called build-deploy
jobs:
# Build image, push to ECR and deploy to staging environment
build-deploy:
Expand Down Expand Up @@ -339,20 +339,3 @@ jobs:
service: ${{ secrets.ecs-service }}
cluster: ${{ secrets.ecs-cluster }}
wait-for-service-stability: true

test:
name: Test
needs: build-deploy
# The type of runner that the job will run on
runs-on: ubuntu-latest
steps:
# Check-out repository under $GITHUB_WORKSPACE, so the job can access it
- name: Check out code
uses: actions/checkout@v2
with:
ref: ${{ inputs.tag }}

# This step runs a single command to execute integation testing
- name: Test
run: |
echo "This is the integration test step"
19 changes: 1 addition & 18 deletions .github/workflows/cdelivery-ecs-explorer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ env:
# Allows to increase Node's max heap size
NODE_OPTIONS: '--max_old_space_size=8192'

# This workflow is made up of two jobs that run sequentially, called: build-deploy and test
# This workflow is made up of one job called build-deploy
jobs:
# Build image, push to ECR and deploy to staging environment
build-deploy:
Expand Down Expand Up @@ -143,20 +143,3 @@ jobs:
service: ${{ secrets.ecs-service }}
cluster: ${{ secrets.ecs-cluster }}
wait-for-service-stability: true

test:
name: Test
needs: build-deploy
# The type of runner that the job will run on
runs-on: ubuntu-latest
steps:
# Check-out repository under $GITHUB_WORKSPACE, so the job can access it
- name: Check out code
uses: actions/checkout@v2
with:
ref: ${{ inputs.tag }}

# This step runs a single command to execute integation testing
- name: Test
run: |
echo "This is the integration test step"
19 changes: 1 addition & 18 deletions .github/workflows/cdelivery-ecs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ env:
# Allows to increase Node's max heap size
NODE_OPTIONS: '--max_old_space_size=8192'

# This workflow is made up of two jobs that run sequentially, called: build-deploy and test
# This workflow is made up of one job called build-deploy
jobs:
# Build image, push to ECR and deploy to staging environment
build-deploy:
Expand Down Expand Up @@ -130,20 +130,3 @@ jobs:
service: ${{ secrets.ecs-service }}
cluster: ${{ secrets.ecs-cluster }}
wait-for-service-stability: true

test:
name: Test
needs: build-deploy
# The type of runner that the job will run on
runs-on: ubuntu-latest
steps:
# Check-out repository under $GITHUB_WORKSPACE, so the job can access it
- name: Check out code
uses: actions/checkout@v2
with:
ref: ${{ inputs.tag }}

# This step runs a single command to execute integation testing
- name: Test
run: |
echo "This is the integration test step"
19 changes: 1 addition & 18 deletions .github/workflows/cdelivery-s3-apps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ env:
# Allows to increase Node's max heap size
NODE_OPTIONS: '--max_old_space_size=8192'

# This workflow is made up of two jobs that run sequentially, called: build-deploy and test
# This workflow is made up of one job called build-deploy
jobs:
# Build, sync with S3 and deploy to staging environment
build-deploy:
Expand Down Expand Up @@ -108,20 +108,3 @@ jobs:
- name: Invalidate cloudfront distribution
id: invalidate-cloudfront
run: aws cloudfront create-invalidation --distribution-id ${{ secrets.cloudfront-distribution-id }} --paths /${{ secrets.app-id }}/${{env.VERSION}}/*

test:
name: Test
needs: build-deploy
# The type of runner that the job will run on
runs-on: ubuntu-latest
steps:
# Check-out repository under $GITHUB_WORKSPACE, so the job can access it
- name: Check out code
uses: actions/checkout@v2
with:
ref: ${{ inputs.tag }}

# This step runs a single command to execute integation testing
- name: Test
run: |
echo "This is the integrations test step"
19 changes: 1 addition & 18 deletions .github/workflows/cdelivery-s3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ env:
# Allows to increase Node's max heap size
NODE_OPTIONS: '--max_old_space_size=8192'

# This workflow is made up of two jobs that run sequentially, called build-deploy and test
# This workflow is made up of one job called build-deploy
jobs:
# Build, sync with S3 and deploy to staging environment
build-deploy:
Expand Down Expand Up @@ -138,20 +138,3 @@ jobs:
- name: Invalidate cloudfront distribution
id: invalidate-cloudfront
run: aws cloudfront create-invalidation --distribution-id ${{ secrets.cloudfront-distribution-id }} --paths "/*"

test:
name: Test
needs: build-deploy
# The type of runner that the job will run on
runs-on: ubuntu-latest
steps:
# Check-out repository under $GITHUB_WORKSPACE, so the job can access it
- name: Check out code
uses: actions/checkout@v2
with:
ref: ${{ inputs.tag }}

# This step runs a single command to execute integation testing
- name: Test
run: |
echo "This is the integration test step"
184 changes: 142 additions & 42 deletions .github/workflows/cintegration-ecs-backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ on:
websockets-plugin:
required: true
type: string
test-execution:
required: false
type: string
default: 'true'
# Define secrets which can be passed from the caller workflow
secrets:
# AWS credentials and variables
Expand Down Expand Up @@ -175,6 +179,19 @@ on:
required: true
thumbnails-path-prefix:
required: true
mock-secure-session-secret-key:
required: true
mock-jwt-secret:
required: true
mock-refresh-token-jwt-secret:
required: true
mock-auth-token-jwt-secret:
required: true

# Saving computation time by stopping obsolete workflows
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true

# Set environment variables that are available to the steps of all jobs in the workflow
env:
Expand All @@ -184,32 +201,140 @@ env:
# Allows to increase Node's max heap size
NODE_OPTIONS: '--max_old_space_size=8192'

# This workflow is made up of three jobs that run sequentially, called test, build and deploy
# This workflow is made up of three jobs that run sequentially, called build, test, and deploy
jobs:
# Build image and cache dist directory
build:
name: Build
runs-on: ubuntu-latest

steps:
# Check-out repository under $GITHUB_WORKSPACE, so the job can access it
- name: Check out code
uses: actions/checkout@v3

# Download and cache distribution of the requested Node.js version, and add it to the PATH
- name: Setup node
id: setup-node
uses: actions/setup-node@v3
with:
node-version: 16.x

# Get the yarn cache path.
- name: Get yarn cache directory
id: yarn-cache-dir-path
run: |
echo "::set-output name=dir::$(yarn config get cacheFolder)"

# Cache dependencies to speed up workflow. Only for development branches
# path: The file path on the runner to cache or restore.
# key: Create cache key using the hashFiles function to create a new cache when dependencies change.
# restore-keys: An ordered list of alternative keys to use for finding the cache if no cache hit occurred for key
- name: Cache dependencies
id: cache-yarn
uses: actions/cache@v3
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-

# Install dependencies
- name: Install dependencies and build
run: yarn add --cached

# Build image
- name: Yarn build
run: yarn build --if-present

# Cache build to share it between jobs
# path: The file path on the runner to cache or restore.
# key: Create cache key using the branch and run_id to create a new build for every run.
- name: Cache build
id: cache-build
uses: actions/cache@v3
with:
path: dist
key: ${{ runner.os }}-build-${{ github.ref_name }}-${{ github.run_id }}

test:
name: Test
needs: build
# This job is executed only when the user manually selects this option. If not, the code will be deployed without testing.
if: ${{ (inputs.test-execution == 'true') || (github.event_name == 'push') }}
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Check-out repository under $GITHUB_WORKSPACE, so the job can access it
- name: Check out code
uses: actions/checkout@v2
uses: actions/checkout@v3

# This step runs a single command to execute unitary testing
- name: Test job
# Download and cache distribution of the requested Node.js version, and add it to the PATH
- name: Setup node
id: setup-node
uses: actions/setup-node@v3
with:
node-version: 16.x

# Get the yarn cache path.
- name: Get yarn cache directory
id: yarn-cache-dir-path
run: |
echo "This is the test job"
echo "::set-output name=dir::$(yarn config get cacheFolder)"

# Build image and push to ECR
build:
needs: test
name: Build
# Cache dependencies to speed up workflow. Only for development branches
# path: The file path on the runner to cache or restore.
# key: Create cache key using the hashFiles function to create a new cache when dependencies change.
# restore-keys: An ordered list of alternative keys to use for finding the cache if no cache hit occurred for key
- name: Cache dependencies
id: cache-yarn
uses: actions/cache@v3
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-

# Cache build to re-use it from previous jobs
- name: Cache build
id: cache-build
uses: actions/cache@v3
with:
path: dist
key: ${{ runner.os }}-build-${{ github.ref_name }}-${{ github.run_id }}

# Install dependencies
- name: Install dependencies and build
run: yarn add --cached

- name: yarn test
run:
yarn test
env:
CI: true
# random keys
SECURE_SESSION_SECRET_KEY: ${{ secrets.mock-secure-session-secret-key }}
JWT_SECRET: ${{ secrets.mock-jwt-secret }}
REFRESH_TOKEN_JWT_SECRET: ${{ secrets.mock-refresh-token-jwt-secret }}
AUTH_TOKEN_JWT_SECRET: ${{ secrets.mock-auth-token-jwt-secret }}
STRIPE_SECRET_KEY: ${{ secrets.stripe-secret-key }}
STRIPE_DEFAULT_PLAN_PRICE_ID: ${{ secrets.stripe-default-plan-price-id }}
FILE_STORAGE_ROOT_PATH: /
H5P_PATH_PREFIX: h5p
SAVE_ACTIONS: true
BUILDER_CLIENT_HOST: 'http://localhost:3111'
PLAYER_CLIENT_HOST: 'http://localhost:3112'
EXPLORER_CLIENT_HOST: 'http://localhost:3113'

# Deploy to dev environment
deploy:
name: Deploy
needs: [build, test]
# This job is executed only when the build job has been successful and either the user has manually dispatched the workflow or it is a push to the default branch (master).
if: ${{ always() && needs.build.result == 'success' && ((github.event_name == 'workflow_dispatch') || (github.ref_name == 'master')) }}
runs-on: ubuntu-latest
# Define job output that is available to all downstream jobs that depend on this job
outputs:
tag: ${{ steps.tag-number.outputs.tag }}

steps:
# Check-out repository under $GITHUB_WORKSPACE, so the job can access it
Expand All @@ -222,8 +347,7 @@ jobs:
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}

# Configure AWS credential and region environment variables for use in next steps
- name: Configure AWS Credentials
id: configure-aws
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.aws-access-key-id }}
Expand All @@ -232,51 +356,27 @@ jobs:

# Log in the local Docker client
- name: Login to Amazon ECR
id: login-ecr-build
id: login-ecr-deploy
uses: aws-actions/amazon-ecr-login@v1

# Build and tag the docker image
- name: Build, tag and push image to AWS ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr-build.outputs.registry }}
ECR_REGISTRY: ${{ steps.login-ecr-deploy.outputs.registry }}
IMAGE_TAG: ${{ steps.tag-number.outputs.tag }}
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f .stagingcontainer/Dockerfile .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG

# Deploy to dev environment
deploy:
needs: build
name: Deploy
runs-on: ubuntu-latest

steps:
# Check-out repository under $GITHUB_WORKSPACE, so the job can access it
- name: Check out code
uses: actions/checkout@v2

# Configure AWS credential and region environment variables for use in next steps
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.aws-access-key-id }}
aws-secret-access-key: ${{ secrets.aws-secret-access-key }}
aws-region: ${{ secrets.aws-region }}

# Log in the local Docker client
- name: Login to Amazon ECR
id: login-ecr-deploy
uses: aws-actions/amazon-ecr-login@v1

# Insert a container image URI into template Amazon ECS task definition JSON file, creating a new task definition file.
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def-1
uses: aws-actions/amazon-ecs-render-task-definition@v1
# Set environment variables required to create the task definition file. These are only available to this step
env:
ECR_REGISTRY: ${{ steps.login-ecr-deploy.outputs.registry }}
IMAGE_TAG: ${{ needs.build.outputs.tag }}
IMAGE_TAG: ${{ steps.tag-number.outputs.tag }}
with:
task-definition: ${{ inputs.ecs-task-definition }}
container-name: ${{ secrets.container-name-graasp }}
Expand Down
Loading