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

[TC-0066] (pt2) pipeline config for running tests #13

Closed
wants to merge 2 commits into from
Closed
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
24 changes: 12 additions & 12 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
#######################
# LOCAL DEVELOPMENT !!!
#######################
###################
# LOCAL DEVELOPMENT
###################


# Local DB
DB_HOST=db
DB_NAME=tc
DB_USER=tc_user
DB_PASSWORD=tc_password
DB_TYPE=postgres
DB_PORT=5432

POSTGRES_HOST=localhost
POSTGRES_PORT=5432

# Local backend
API_VERSION=0.0.1
API_PORT=8081
DB_HOST=db

# Local keycloak

KEYCLOAK_ADMIN=admin
KEYCLOAK_PASSWORD=password
KEYCLOAK_PORT=8080
KEYCLOAK_REALM=local
KEYCLOAK_CLIENT=local-client
KEYCLOAK_REDIRECT=http://localhost:3050
KEYCLOAK_AUTH_SERVER=http://localhost:8080

# Local frontend
REACT_APP_SSO_REDIRECT_URI=http://localhost:3050
REACT_APP_SSO_AUTH_SERVER_URL=http://localhost:8080
REACT_APP_SSO_REALM=local
REACT_APP_SSO_CLIENT_ID=local-client
REACT_APP_URL=http://localhost:3050
REACT_APP_PORT=3000

