From 0afc9c27af7c6f8fa08e685311ef287baa052869 Mon Sep 17 00:00:00 2001 From: Daniel_I_Am Date: Sat, 28 May 2022 12:36:45 +0000 Subject: [PATCH] Implement CI/CD --- .eslintrc.js | 34 ++++++++++++------------ .gitlab-ci.yml | 57 +++++++++++++++++++++++++++++++++++++++++ Makefile | 2 +- babel.config.js | 2 +- docker/nginx/Dockerfile | 2 +- src/data/snippets.json | 1 + vue.config.js | 2 +- yarn.lock | 6 ++--- 8 files changed, 82 insertions(+), 24 deletions(-) create mode 100644 .gitlab-ci.yml diff --git a/.eslintrc.js b/.eslintrc.js index d3404af..2ce6537 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,19 +1,19 @@ module.exports = { - root: true, - env: { - node: true, - }, - extends: [ - "plugin:vue/vue3-essential", - "eslint:recommended", - "@vue/typescript/recommended", - "plugin:prettier/recommended", - ], - parserOptions: { - ecmaVersion: 2020, - }, - rules: { - "no-console": process.env.NODE_ENV === "production" ? "warn" : "off", - "no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off", - }, + root: true, + env: { + node: true, + }, + extends: [ + "plugin:vue/vue3-essential", + "eslint:recommended", + "@vue/typescript/recommended", + "plugin:prettier/recommended", + ], + parserOptions: { + ecmaVersion: 2020, + }, + rules: { + "no-console": process.env.NODE_ENV === "production" ? "warn" : "off", + "no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off", + }, }; diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..066f2b5 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,57 @@ +stages: + - "Install Dependencies" + - "Lint Code" + - "Build Docker Image" + - "Publish Docker Image" + +"Install node_modules": + image: node:16 + stage: "Install Dependencies" + script: + - yarn --frozen-lockfile + artifacts: + paths: + - node_modules/ + +"Lint JS": + image: node:16 + stage: "Lint Code" + dependencies: + - "Install node_modules" + script: + - yarn lint --no-fix + +"Build docker image": + image: docker:stable + stage: "Build Docker Image" + tags: + - docker + - hawkeye + dependencies: + - "Install node_modules" + - "Lint JS" + script: + # Add make support + - 'apk add --no-cache make' + # Build the image + - 'make build-container DOCKER_REPOSITORY=$REGISTRY_BASE_URL/$DOCKER_IMAGE_NAME DOCKER_TAG=$CI_COMMIT_SHA' + rules: + - if: '$CI_COMMIT_REF_PROTECTED == "true"' + +"Publish Docker Image": + image: docker:stable + stage: "Publish Docker Image" + tags: + - docker + - hawkeye + dependencies: + - "Build docker image" + script: + # Log in to the registry + - 'docker login -u=$REGISTRY_USER -p=$REGISTRY_PASSWORD $REGISTRY_BASE_URL' + # Push the registry images + - 'docker image push $REGISTRY_BASE_URL/$DOCKER_IMAGE_NAME:$CI_COMMIT_SHA' + # Clean local image + - 'docker image rm $REGISTRY_BASE_URL/$DOCKER_IMAGE_NAME:$CI_COMMIT_SHA' + rules: + - if: '$CI_COMMIT_REF_PROTECTED == "true"' diff --git a/Makefile b/Makefile index 5a503a5..fc62afc 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -DOCKER_REPOSITORY := daniel-website/nginx +DOCKER_REPOSITORY?="daniel-website/nginx" DOCKER_TAG?="dev" .DEFAULT_GOAL := help diff --git a/babel.config.js b/babel.config.js index 162a3ea..6431b56 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,3 +1,3 @@ module.exports = { - presets: ["@vue/cli-plugin-babel/preset"], + presets: ["@vue/cli-plugin-babel/preset"], }; diff --git a/docker/nginx/Dockerfile b/docker/nginx/Dockerfile index 63c5e9a..922a460 100644 --- a/docker/nginx/Dockerfile +++ b/docker/nginx/Dockerfile @@ -5,7 +5,7 @@ WORKDIR /code USER node -RUN yarn +RUN yarn --frozen-lockfile RUN yarn build FROM nginx:1.22.0-alpine diff --git a/src/data/snippets.json b/src/data/snippets.json index dc61d78..580155d 100644 --- a/src/data/snippets.json +++ b/src/data/snippets.json @@ -1,5 +1,6 @@ [ { + "id": 1, "title": "Seconds since last pacman sync", "slug": "seconds-since-last-pacman-sync", "timeAdded": 1652993100, diff --git a/vue.config.js b/vue.config.js index 0aed899..32febd4 100644 --- a/vue.config.js +++ b/vue.config.js @@ -1,4 +1,4 @@ const { defineConfig } = require("@vue/cli-service"); module.exports = defineConfig({ - transpileDependencies: true, + transpileDependencies: true, }); diff --git a/yarn.lock b/yarn.lock index 561fab1..24b35bf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2276,9 +2276,9 @@ caniuse-api@^3.0.0: lodash.uniq "^4.5.0" caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001332, caniuse-lite@^1.0.30001335: - version "1.0.30001343" - resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001343.tgz" - integrity sha512-8KeCrAtPMabo/XW14B+R9sZYoClx1n0b+WYgwDKZPtWR3TcdvWzdSy7mPyFEmR5WU1St9v1PW6sdO5dkFOEzfA== + version "1.0.30001344" + resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001344.tgz" + integrity sha512-0ZFjnlCaXNOAYcV7i+TtdKBp0L/3XEU2MF/x6Du1lrh+SRX4IfzIVL4HNJg5pB2PmFb8rszIGyOvsZnqqRoc2g== case-sensitive-paths-webpack-plugin@^2.3.0: version "2.4.0"