@ackee/create-node-app 2.0.2 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ackee/create-node-app",
3
- "version": "2.0.2",
3
+ "version": "2.1.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -28,6 +28,7 @@
28
28
  "@istanbuljs/nyc-config-typescript": "^1.0.0",
29
29
  "@types/mocha": "^10.0.0",
30
30
  "@types/node": "^24.0.0",
31
+ "@types/yargs": "^17.0.35",
31
32
  "eslint": "^8.0.0",
32
33
  "eslint-formatter-gitlab": "^5.0.0",
33
34
  "mocha": "^11.0.0",
@@ -1,208 +1,82 @@
1
1
  # Define environments in GitLab UI with vars according to the branches for the pipeline
2
- # ENVIRONMENT={{develpoment/stage/production}}
3
- # GCP_PROJECT_ID={{PROJECT_NAME}}
2
+ # GCP_PROJECT_ID=node-app
4
3
  # GCP_REGION={{europe-west3}}
5
- # GCP_SECRETS_NAME={{PROJECT_NAME}}
4
+ # GCP_SECRETS_NAME=node-app
6
5
  # GCP_SECRETS_VERSION=latest
7
6
  # GCP_SA_KEY={{base64 encoded string with SA key to deploy Cloud Run}}
8
7
  # GCP_CLOUD_RUN_SA_NAME={{name of the service account for Cloud Run}}
9
-
10
- variables:
11
- # Default configuration, check .export_variables job for calculated env variables based on branch config
12
- # Node image for pipeline runner
13
- NODE_BASE_IMAGE: node:24.5.0
14
- # Where to store json secrets from Cloud provider
15
- SECRETS_PATH: '/config/secrets.json'
16
-
17
- ## GCP configuration ##
18
- # Where to temporary store Google service account
19
- GCP_SA_KEY_JSON_PATH: /tmp/key.json
20
-
21
- ## Docker artifact registry configuration ##
22
- # Project name for docker compose CI job runs
23
- DOCKER_COMPOSE_PROJECT_NAME: $CI_PROJECT_NAME-job-$CI_JOB_ID
24
- # Build docker version tag
25
- DOCKER_IMAGE_TAG: $CI_COMMIT_SHORT_SHA
26
-
27
- default:
28
- image: ackee/gitlab-builder
29
- before_script:
30
- - echo "//${CI_SERVER_HOST}/api/v4/projects/${CI_PROJECT_ID}/packages/npm/:_authToken=${CI_JOB_TOKEN}" >> .npmrc
31
- - echo "//${CI_SERVER_HOST}/api/v4/packages/npm/:_authToken=${CI_JOB_TOKEN}" >> .npmrc;
32
-
33
- cache: &docker_cache
34
- key: "$CI_COMMIT_REF_NAME"
35
- paths:
36
- - app_image*.tar
37
- policy: pull
8
+ # GCP_CLOUD_RUN_ALLOCATED_MEMORY={{allocated memory for Cloud Run}}
9
+ # GCP_SQL_INSTANCE_NAME={{name of the SQL instance for Cloud Run}}
38
10
 
39
11
  stages:
40
12
  - build
41
13
  - test
14
+ - push
42
15
  - deploy
43
16
 
