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

Web CI and CD Workflow Pipelines #9

Merged
merged 49 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
b1a4651
- Trigger Web CI when PR is created targeting master branch
Aug 16, 2024
7735e12
- Added comments for WEB CI
Aug 17, 2024
ea5ec50
Changed path of API CI
Aug 17, 2024
188cac5
Renamed to build-web and build-api
Aug 17, 2024
840aa16
Initial changes for building web images
Aug 21, 2024
004191f
web yml file cleanup
Aug 21, 2024
c4bb31b
Changed working dir when building docker image
Aug 21, 2024
1c74dbe
Added Dockerfile.node in Web
Aug 21, 2024
436d847
Removed npm-force-resolutions and add permissions to /tmp/app/dist/
Aug 21, 2024
74f8fdb
Changed permissions to /opt/app-root/src
Aug 21, 2024
18411ef
Update permission trial and error
Aug 21, 2024
8d9ff76
Changed to root user
Aug 21, 2024
b502e7e
Push image to jasper gchr and pass to deploy2dev step
Aug 21, 2024
1cb9c37
Separate push to another step
Aug 21, 2024
5229a06
Move login to GCHR before docker tag
Aug 21, 2024
d392326
Adding logs for debugging
Aug 21, 2024
6ce6547
Rename image name
Aug 21, 2024
8278c22
Fixed run command to us |
Aug 21, 2024
ec557ba
Changed deprecated code to new implementation
Aug 21, 2024
52fd49c
Use $image_digest
Aug 21, 2024
f3d3b89
Rename WF back to App (Vue)
Aug 21, 2024
6db5ae2
- Separate building web artifacts to make it reusable
Aug 22, 2024
9bed2e0
Tweaks to missing variable references
Aug 22, 2024
d37060d
Pass correct parameter
Aug 22, 2024
4f3418f
- Fixes to use inputs rather than env
Aug 22, 2024
cbc7559
Fixed indention
Aug 22, 2024
cc68430
Moved node setup
Aug 22, 2024
cd855d1
Revert code
Aug 22, 2024
0429801
Fixed path
Aug 22, 2024
93a6f48
Pass the vars variable to composite action
Aug 22, 2024
4b94891
- Renamed jasper-web to web
Aug 22, 2024
e2c0547
Added shell: bash
Aug 22, 2024
1b086a3
display aws_account
Aug 22, 2024
440220b
Removed env variable
Aug 22, 2024
5d5b53e
Fixed github_image_repo error
Aug 22, 2024
6c8144d
Added id-token: write
Aug 22, 2024
e350a7d
Add Deploy to TEST and PROD
Aug 22, 2024
3e5badf
- Added Web CI Workflow
Aug 22, 2024
66432c5
Revert changes to API
Aug 22, 2024
3552bfa
Merge branch 'master' into feature-web-ci
Aug 27, 2024
0c0aef6
- Moved web Dockerfile to /docker/web.
Aug 27, 2024
d3c7164
Renamed to app-vue so it can be tested on feature branch
Aug 27, 2024
75a9e72
Moved --build-arg position to the front
Aug 27, 2024
ea39c19
Add major and minor node version.
Aug 27, 2024
5b4c038
Revert code changes in devcontainer.json
Aug 27, 2024
53f21db
Add ls to see all files
Aug 27, 2024
54f10c9
Changed source file location
Aug 27, 2024
b2c193f
Run npm install as root user
Aug 27, 2024
94ef6a9
Rename back to publish-web.yml
Aug 27, 2024
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
38 changes: 38 additions & 0 deletions .github/workflows/actions/build-web/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Build Web
description: Builds the Web codebase

inputs:
working_directory:
description: The working directory where the code will be built.
required: true
node_version:
description: The node version that will be used.
required: true

runs:
using: composite

steps:
- name: Use Node.js ${{ inputs.node_version }}
uses: actions/setup-node@v1
with:
node-version: ${{ inputs.node_version }}

- run: npm ci
shell: bash
working-directory: ${{ inputs.working_directory }}

# Lint errors exists from SCC and will be worked on separately.
- run: npm run lint
shell: bash
working-directory: ${{ inputs.working_directory }}
continue-on-error: true

- run: npm run build
shell: bash
working-directory: ${{ inputs.working_directory }}

# Unit test is not configured in SCC and will be worked on separately.
- run: npm run test --if-present
shell: bash
working-directory: ${{ inputs.working_directory }}
64 changes: 64 additions & 0 deletions .github/workflows/actions/deploy-to-aws/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Deploy to AWS
description: Deploy image to AWS Instance