ENV=local
TARGET=dev
3 changes: 3 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[TC-0000](https://bcdevex.atlassian.net/browse/TC-0000)

Objective:
30 changes: 30 additions & 0 deletions .github/workflows/ci-jira.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Jira issue in PR title

on:
workflow_dispatch:
pull_request:
types:
- opened
- edited
- reopened
- synchronize
- ready_for_review

jobs:
check-pr-title-jira-link:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name:
Check PR title for Jira ticket number unless it is a
CHORE/FIX/REFACTOR/DEVOPS PR
uses: gsactions/commit-message-checker@8c8c0d18ba9b1fcfed6e7385fd2bf357dfc8dccb
with:
pattern: '(\W)+(TC)+-[0-9]+(\W)|(\W)(CHORE|FIX|REFACTOR|DEVOPS)(\W)'
excludeTitle: "false" # optional: this excludes the title of a pull request
excludeDescription: "true" # optional: this excludes the description body of a pull request
checkAllCommitMessages: "false" # optional: this checks all commits associated with a pull request
# accessToken: ${{ secrets.GITHUB_TOKEN }} # github access token is only required if checkAllCommitMessages is true
error:
"PR title should look like [TC-####] or [CHORE] or [FIX] or
[REFACTOR] for general non feature commits"
83 changes: 83 additions & 0 deletions .github/workflows/ci-lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Lint

on:
workflow_dispatch:
pull_request:
types:
- opened
- edited
- reopened
- synchronize
- ready_for_review

jobs:
check_directory:
runs-on: "ubuntu-20.04"
# Declare outputs for next jobs
outputs:
frontend_changed: ${{ steps.check_file_changed.outputs.frontend_changed }}
backend_changed: ${{ steps.check_file_changed.outputs.backend_changed }}
steps:
- uses: actions/checkout@v2
with:
# Checkout as many commits as needed for the diff
fetch-depth: 2
- shell: pwsh
id: check_file_changed
run: |
# Diff HEAD with the previous commit
$diff = git diff --name-only HEAD^ HEAD

# Check if a file under frontend has changed (added, modified, deleted)
$SourceDiff = $diff | Where-Object { $_ -match '^frontend/' }
$HasDiff = $SourceDiff.Length -gt 0

# Set the output named "frontend_changed"
Write-Host "::set-output name=frontend_changed::$HasDiff"

# Check if a file under backend has changed (added, modified, deleted)
$SourceDiff = $diff | Where-Object { $_ -match '^backend/' }
$HasDiff = $SourceDiff.Length -gt 0

# Set the output named "frontend_changed"
Write-Host "::set-output name=backend_changed::$HasDiff"

lint-frontend:
runs-on: ubuntu-latest
needs: [check_directory]
if: needs.check_directory.outputs.frontend_changed == 'True'
timeout-minutes: 5

steps:
- uses: actions/checkout@v3
name: checkout

- uses: actions/setup-node@v3
with:
node-version: 18.x

- name: Install Dependencies
run: cd frontend && npm ci

- name: Lint Check Frontend
run: cd frontend && npm run lint

lint-backend:
runs-on: ubuntu-latest
needs: [check_directory]
if: needs.check_directory.outputs.backend_changed == 'True'
timeout-minutes: 5

steps:
- uses: actions/checkout@v3
name: checkout

- uses: actions/setup-node@v3
with:
node-version: 18.x

- name: Install Dependencies
run: cd backend && npm ci

- name: Lint Check Backend
run: cd backend && npm run lint
40 changes: 40 additions & 0 deletions .github/workflows/ci-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Tests pipeline

on:
workflow_dispatch:
pull_request:

jobs:
run-tests:
runs-on: ubuntu-latest
timeout-minutes: 20

steps:
- name: checkout
uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version: 20.x

- name: Setup ENV file
run: cp .env.example .env

- name: Install Backend Dependencies
run: cd backend && npm ci

- name: Install Frontend Dependencies
run: cd frontend && npm ci

- name: Run Docker containers
run: make build-test

- name: Run Tests
run: make test-backend-pipeline

- name: Run Tests
run: make test-frontend-pipeline

- name: Stop containers
run: make close
if: ${{ always() }}
40 changes: 15 additions & 25 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,38 @@ export $(sed 's/=.*//' .env)
ENV := $(PWD)/.env
include $(ENV)

export ENV_NAME=dev
# Project
export PROJECT := tc

export CONTAINER_REGISTRY := ""

export APP_VERSION := $(shell cat apps/backend/package.json | jq '.version' -r)
export API_VERSION := $(API_VERSION)

# Git
export COMMIT_SHA:=$(shell git rev-parse --short=7 HEAD)
export LAST_COMMIT_MESSAGE:=$(shell git log -1 --oneline --decorate=full --no-color --format="%h, %cn, %f, %D" | sed 's/->/:/')
export GIT_LOCAL_BRANCH?=$(shell git rev-parse --abbrev-ref HEAD)
export GIT_LOCAL_BRANCH := $(or $(GIT_LOCAL_BRANCH),dev)

build-test:
@echo "+\n++ Make: Running test build ...\n+"
@$(shell echo ./scripts/setenv.sh local ci )
@docker-compose up --force-recreate -d --build

test-backend-pipeline:
@docker exec tc-backend-ci npm run test:pipeline

test-frontend-pipeline:
@docker exec tc-frontend-ci npm run test:pipeline

build-local:
@echo "+\n++ Make: Run/Build locally ...\n+"
@docker-compose up --build -d
@$(shell echo ./scripts/setenv.sh ci local )
@docker-compose up --force-recreate -d --build

run-local:
@echo "+\n++ Make: Running locally ...\n+"
@docker-compose up -d

build-keycloak:
@echo "+\n++ Make: Buidling keycloak ...\n+"
@docker-compose build --no-cache keycloak

build-frontend:
@echo "+\n++ Make: Building frontend ...\n+"
@docker build --platform linux/amd64 -t $(CONTAINER_REGISTRY)/frontend:latest ./frontend

build-backend:
@echo "+\n++ Make: Building backend ...\n+"
@docker build --platform linux/amd64 -t $(CONTAINER_REGISTRY)/backend:latest ./backend

build-nginx:
@echo "+\n++ Make: Building Nginx ...\n+"
@docker build --platform linux/amd64 -t $(CONTAINER_REGISTRY)/nginx:latest ./nginx
@$(shell echo ./scripts/setenv.sh ci local )
@docker-compose up -d

local-frontend-logs:
@docker logs $(PROJECT)-frontend --tail 25 --follow
Expand Down Expand Up @@ -73,10 +67,6 @@ local-frontend-workspace:
local-nginx-workspace:
@docker exec -it $(PROJECT)-nginx sh

close-local:
@echo "+\n++ Make: Close Local ...\n+"
@docker-compose -f docker-compose.yml down -v --remove-orphans

close:
@echo "+\n++ Make: Run/Close ...\n+"
@docker-compose down -v --remove-orphans
Expand Down
37 changes: 18 additions & 19 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3.7"
services:
db:
image: postgres:15-alpine
container_name: ${PROJECT}-db
container_name: ${PROJECT}-db-${ENV}
restart: always
env_file: .env
environment:
Expand All @@ -21,26 +21,25 @@ services:

frontend:
image: ${PROJECT}-frontend:${GIT_LOCAL_BRANCH}
container_name: ${PROJECT}-frontend
container_name: ${PROJECT}-frontend-${ENV}
command: "npm run start"
build:
context: "./frontend"
target: dev
target: ${TARGET}
dockerfile: "Dockerfile.${ENV}"
restart: always
stdin_open: true
env_file: .env
environment:
REACT_APP_SSO_REDIRECT_URI: ${REACT_APP_SSO_REDIRECT_URI}
REACT_APP_SSO_AUTH_SERVER_URL: ${REACT_APP_SSO_AUTH_SERVER_URL}
REACT_APP_SSO_REALM: ${REACT_APP_SSO_REALM}
REACT_APP_SSO_CLIENT_ID: ${REACT_APP_SSO_CLIENT_ID}
REACT_APP_URL: ${REACT_APP_URL}
REACT_APP_SSO_REDIRECT_URI: ${KEYCLOAK_REDIRECT}
REACT_APP_SSO_AUTH_SERVER_URL: ${KEYCLOAK_AUTH_SERVER}
REACT_APP_SSO_REALM: ${KEYCLOAK_REALM}
REACT_APP_SSO_CLIENT_ID: ${KEYCLOAK_CLIENT}
REACT_APP_PORT: ${REACT_APP_PORT}
CHOKIDAR_USEPOLLING: "true"
WATCHPACK_POLLING: "true"
# uncomment if hot reload fails (windows only?)
# WDS_SOCKET_HOST: "127.0.0.1"
ports:
- "3000:3000"
- "3000:3000"
volumes:
- /app/node_modules
- ./frontend:/app
Expand All @@ -50,20 +49,24 @@ services:
networks:
- tc
backend:
container_name: ${PROJECT}-backend
container_name: ${PROJECT}-backend-${ENV}
image: ${PROJECT}-backend:${GIT_LOCAL_BRANCH}
build:
context: "./backend"
target: dev
restart: always
stdin_open: true
command: "npm run start:dev"
env_file: .env
environment:
PORT: ${API_PORT}
DB_PORT: ${DB_PORT}
DB_HOST: ${DB_HOST}
DB_NAME: ${DB_NAME}
DB_USER: ${DB_USER}
KEYCLOAK_REALM: ${KEYCLOAK_REALM}
KEYCLOAK_AUTH_SERVER: ${KEYCLOAK_AUTH_SERVER}
KEYCLOAK_CLIENT: ${KEYCLOAK_CLIENT}
DB_PASSWORD: ${DB_PASSWORD}
CHOKIDAR_USEPOLLING: "true"
ALLOW_EMPTY_PASSWORD: "yes"
Expand All @@ -79,7 +82,7 @@ services:

nginx:
image: ${PROJECT}-nginx:${GIT_LOCAL_BRANCH}
container_name: ${PROJECT}-nginx
container_name: ${PROJECT}-nginx-${ENV}
build:
context: "./nginx"
ports:
Expand All @@ -89,24 +92,20 @@ services:
- frontend
networks:
- tc

keycloak:
container_name: keycloak
container_name: ${PROJECT}-keycloak-${ENV}
build:
context: ./keycloak
command:
- start-dev
- --import-realm
- --hostname-strict=false
- --hostname-strict-https=false
# - --hostname=localhost
# - --proxy=edge
# - --hostname-url=http://localhost:3050
# - --hostname-strict-backchannel=true
platform: linux/arm64/v8
volumes:
- keycloak:/opt/keycloak/data
- ./keycloak/default.json:/opt/keycloak/data/import/default.json
env_file: .env
environment:
KEYCLOAK_IMPORT: /opt/keycloak/data/import/default.json
DB_VENDOR: ${DB_TYPE}
Expand Down
13 changes: 13 additions & 0 deletions frontend/Dockerfile.ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM cypress/base:latest AS dev

WORKDIR /app

ENV PORT 3000

COPY *.json .

RUN npm ci

COPY . .

EXPOSE 3000
File renamed without changes.
Loading
Loading