44
- ##
45
- # HELPERS
46
- ##
47
- # Before script extension that exports ci-branch-config environment variables and stores the GCP service
48
- # account on the disk to be used by another jobs in the CI. This should be extended by every job that uses
49
- # any of the branch configuration, docker image or CI SA
50
- .export_variables:
51
- before_script:
52
- - export DOCKER_REGISTRY_URL="$GCP_REGION-docker.pkg.dev"
53
- - export DOCKER_IMAGE_NAME="$DOCKER_REGISTRY_URL/$GCP_PROJECT_ID/${GCP_PROJECT_ID}-docker/$CI_PROJECT_NAME"
54
- - export DOCKER_IMAGE_BUILDER_NAME="$DOCKER_IMAGE_NAME-builder"
55
- - echo "$GCP_SA_KEY" | base64 -d > "$GCP_SA_KEY_JSON_PATH"
56
-
57
-
58
- # Fetches built docker builder image from remote storage or cache
59
- .fetch_build_image: &fetch_build_image
60
- - |
61
- if ! docker inspect --type=image "$DOCKER_IMAGE_BUILDER_NAME:$DOCKER_IMAGE_TAG" >/dev/null; then
62
- docker load -i app_image_builder.tar
63
- fi
64
-
65
- ##
66
- # BUILD STAGE
67
- ##
68
- # Builds the builder docker image that can be used for running jobs using the CI docker dependencies and
69
- # configuration (tests, lint, audit, ...)
70
- build image:
71
- stage: build
72
- interruptible: true
73
- extends: .export_variables
74
- script:
75
- - |
76
- echo "app_image*" >> .dockerignore
77
- docker build --target builder \
78
- -t "$DOCKER_IMAGE_BUILDER_NAME:$DOCKER_IMAGE_TAG" .
79
- - docker save "$DOCKER_IMAGE_BUILDER_NAME:$DOCKER_IMAGE_TAG" > app_image_builder.tar
80
- cache:
81
- <<: *docker_cache
82
- policy: push
83
- when: on_success
84
-
85
- ##
86
- # TEST STAGE
87
- ##
88
- # Performs npm ci-lint script in builder image.
89
- # Make sure the ci-lint outputs json file "output/checkstyle-result.json" that reports the result of the linter
90
- lint:
91
- stage: test
92
- interruptible: true
93
- extends: .export_variables
94
- script:
95
- - if [ "$SKIP_LINT" == "true" ]; then warn "Lint skipped."; exit 0; fi
96
- - *fetch_build_image
97
- - cd "$CI_PROJECT_DIR/docker-compose"
98
- - |
99
- DOCKER_IMAGE_NAME="$DOCKER_IMAGE_BUILDER_NAME" docker-compose -p "$DOCKER_COMPOSE_PROJECT_NAME" \
100
- -f docker-compose.yml -f docker-compose.ci.yml \
101
- run --rm --no-deps app npm run ci-lint
102
- needs:
103
- - build image
104
- artifacts:
105
- reports:
106
- codequality: output/checkstyle-result.json
107
-
108
- # Npm audit run inside of builder image
109
- npm audit:
110
- stage: test
111
- interruptible: true
112
- extends: .export_variables
113
- script:
114
- - if [ "$SKIP_AUDIT" == "true" ]; then warn "Audit skipped."; exit 0; fi
115
- - *fetch_build_image
116
- - cd "$CI_PROJECT_DIR/docker-compose"
117
- - |
118
- DOCKER_IMAGE_NAME="$DOCKER_IMAGE_BUILDER_NAME" docker-compose -p "$DOCKER_COMPOSE_PROJECT_NAME" \
119
- -f docker-compose.yml -f docker-compose.ci.yml \
120
- run --rm --no-deps app npm audit --production --audit-level=high
121
- needs:
122
- - build image
123
-
124
- # Test job running npm ci-test script. Make sure the ci-test script exports two files on disk:
125
- # output/test.xml - jUnit reporter with test results
126
- # output/cobertura-coverage.xml - Test coverage results
127
- test:
128
- stage: test
129
- interruptible: true
130
- extends: .export_variables
131
- script:
132
- - if [ "$SKIP_TESTS" == "true" ]; then warn "Tests skipped."; exit 0; fi
133
- - *fetch_build_image
134
- - cd "$CI_PROJECT_DIR/docker-compose"
135
- - |
136
- DOCKER_IMAGE_NAME="$DOCKER_IMAGE_BUILDER_NAME" \
137
- docker-compose -p "$DOCKER_COMPOSE_PROJECT_NAME" \
138
- -f docker-compose.yml -f docker-compose.ci.yml \
139
- run --rm -e RUN_DOCKER_COMPOSE_DEPS=true -e DB_HOST=postgres app npm run ci-test
140
- artifacts:
141
- when: always
142
- reports:
143
- junit: output/test.xml
144
- coverage_report:
145
- coverage_format: cobertura
146
- path: output/cobertura-coverage.xml
147
- needs:
148
- - build image
17
+ variables:
18
+ # Node image for pipeline runner
19
+ NODEJS_VERSION: "24.12.0"
20
+ # Where to store json secrets from Cloud provider
21
+ SECRETS_PATH: '/config/secrets.json'
22
+ # Port for Cloud Run
23
+ PORT: "3000"
24
+ # Docker image name for Cloud Run
25
+ IMAGE_NAME: $GCP_REGION-docker.pkg.dev/$GCP_PROJECT_ID/$GCP_PROJECT_ID-docker/$CI_PROJECT_NAME:$CI_COMMIT_SHA
149
26
 
150
- ##
151
- # DEPLOY STAGE
152
- ##
153
- # Build production image and push to registry
154
- # Signs in with GCP SA key from pipeline, perform build of the image and pushes it to remote registry
155
- # Make sure /ci-branch-config-name/{branch} exists when adding new branches to "only" field
156
- build and push to registry:
157
- stage: deploy
158
- extends: .export_variables
159
- script:
160
- - docker login -u _json_key --password-stdin $DOCKER_REGISTRY_URL < "$GCP_SA_KEY_JSON_PATH"
161
- - set -a && source ci-branch-config/${CI_COMMIT_REF_NAME}.env && set +a
162
- - |
163
- docker build \
164
- -t "$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG" \
165
- $(for var in $(cat ci-branch-config/${CI_COMMIT_REF_NAME}.env | sed 's/=.*//'); do echo "--build-arg $var=${!var} "; done) \
166
- --build-arg "SECRETS_PATH=$SECRETS_PATH" \
167
- .
168
- - docker push "$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG"
169
- needs:
170
- - build image
171
- - npm audit
172
- - test
173
- environment:
174
- name: $CI_COMMIT_REF_NAME
175
- only:
176
- - development
177
- - stage
178
- - master
179
27
 