inputs:
environment:
description: The environment to which the image will be deployed.
required: true
aws_account:
description: The AWS Account ID.
required: true
region:
description: The AWS Region of the AWS Account.
required: true
app_name:
description: The application name.
required: true
aws_role_arn:
description: The AWS Role ARN to assume.
required: true

# Image parameters
ghcr_token:
description: The token to use to login to the GHCR.
required: true
github_image_repo:
description: The GCHR repo where images are stored.
required: true
image_name:
description: The name of the image to be deployed.
required: true
image_digest:
description: The digest of the image to be deployed. Identifies the unique image tag in the GHCR.
required: true

runs:
using: composite
steps:
- name: Log in to the GHCR
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ inputs.ghcr_token }}

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-skip-session-tagging: true
aws-region: ${{ inputs.region }}
role-to-assume: ${{ inputs.aws_role_arn }}
role-duration-seconds: 1800
role-session-name: ci-deployment

- name: Login to AWS CLI
shell: bash
run: |
aws ecr get-login-password --region ${{ inputs.region }} | docker login --username AWS --password-stdin ${{ inputs.aws_account }}.dkr.ecr.${{ inputs.region }}.amazonaws.com/${{ inputs.app_name }}-ecr-repo-${{ inputs.environment }}

- name: Tag the image in the GHCR as ${{ inputs.environment }}
shell: bash
run: |
docker pull ${{ inputs.github_image_repo }}${{ inputs.image_name }}@${{ inputs.image_digest }}
docker tag ${{ inputs.github_image_repo }}${{ inputs.image_name }}@${{ inputs.image_digest }} ${{ inputs.aws_account }}.dkr.ecr.${{ inputs.region }}.amazonaws.com/${{ inputs.app_name }}-ecr-repo-${{ inputs.environment }}:${{ inputs.image_name }}
docker push ${{ inputs.aws_account }}.dkr.ecr.${{ inputs.region }}.amazonaws.com/${{ inputs.app_name }}-ecr-repo-${{ inputs.environment }}:${{ inputs.image_name }}
30 changes: 0 additions & 30 deletions .github/workflows/app-vue.yml

This file was deleted.

30 changes: 30 additions & 0 deletions .github/workflows/build-and-test-web.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Build and Test Web

on:
pull_request:
branches:
- master
paths:
- "web/**"

workflow_dispatch:

env:
WORKING_DIRECTORY: ./web

jobs:
build-and-test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [12.x]
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Building Web codebase
uses: ./.github/workflows/actions/build-web
with:
working_directory: ${{ env.WORKING_DIRECTORY }}
node_version: ${{ matrix.node-version }}
153 changes: 153 additions & 0 deletions .github/workflows/publish-web.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
name: Deploy Web

on:
push:
branches:
- master
paths:
- "web/**"

workflow_dispatch:

env:
WORKING_DIRECTORY: ./web
IMAGE_NAME: web
GITHUB_IMAGE_REPO: ghcr.io/bcgov/jasper/
WEB_BASE_HREF: /

jobs:
build:
name: Build, Create and Push Image
runs-on: ubuntu-latest
outputs:
image_digest: ${{ steps.docker_push.outputs.digest }}

strategy:
matrix:
node-major-version: [12]
node-minor-version: [x]

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Building Web codebase
uses: ./.github/workflows/actions/build-web
with:
working_directory: ${{ env.WORKING_DIRECTORY }}
node_version: ${{ matrix.node-major-version }}.${{ matrix.node-minor-version }}

- name: Log in to the GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Get short SHA
id: short_sha
run: |
echo "::set-output name=SHORT_SHA::$(git rev-parse --short HEAD)"
echo "Short SHA: $SHORT_SHA"

- name: Build Docker Image
working-directory: ${{env.WORKING_DIRECTORY}}/../
run: |
docker build --tag web-runtime -f docker/nginx-runtime/Dockerfile ./docker/nginx-runtime/
docker build --tag web-artifacts --build-arg node_version=${{ matrix.node-major-version }} --build-arg WEB_BASE_HREF=${{ env.WEB_BASE_HREF }} -f docker/web/Dockerfile .
docker build --tag ${{ env.IMAGE_NAME }} -f docker/vue-on-nginx/Dockerfile ./docker/vue-on-nginx/
docker tag ${{ env.IMAGE_NAME }} ${{ env.GITHUB_IMAGE_REPO }}${{ env.IMAGE_NAME }}:${{ steps.short_sha.outputs.SHORT_SHA }}

