Skip to content

Commit

Permalink
feat(common): Introduced common library for all sub-services (#4)
Browse files Browse the repository at this point in the history
* initial common

* Build common

* Renamed to build-js

* Renamed

* include chai

* Use chai

* Finalized tests

* Move xo to root

* Actually remove xo from projects

* Allow anonymous exports

* xo format

* Test error handler

* Test RootError

* Install xo

* Do xo validations across projects

* Find each tar and untar

* Moved integration testing to the root

* Removed

* Moved to int-test

* Integartion tests

* Change it up

* zine-generator

* Do integration testing

* Build docker

* Build with working directory

* Added NotFoundError

* Cleaned up package

* Removed int-test

* Fixed integration test dockerfile

* Remove node_modules from xo

* XO ignore current dir

* Move end-to-end to test

* Include common

* Removed int-test from zine-generator

* Fixed packaging

* Build common package

* RouteNotFoundError

* Use different exports

* use common error handler

* Use common error handler

* Fix ignores

* Fixed XO

* Don't fail if file can't be found

* Fixed imports

* Include correct dir

* Mispelled parameters

* Debug

* Try persisting different path

* Avoid failure

* Use folder

* Install common before doing your own

* Include common for template

* Do common

* Include common

* Try different way

* Build common image

* common dockerfile

* Docker build from common

* Use common docker

* Load common image

* Build common docker

* Depend on buildjs

* Use common image build arg

* Accidental remove

* Integration tests

* removed error-handler as its common now

* Only include common

* Build template as well

* Use root dir

* Ignore all subfolder c8/mocha

* Use matrix for deploy env

* Fixed config

* Do integration testing even for main

* Add test results

* Clean up lcov files

* Fixed multiline

* Include JUnit reporter

* Exec

* Debugging sonar

* removed template from build

* Prod separate

* Remove pack

* Don't ignore

* Dependabot changes for common

* Use dev-deps

* deps-dev

* Fixed dependabot [ci skip]
  • Loading branch information
superflyxxi authored Oct 31, 2021
1 parent d9df1ce commit 9e06b4d
Show file tree
Hide file tree
Showing 42 changed files with 24,627 additions and 30,340 deletions.
File renamed without changes.
137 changes: 85 additions & 52 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ commands:
sshpass -e ssh ${SSH_USER}@${SSH_SERVER} -p ${SSH_PORT} "${SSH_DOCKER_COMPOSE_REMOTE_DIR}/<< parameters.command >>"
jobs:
unit-test:
build-js:
resource_class: small
executor:
name: node/default
Expand All @@ -55,37 +55,49 @@ jobs:
description: The sub-project to work on.
type: string
steps:
- attach_workspace:
at: /tmp/workspace
- checkout
- node/install-packages:
app-dir: ./<< parameters.project >>
- run:
name: install packages
command: |
cd common
npm ci
cd ../<< parameters.project >>
npm ci
- run:
name: Unit Tests
working_directory: ./<< parameters.project >>
environment:
MOCHA_FILE: ./mocha/test-results.xml
MOCHA_FILE: ./test-results.xml
MOCHA_ARGS: --forbid-pending --forbid-only --reporter mocha-junit-reporter
command: |
cp -v ../template/.c8rc.json ../template/.mocharc.json ./
cp -v ../.c8rc.json ../.mocharc.json ./
npm test
- run:
name: Tar coverage
command: tar -vcf << parameters.project >>-coverage.tar << parameters.project >>/coverage/
- store_test_results:
path: ./<< parameters.project >>/mocha
- store_artifacts:
path: ./<< parameters.project >>/mocha/test-results.xml
path: ./<< parameters.project >>/test-results.xml
- store_artifacts:
path: ./<< parameters.project >>/coverage/
- persist_to_workspace:
root: ./
paths:
- ./*coverage.tar*

validate-format:
resource_class: small
executor:
name: node/default
tag: '16.5.0'
steps:
- checkout
- node/install-packages
- run:
name: Verify XO
working_directory: ./<< parameters.project >>
command: |
cp -v ../template/.prettierrc.json ../template/.xo-config.json ./
npm run xo-verify
find . -mindepth 1 -maxdepth 1 -type d | grep -v "\./\..*" | grep -v "\./node_modules" | xargs npm run xo --
sonar-scan:
executor:
Expand All @@ -98,7 +110,16 @@ jobs:
- run:
name: Untar coverage
command: |
tar -vxf ./*coverage.tar*
find ./ -maxdepth 1 -name '*coverage.tar*' -exec tar -vxf {} \;
- run:
name: Clean up Coverage
command: |
echo "Showing directories first"
find . -maxdepth 2 -name coverage -type d
echo "now running"
set -x
find . -maxdepth 2 -name coverage -type d | sed 's#\(.*\)/coverage#\1#g' | xargs -L1 -I{} sed -i 's#SF:#SF:{}/#g' {}/coverage/lcov.info
find . -name lcov.info -exec cat {} \;
- run:
name: Configure sonar-project.properties
command: |
Expand All @@ -117,6 +138,13 @@ jobs:
steps:
- attach_workspace:
at: /tmp/workspace
- run:
name: Load docker images
command: |
ls /tmp/workspace
if [[ -f /tmp/workspace/common-image.tar ]]; then
docker load -i /tmp/workspace/common-image.tar
fi
- docker/check:
registry: ${DOCKER_REGISTRY}
- export-primary-docker-tag
Expand Down Expand Up @@ -145,6 +173,9 @@ jobs:
done
export DOCKER_TAGS="${DOCKER_TAGS},main,latest"
fi
if [[ "common" != "<< parameters.project >>" ]]; then
echo "export COMMON_IMAGE=${DOCKER_REGISTRY}/${CIRCLE_PROJECT_REPONAME}/common:${PRIMARY_DOCKER_TAG}" >> ${BASH_ENV}
fi
echo "export DOCKER_TAGS=${DOCKER_TAGS}" >> ${BASH_ENV}
echo "export CACHE_FROM_IMAGES=${CACHE_FROM_IMAGES}" >> ${BASH_ENV}
cat ${BASH_ENV}
Expand All @@ -156,6 +187,7 @@ jobs:
registry: ${DOCKER_REGISTRY}
tag: ${DOCKER_TAGS}
cache_from: ${CACHE_FROM_IMAGES}
extra_build_args: --build-arg COMMON_IMAGE=${COMMON_IMAGE}
- docker/push:
step-name: Push application docker image
image: ${CIRCLE_PROJECT_REPONAME}/<< parameters.project >>
Expand Down Expand Up @@ -186,10 +218,10 @@ jobs:
- when:
condition: << parameters.prerelease >>
steps:
run:
name: Define additional args
command: |
echo "export ADDITIONAL_ARGS=--dry-run" >> ${BASH_ENV}
- run:
name: Define additional args
command: |
echo "export ADDITIONAL_ARGS=--dry-run" >> ${BASH_ENV}
- run:
name: Run semantic-release
command: |
Expand All @@ -208,6 +240,7 @@ jobs:
- short_version.txt

deploy:
executor: docker/machine
parameters:
project:
description: The sub-project to work on.
Expand All @@ -217,8 +250,6 @@ jobs:
type: enum
default: "wip"
enum: ["wip", "prod"]
machine:
enabled: true
steps:
- attach_workspace:
at: /tmp/workspace
Expand All @@ -243,37 +274,31 @@ jobs:

integration-test:
executor: docker/machine
parameters:
project:
description: The sub-project to work on.
type: string
steps:
- attach_workspace:
at: /tmp/workspace
- export-primary-docker-tag
- run:
name: Load docker image
command: docker load -i /tmp/workspace/<< parameters.project >>-image.tar
name: Load docker images
command: |
find /tmp/workspace -name '*-image.tar' -exec docker load -i {} \;
- checkout
- docker/build:
step-name: Build integration testing docker image
docker-context: ./<< parameters.project >>
path: ./<< parameters.project >>
image: ${CIRCLE_PROJECT_REPONAME}/<< parameters.project >>
docker-context: ./int-test
path: ./int-test
image: ${CIRCLE_PROJECT_REPONAME}/int-test
registry: ${DOCKER_REGISTRY}
tag: inttest-${PRIMARY_DOCKER_TAG}
dockerfile: int-test/Dockerfile
extra_build_args: --build-arg FROM_IMAGE=${DOCKER_REGISTRY}/${CIRCLE_PROJECT_REPONAME}/<< parameters.project >>:${PRIMARY_DOCKER_TAG}
tag: ${PRIMARY_DOCKER_TAG}
- docker/check:
registry: ${DOCKER_REGISTRY}
- docker/push:
step-name: Push integration testing docker image
image: ${CIRCLE_PROJECT_REPONAME}/<< parameters.project >>
image: ${CIRCLE_PROJECT_REPONAME}/int-test
registry: ${DOCKER_REGISTRY}
tag: inttest-${PRIMARY_DOCKER_TAG}
tag: ${PRIMARY_DOCKER_TAG}
- run:
name: Generate docker-compose file
working_directory: ./<< parameters.project >>
command: |
cat int-test/docker-compose.yml |\
sed "s#\${DOCKER_REGISTRY}#${DOCKER_REGISTRY}#g" |\
Expand All @@ -282,7 +307,6 @@ jobs:
cat docker-compose.ci-test.yml
- run:
name: Bring up
working_directory: ./<< parameters.project >>
command: |
docker-compose -f docker-compose.ci-test.yml up --abort-on-container-exit --exit-code-from test
Expand All @@ -293,27 +317,44 @@ workflows:
name: pre-release
context: default
prerelease: true
- unit-test:
- build-js:
context: default
name: build-js-common
project: common
- build-js:
context: default
requires:
- build-js-common
matrix:
parameters:
project: ["zine-generator"]
- validate-format:
context: default
- sonar-scan:
context: default
requires:
- unit-test
- build-js
- docker/hadolint:
name: validate-dockerfiles
context: default
dockerfiles: "template/Dockerfile"
dockerfiles: "common/Dockerfile:zine-generator/Dockerfile:template/Dockerfile"
- build-docker:
context: default
project: common
name: build-docker-common
requires:
- pre-release
- build-js-common
- build-docker:
context: default
matrix:
parameters:
project: ["zine-generator"]
requires:
- validate-dockerfiles
- unit-test
- build-js
- build-docker-common
- validate-format
- pre-release
- release:
prerelease: false
Expand All @@ -324,36 +365,28 @@ workflows:
branches:
only:
- main
- deploy:
- integration-test:
context: default
name: deploy-wip
env: wip
matrix:
parameters:
project: ["zine-generator"]
requires:
- build-docker
- deploy:
context: default
name: deploy-prod
env: prod
matrix:
parameters:
project: ["zine-generator"]
env: ["wip"]
requires:
- build-docker
filters:
branches:
only:
- main
- integration-test:
- deploy:
context: default
matrix:
parameters:
project: ["zine-generator"]
env: ["prod"]
requires:
- build-docker
- integration-test
filters:
branches:
ignore:
only:
- main
29 changes: 24 additions & 5 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ updates:
schedule:
interval: "monthly"
commit-message:
prefix-development: "fix(template): "
prefix: "fix(ci): "
prefix-development: "fix(ci): "
reviewers:
- superflyxxi
- package-ecosystem: "npm"
Expand All @@ -15,7 +16,7 @@ updates:
interval: "monthly"
commit-message:
prefix: "fix(zine-generator): "
prefix-development: "fix(zine-generator): "
prefix-development: "fix(deps-dev): "
reviewers:
- superflyxxi
- package-ecosystem: "docker"
Expand All @@ -24,7 +25,25 @@ updates:
interval: "monthly"
commit-message:
prefix: "fix(zine-generator): "
prefix-development: "fix(zine-generator): "
prefix-development: "fix(deps-dev): "
reviewers:
- superflyxxi
- package-ecosystem: "npm"
directory: "/common"
schedule:
interval: "monthly"
commit-message:
prefix: "fix(common): "
prefix-development: "fix(deps-dev): "
reviewers:
- superflyxxi
- package-ecosystem: "docker"
directory: "/common"
schedule:
interval: "monthly"
commit-message:
prefix: "fix(common): "
prefix-development: "fix(deps-dev): "
reviewers:
- superflyxxi
- package-ecosystem: "npm"
Expand All @@ -33,7 +52,7 @@ updates:
interval: "monthly"
commit-message:
prefix: "fix(template): "
prefix-development: "fix(template): "
prefix-development: "fix(deps-dev): "
reviewers:
- superflyxxi
- package-ecosystem: "docker"
Expand All @@ -42,6 +61,6 @@ updates:
interval: "monthly"
commit-message:
prefix: "fix(template): "
prefix-development: "fix(template): "
prefix-development: "fix(deps-dev): "
reviewers:
- superflyxxi
9 changes: 2 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
**/.c8rc.json
!template/.c8rc.json
!/.c8rc.json
**/.mocharc.json
!template/.mocharc.json
**/.xo-config.json
!template/.xo-config.json
**/.prettierrc.json
!template/.prettierrc.json

!/.mocharc.json

# Standard Stuff Below

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions common/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM node:16.10.0-alpine3.11
LABEL org.opencontainers.image.authors="SuperFlyXXI <superflyxxi@yahoo.com>"
ENV NODE_ENV=production
WORKDIR /app
ENTRYPOINT ["npm"]
CMD ["start"]
COPY ./ /common/
RUN cd /common && npm install
Loading

0 comments on commit 9e06b4d

Please sign in to comment.