180
- # Deploy to Google Cloud Run based on image stored on remote registry
181
- deploy cloud run:
182
- stage: deploy
183
- image: google/cloud-sdk:slim
184
- extends: .export_variables
185
- script:
186
- - gcloud auth activate-service-account --key-file "$GCP_SA_KEY_JSON_PATH"
187
- - gcloud config set project $GCP_PROJECT_ID
188
- - gcloud auth configure-docker
189
- - |
190
- gcloud run deploy wake-arena-project-api \
191
- --image "$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG" \
192
- --project "$GCP_PROJECT_ID" \
193
- --platform managed \
194
- --port 3000 \
195
- --region "$GCP_REGION" \
196
- --allow-unauthenticated \
197
- --memory "$GCP_CLOUD_RUN_ALLOCATED_MEMORY" \
198
- --service-account="$GCP_CLOUD_RUN_SA_NAME" \
199
- --set-secrets=$SECRETS_PATH="$GCP_SECRETS_NAME:$GCP_SECRETS_VERSION" \
200
- --set-cloudsql-instances="$GCP_PROJECT_ID:$GCP_REGION:$GCP_SQL_INSTANCE_NAME"
201
- only:
202
- - development
203
- - stage
204
- - master
205
- environment:
206
- name: $CI_COMMIT_REF_NAME
207
- needs:
208
- - build and push to registry
28
+ include:
29
+ # BUILD APP
30
+ - component: $CI_SERVER_FQDN/Backend/gitlab-components/build@v1.0.0
31
+ inputs:
32
+ job-stage: build
33
+ # BUILD DOCKER IMAGE
34
+ - component: $CI_SERVER_FQDN/Backend/gitlab-components/docker-build@v1.0.0
35
+ inputs:
36
+ job-stage: build
37
+ allowed-branches: "master|stage|development"
38
+ image-tag: $IMAGE_NAME
39
+ # CODE QUALITY
40
+ - component: $CI_SERVER_FQDN/Backend/gitlab-components/codequality@v1.0.0
41
+ inputs:
42
+ job-stage: test
43
+ # CODE STYLE
44
+ - component: $CI_SERVER_FQDN/Backend/gitlab-components/codestyle@v1.0.0
45
+ inputs:
46
+ job-stage: test
47
+ # AUDIT
48
+ - component: $CI_SERVER_FQDN/Backend/gitlab-components/audit@v1.0.0
49
+ inputs:
50
+ job-stage: test
51
+ audit-command: npm audit --production --audit-level=high
52
+ # TEST
53
+ - component: $CI_SERVER_FQDN/Backend/gitlab-components/test@v1.0.0
54
+ inputs:
55
+ job-stage: test
56
+ test-command: DB_CONNECTION_STRING="postgres://node-app_docker:node-app_docker@postgres:5432/postgres" npm run ci-test
57
+ postgres-user: node-app_docker
58
+ postgres-password: node-app_docker
59
+ postgres-db: postgres
60
+ # PUSH DOCKER IMAGE
61
+ - component: $CI_SERVER_FQDN/Backend/gitlab-components/artifact-registry-push@v1.0.0
62
+ inputs:
63
+ job-stage: push
64
+ allowed-branches: "master|stage|development"
65
+ image-name: $IMAGE_NAME
66
+ registry: $GCP_REGION-docker.pkg.dev
67
+ # DEPLOY TO CLOUD RUN
68
+ - component: $CI_SERVER_FQDN/Backend/gitlab-components/cloudrun-deploy@v1.0.0
69
+ inputs:
70
+ job-stage: deploy
71
+ allowed-branches: "master|stage|development"
72
+ deploy-command: >-
73
+ gcloud run deploy $CI_PROJECT_NAME
74
+ --image $IMAGE_NAME
75
+ --project "$GCP_PROJECT_ID"
76
+ --platform managed
77
+ --port $PORT
78
+ --region "$GCP_REGION"
79
+ --allow-unauthenticated
80
+ --memory "$GCP_CLOUD_RUN_ALLOCATED_MEMORY"
81
+ --service-account="$GCP_CLOUD_RUN_SA_NAME"
82
+ --set-secrets=$SECRETS_PATH="$GCP_SECRETS_NAME:$GCP_SECRETS_VERSION"