- name: Push Image to GCHR
id: docker_push
run: |
output=$(docker push ${{ env.GITHUB_IMAGE_REPO }}${{ env.IMAGE_NAME }}:${{ steps.short_sha.outputs.SHORT_SHA }})
echo $output
digest=$(echo "$output" | grep "digest: sha256" | awk '{ print $3 }')
echo "digest=$digest" >> $GITHUB_OUTPUT

deploy2dev:
name: Deploy to DEV
needs: build
env:
ENVIRONMENT: dev
permissions:
id-token: write
packages: write
runs-on: ubuntu-latest
environment: dev

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Deploy to ${{ env.ENVIRONMENT }}
uses: ./.github/workflows/actions/deploy-to-aws
with:
environment: ${{ env.ENVIRONMENT }}
aws_account: ${{ vars.AWS_ACCOUNT }}
region: ${{ vars.AWS_REGION }}
app_name: ${{ vars.APP_NAME }}
aws_role_arn: ${{ vars.AWS_ROLE_ARN }}
ghcr_token: ${{ secrets.GITHUB_TOKEN }}
github_image_repo: ${{ env.GITHUB_IMAGE_REPO }}
image_name: ${{ env.IMAGE_NAME }}
image_digest: ${{ needs.build.outputs.image_digest }}

deploy2test:
name: Deploy to TEST
needs: [build, deploy2dev]
env:
ENVIRONMENT: test
permissions:
id-token: write
packages: write
runs-on: ubuntu-latest
environment: test

steps:
- name: Checkout
uses: actions/checkout@v4

# Uncomment when infra in AWS in TEST environment has been configured
# - name: Deploy to ${{ env.ENVIRONMENT }}
# uses: ./.github/workflows/actions/deploy-to-aws
# with:
# environment: ${{ env.ENVIRONMENT }}
# aws_account: ${{ vars.AWS_ACCOUNT }}
# region: ${{ vars.AWS_REGION }}
# app_name: ${{ vars.APP_NAME }}
# aws_role_arn: ${{ vars.AWS_ROLE_ARN }}
# ghcr_token: ${{ secrets.GITHUB_TOKEN }}
# github_image_repo: ${{ env.GITHUB_IMAGE_REPO }}
# image_name: ${{ env.IMAGE_NAME }}
# image_digest: ${{ needs.build.outputs.image_digest }}

deploy2prod:
name: Deploy to PROD
needs: [build, deploy2dev, deploy2test]
env:
ENVIRONMENT: prod
permissions:
id-token: write
packages: write
runs-on: ubuntu-latest
environment: prod

steps:
- name: Checkout
uses: actions/checkout@v4

# Uncomment when infra in AWS in PROD environment has been configured
# - name: Deploy to ${{ env.ENVIRONMENT }}
# uses: ./.github/workflows/actions/deploy-to-aws
# with:
# environment: ${{ env.ENVIRONMENT }}
# aws_account: ${{ vars.AWS_ACCOUNT }}
# region: ${{ vars.AWS_REGION }}
# app_name: ${{ vars.APP_NAME }}
# aws_role_arn: ${{ vars.AWS_ROLE_ARN }}
# ghcr_token: ${{ secrets.GITHUB_TOKEN }}
# github_image_repo: ${{ env.GITHUB_IMAGE_REPO }}
# image_name: ${{ env.IMAGE_NAME }}
# image_digest: ${{ needs.build.outputs.image_digest }}
1 change: 1 addition & 0 deletions docker/vue-on-nginx/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ COPY ./s2i/bin/fix-base-url /usr/libexec/s2i/fix-base-url
# Fix permissions.
USER root
RUN chmod 674 /usr/libexec/s2i/fix-base-url
RUN chmod -R 674 /tmp/app/dist/

# From nginx-runtime.
USER 104
Expand Down
12 changes: 12 additions & 0 deletions docker/web/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
ARG node_version=10
ARG WEB_BASE_HREF=/
FROM centos/nodejs-${node_version}-centos7:${node_version}
ENV WEB_BASE_HREF=${WEB_BASE_HREF}
ENV WEB1_BASE_HREF=${WEB_BASE_HREF}
WORKDIR /opt/app-root/src
COPY ../../web .
RUN echo "$WEB1_BASE_HREF"
RUN echo "$WEB_BASE_HREF"
USER root
RUN npm install
RUN npm run build
1 change: 0 additions & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"version": "0.1.0",
"private": true,
"scripts": {
"preinstall": "npx npm-force-resolutions",
"serve": "cross-env WEB_BASE_HREF='/' vue-cli-service serve",
"build": "vue-cli-service build",
"clean": "",
Expand Down
Loading