From 6f979c8275e3c8eeff99135f736c5d93462007a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Acid=20Chicken=20=28=E7=A1=AB=E9=85=B8=E9=B6=8F=29?= Date: Tue, 30 Oct 2018 12:36:14 +0900 Subject: [PATCH] Configure CI (#3037) * Update config.yml * Configure CI * Use Vesion 2.1 * Fix error * Ensure binary builds * Ensure misskey builds * Store artifacts * Ensure node-gyp builds * Fix typo * Fix typo * Ensure binary builds * Update working directory * Cache test npm packages * Revert "Update working directory" * Ensure misskey builds * Ensure node-gyp builds * Fix missing configurations * Configure deploy filters * Use latest npm in Docker --- {.travis => .ci}/default.yml | 0 {.travis => .ci}/test.yml | 0 .circleci/config.yml | 137 ++++++++++++++++++++++++++--------- .travis.yml | 4 +- Dockerfile | 11 +-- 5 files changed, 111 insertions(+), 41 deletions(-) rename {.travis => .ci}/default.yml (100%) rename {.travis => .ci}/test.yml (100%) diff --git a/.travis/default.yml b/.ci/default.yml similarity index 100% rename from .travis/default.yml rename to .ci/default.yml diff --git a/.travis/test.yml b/.ci/test.yml similarity index 100% rename from .travis/test.yml rename to .ci/test.yml diff --git a/.circleci/config.yml b/.circleci/config.yml index 630a7eebb..422f6fdc2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,60 +1,129 @@ -version: 2 +version: 2.1 general: branches: ignore: - l10n_develop + - imgbot + +executors: + default: + working_directory: /tmp/workspace + docker: + - image: misskey/ci:latest + - image: circleci/mongo:latest + - image: circleci/redis:latest + docker: + working_directory: /tmp/workspace + docker: + - image: docker:latest jobs: - webpack-build: - working_directory: /misskey - docker: - - image: yukimochi/misskey-builder:latest + build: + executor: default steps: - checkout + - restore_cache: + name: Restore npm package caches + keys: + - npm-v1-arch-{{ arch }}-env-{{ .Environment.variableName }}-package-{{ checksum "package.json" }}-lock-{{ checksum "package-lock.json" }}- + - npm-v1-arch-{{ arch }}-env-{{ .Environment.variableName }}-package-{{ checksum "package.json" }}- + - npm-v1-arch-{{ arch }}-env-{{ .Environment.variableName }}- + - npm-v1-arch-{{ arch }}- + - npm-v1- - run: - name: Setup Dependencies + name: Install Dependencies command: | - yarn install - yarn global add web-push + npm install - run: - name: Import default.yml + name: Configure command: | - echo ${IMPORT_DEFAULT_YML} | base64 -d | gzip -d > .config/default.yml + cp .ci/default.yml .config + cp .ci/test.yml .config - run: - name: Build Webpack + name: Build command: | - yarn run build + npm run build || (echo -e '\033[0;34mRebuild modules\033[0;39m' && ls -1A node_modules | grep '^[^@]' | xargs npm rebuild && ls -1A node_modules | grep '^@' | xargs -I%1 sh -c 'ls -1A node_modules/'%1' | xargs -P0 -I%2 npm rebuild node_modules/'%1'/%2' && npm run build) + ls -1ARl node_modules > ls + - save_cache: + name: Cache npm packages + key: npm-v1-arch-{{ arch }}-env-{{ .Environment.variableName }}-package-{{ checksum "package.json" }}-lock-{{ checksum "package-lock.json" }}-ls-{{ checksum "ls" }} + paths: + - node_modules + - store_artifacts: + path: built + - persist_to_workspace: + root: . + paths: + - . + test: + parameters: + without_redis: + type: string + default: "" + executor: default + steps: + - attach_workspace: + at: /tmp/workspace + - when: + condition: <> + steps: + - run: + name: Configure + command: | + mv .config/test.yml .config/test_redis.yml + touch .config/test.yml + cat .config/test_redis.yml | while IFS= read line; do if [[ "$line" = '# __REDIS__' ]]; then break; else echo "$line" >> .config/test.yml; fi; done - run: - name: Compress clients + name: Test command: | - find ./built/client -name "*.js" -or -name "*.js.map" -or -name "*.css" -or -name "*.svg" -or -name "*.html" -or -name "*.json" | xargs -t gzip -k -9 - find ./built/client -name "*.js" -or -name "*.js.map" -or -name "*.css" -or -name "*.svg" -or -name "*.html" -or -name "*.json" | xargs -t brotli -q 10 - tar cfz ~/built-${CIRCLE_SHA1}.tar.gz built - - run: - name: Send built s3 - command: | - mc config host add ykmc ${s3_endpoint} ${s3_accesskey} ${s3_secretkey} - mc cp ~/built-${CIRCLE_SHA1}.tar.gz ${backet}/${CIRCLE_BRANCH}/ - docker-build: - docker: - - image: docker:17-git + npm run test || (npm rebuild && npm run test) || ((node-gyp configure && node-gyp build && npm run build || (echo -e '\033[0;34mRebuild modules\033[0;39m' && ls -1A node_modules | grep '^[^@]' | xargs npm rebuild && ls -1A node_modules | grep '^@' | xargs -I%1 sh -c 'ls -1A node_modules/'%1' | xargs -P0 -I%2 npm rebuild node_modules/'%1'/%2' && npm run build)) && npm run test) + ls -1ARl node_modules > ls + - save_cache: + name: Cache npm packages + key: npm-v1-arch-{{ arch }}-env-{{ .Environment.variableName }}-package-{{ checksum "package.json" }}-lock-{{ checksum "package-lock.json" }}-ls-{{ checksum "ls" }} + paths: + - node_modules + + docker: + parameters: + with_deploy: + type: string + default: "" + executor: docker steps: - checkout - setup_remote_docker - run: - name: build docker image + name: Build command: | - docker build -t misskey:latest . - - run: - name: upload image to docker hub. - command: | - docker login --username=${DOCKER_USER} --password=${DOCKER_PASS} - docker push ${DOCKER_USER}/misskey:latest + docker build . + - when: + condition: <> + steps: + - run: + name: Deploy + command: | + docker login -u $DOCKERHUB_USERNAME -p $DOCKERHUB_PASSWORD && docker push misskey/misskey workflows: version: 2 - build: + build-and-test: jobs: - - webpack-build - - docker-build + - build + - test: + requires: + - build + - test: + without_redis: "true" + requires: + - build + - docker: + filters: + branches: + ignore: master + - docker: + with_deploy: "true" + filters: + branches: + only: master diff --git a/.travis.yml b/.travis.yml index bf00d28da..80ecb236c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,7 +35,7 @@ before_script: - npm install # 設定ファイルを配置 - - cp ./.travis/default.yml ./.config - - cp ./.travis/test.yml ./.config + - cp ./.ci/default.yml ./.config + - cp ./.ci/test.yml ./.config - travis_wait npm run build diff --git a/Dockerfile b/Dockerfile index a95789c01..e31af0099 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,11 +21,12 @@ RUN apk add --no-cache \ pkgconfig \ libtool \ zlib-dev -RUN npm install \ - && npm install -g node-gyp \ - && node-gyp configure \ - && node-gyp build \ - && npm run build +RUN npm i -g npm@latest \ + && npm i \ + && npm i -g node-gyp \ + && node-gyp configure \ + && node-gyp build \ + && npm run build FROM base AS runner