From 4e694d278a2149c5ea6283d22021801b0e84d6ad Mon Sep 17 00:00:00 2001 From: iVamp Date: Tue, 24 Oct 2023 18:08:36 +0800 Subject: [PATCH] =?UTF-8?q?CI=20=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitlab-ci.yml | 40 ++++++++++++++++++++++++++++++++++++++++ Dockerfile | 17 +++++++++++++++++ package.json | 8 +++++--- 3 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 .gitlab-ci.yml create mode 100644 Dockerfile diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..ace4c55 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,40 @@ +docker-build: + image: docker:latest + stage: build + tags: + - vm + before_script: + - docker login "$DOCKER_REGISTRY" -u "$DOCKER_USER" -p "$DOCKER_PASSWORD" + script: + - | + if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then + tag="" + echo "Running on default branch '$CI_DEFAULT_BRANCH': tag = 'latest'" + else + tag=":$CI_COMMIT_REF_SLUG" + echo "Running on branch '$CI_COMMIT_BRANCH': tag = $tag" + fi + - docker build --pull -t "$CI_REGISTRY_IMAGE${tag}" . + - docker push "$CI_REGISTRY_IMAGE${tag}" + # Run this job in a branch where a Dockerfile exists + rules: + - if: $CI_COMMIT_BRANCH + exists: + - Dockerfile +kubectl: + image: bitnami/kubectl + stage: build + tags: + - k8s + before_script: + - kubectl get pods -n foo + script: + - | + if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then + tag="" + echo "Running on default branch '$CI_DEFAULT_BRANCH': tag = 'latest'" + else + tag=":$CI_COMMIT_REF_SLUG" + echo "Running on branch '$CI_COMMIT_BRANCH': tag = $tag" + fi + - echo test diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..dc5244b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM node:20 +LABEL authors="ivamp" + +WORKDIR /app +ADD . /app + +RUN npm config set registry https://registry.npm.taobao.org/ && yarn config set registry https://registry.npm.taobao.org/ + +RUN npm install -g -s --no-progress yarn && \ + yarn && \ + yarn cache clean \ + +CMD [ "yarn", "migrate" ] + +CMD [ "yarn", "start" ] + +EXPOSE 8080 diff --git a/package.json b/package.json index 3f2b152..f61ab70 100644 --- a/package.json +++ b/package.json @@ -10,19 +10,21 @@ "mysql2": "^3.6.2", "path": "^0.12.7", "reflect-metadata": "^0.1.13", - "typeorm": "0.3.17" + "typeorm": "0.3.17", + "ts-node": "^10.9.1" }, "devDependencies": { "@types/express": "^4.17.20", "@types/morgan": "^1.9.7", "@types/node": "^16.11.10", - "ts-node": "^10.9.1", "typescript": "4.5.2" }, "scripts": { "start": "ts-node main.ts", "typeorm": "typeorm-ts-node-commonjs", "migrate": "typeorm-ts-node-commonjs migration:run -d src/config/typeorm.ts", - "migrate:rollback": "typeorm-ts-node-commonjs migration:revert -d src/config/typeorm.ts" + "migrate:rollback": "typeorm-ts-node-commonjs migration:revert -d src/config/typeorm.ts", + "make:migration": "typeorm-ts-node-commonjs migration:create", + "migrate:fresh": "typeorm-ts-node-commonjs schema:drop -d src/config/typeorm.ts" } }