From 3a16d30b5773c4327e47d368e071f91995fc796f Mon Sep 17 00:00:00 2001 From: Kai Hendry Date: Fri, 7 Feb 2020 12:04:50 +0800 Subject: [PATCH 1/8] This comes from my unmerged PR https://github.com/unee-t/frontend/pull/750 which I think solves https://github.com/unee-t/frontend/pull/892#issuecomment-583220464 because it locks down to .meteor/release --- Dockerfile | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index e456dd4d..d757b7c2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,26 +1,36 @@ -FROM node:8 AS builder +FROM node:8.15.1 AS builder -RUN curl -sL https://install.meteor.com | sed s/--progress-bar/-sL/g | /bin/sh -RUN mkdir /src /bundle -RUN chown -R node /src /bundle +ENV BUNDLE_DIR /home/node/bundle +ENV SRC_DIR /home/node/src +ENV TMP_DIR /home/node/tmp USER node:node -WORKDIR /src -COPY --chown=node:node . . +RUN mkdir -p $SRC_DIR $BUNDLE_DIR $TMP_DIR +COPY --chown=node:node . $SRC_DIR -RUN meteor npm install -RUN meteor build --architecture os.linux.x86_64 --directory /bundle -RUN cd /bundle/bundle/programs/server && npm install +RUN curl -o $TMP_DIR/meteor.sh 'https://install.meteor.com?release=1.8.1'; sh $TMP_DIR/meteor.sh -FROM node:8-slim +ENV PATH="/home/node/.meteor:${PATH}" +WORKDIR $SRC_DIR +RUN npm i +RUN meteor npm install --production +RUN meteor build --server-only --directory $BUNDLE_DIR +RUN cd ${BUNDLE_DIR}/bundle/programs/server && npm install + +FROM node:8.15.1-slim + +ENV APP_DIR /home/node/app +ENV BUNDLE_DIR /home/node/bundle USER node:node -COPY --from=builder /bundle /app -WORKDIR /app/bundle +COPY --from=builder $BUNDLE_DIR $APP_DIR +WORKDIR $APP_DIR/bundle + ENV PORT 3000 EXPOSE 3000 + CMD ["node", "./main.js"] From a05e5985e1b4a37fdb7e0feddcf5773e7b8178d7 Mon Sep 17 00:00:00 2001 From: Kai Hendry Date: Fri, 7 Feb 2020 14:47:39 +0800 Subject: [PATCH 2/8] CI via Dockerfile for more control --- .travis.yml | 64 +++++++++++++++++++++++++++++++---------------------- Dockerfile | 3 +-- 2 files changed, 39 insertions(+), 28 deletions(-) diff --git a/.travis.yml b/.travis.yml index 72f8365a..20354a6b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,50 +1,62 @@ -sudo: required +language: generic +services: + - docker -language: node_js -node_js: - - lts/* +env: + global: + - IMAGE_TAG=${TRAVIS_COMMIT::7} before_install: - # Removed command as pyenv is no longer found during deploy - #- pyenv global 2.7.14 # For removing SNIMissingWarning warnings - - curl https://install.meteor.com | /bin/sh - - export PATH="$HOME/.meteor:$PATH" - pip install --user awscli - export PATH=$PATH:$HOME/.local/bin - curl -o $HOME/.local/bin/ecs-cli https://s3.amazonaws.com/amazon-ecs-cli/ecs-cli-linux-amd64-latest && chmod +x $HOME/.local/bin/ecs-cli -cache: - directories: - - node_modules - -install: - - meteor npm install - -script: - - npm t +after_success: + - docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"; + - docker build -t $DOCKER_CI_REPO_NAME:latest . + - docker tag $DOCKER_CI_REPO_NAME:latest $DOCKER_CI_REPO_NAME:$IMAGE_TAG + - docker push $DOCKER_CI_REPO_NAME:latest + - docker push $DOCKER_CI_REPO_NAME:$IMAGE_TAG matrix: include: - - env: DEPLOY=none + # add deploy stage for dev + - env: DEPLOY=dev + if: branch = master + deploy: + provider: script + script: TRAVIS_DOCKER_REPO_NAME=$DOCKER_CI_REPO_NAME + TRAVIS_PROFILE=$AWS_PROFILE_DEV + TRAVIS_AWS_ACCESS_KEY_ID=$AWS_ACCOUNT_USER_ID_DEV + TRAVIS_AWS_SECRET_ACCESS_KEY=$AWS_ACCOUNT_SECRET_DEV + TRAVIS_AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION + ./deploy.sh + on: + branch: master - env: DEPLOY=demo if: tag IS present deploy: provider: script - skip_cleanup: true - script: AWS_ACCESS_KEY_ID=$AWS_915001051872_ID AWS_SECRET_ACCESS_KEY=$AWS_915001051872_SECRET ./deploy.sh -d + script: PROFILE=$AWS_PROFILE_DEMO + AWS_ACCESS_KEY_ID=$AWS_ACCOUNT_USER_ID_DEMO + AWS_SECRET_ACCESS_KEY=$AWS_ACCOUNT_SECRET_DEMO + AWS_REGION=$AWS_DEFAULT_REGION + ./deploy.sh -d on: tags: true - env: DEPLOY=prod if: tag IS present deploy: provider: script - skip_cleanup: true - script: AWS_ACCESS_KEY_ID=$AWS_192458993663_ID AWS_SECRET_ACCESS_KEY=$AWS_192458993663_SECRET ./deploy.sh -p && AWS_ACCESS_KEY_ID=$AWS_192458993663_ID AWS_SECRET_ACCESS_KEY=$AWS_192458993663_SECRET aws cloudfront create-invalidation --distribution-id E173XT6X8V4A18 --paths '/*' + script: PROFILE=$AWS_PROFILE_PROD + AWS_ACCESS_KEY_ID=$AWS_ACCOUNT_USER_ID_PROD + AWS_SECRET_ACCESS_KEY=$AWS_ACCOUNT_SECRET_PROD + AWS_REGION=$AWS_DEFAULT_REGION . + /deploy.sh -p && + AWS_ACCESS_KEY_ID=$AWS_ACCOUNT_USER_ID_PROD + AWS_SECRET_ACCESS_KEY=$AWS_ACCOUNT_SECRET_PROD + aws cloudfront create-invalidation --distribution-id E173XT6X8V4A18 --paths '/*' on: tags: true - -env: - global: - - COMMIT=${TRAVIS_COMMIT::7} diff --git a/Dockerfile b/Dockerfile index d757b7c2..fc809225 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,6 +15,7 @@ ENV PATH="/home/node/.meteor:${PATH}" WORKDIR $SRC_DIR RUN npm i RUN meteor npm install --production +RUN npm t RUN meteor build --server-only --directory $BUNDLE_DIR RUN cd ${BUNDLE_DIR}/bundle/programs/server && npm install @@ -28,9 +29,7 @@ USER node:node COPY --from=builder $BUNDLE_DIR $APP_DIR WORKDIR $APP_DIR/bundle - ENV PORT 3000 EXPOSE 3000 - CMD ["node", "./main.js"] From 5b9a921788145282b82bb1535215688620a417a9 Mon Sep 17 00:00:00 2001 From: Kai Hendry Date: Fri, 7 Feb 2020 14:48:30 +0800 Subject: [PATCH 3/8] Deprecated Code build in favour of Travis build --- buildspec.yml | 39 --------------------------------------- 1 file changed, 39 deletions(-) delete mode 100644 buildspec.yml diff --git a/buildspec.yml b/buildspec.yml deleted file mode 100644 index 8fc70167..00000000 --- a/buildspec.yml +++ /dev/null @@ -1,39 +0,0 @@ ---- -version: 0.2 - -env: - variables: - IMAGE_REPO_NAME: uneet/frontend - parameter-store: - DOCKER_USERNAME: DOCKER_USERNAME - DOCKER_PASSWORD: DOCKER_PASSWORD - -phases: - pre_build: - commands: - - echo Logging into Docker Hub... - - docker login --username $DOCKER_USERNAME --password $DOCKER_PASSWORD - - IMAGE_TAG=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7) - - install: - runtime-versions: - docker: 18 - - build: - commands: - - echo Build starting on `date` - - echo Build the Docker image... - - 'sed -i "s,<\!-- COMMIT: -->,<\!-- COMMIT: $CODEBUILD_RESOLVED_SOURCE_VERSION -->,g" client/main.html' - - docker build -t $IMAGE_REPO_NAME:latest . - - docker tag $IMAGE_REPO_NAME:latest $IMAGE_REPO_NAME:$IMAGE_TAG - - post_build: - commands: - - test "$CODEBUILD_BUILD_SUCCEEDING" == "1" || exit 1 - - echo Pushing build to Docker Hub... - - docker push $IMAGE_REPO_NAME:latest - - docker push $IMAGE_REPO_NAME:$IMAGE_TAG - - printf '[{"name":"%s","imageUri":"%s"}]' meteor $IMAGE_REPO_NAME:$IMAGE_TAG > $CODEBUILD_SRC_DIR/imagedefinitions.json - -artifacts: - files: imagedefinitions.json From 877b03750aaa46cefa1b518416b5f5d69f148a19 Mon Sep 17 00:00:00 2001 From: Kai Hendry Date: Sat, 8 Feb 2020 18:30:06 +0800 Subject: [PATCH 4/8] Don't do tests in the Dockerfile as it would require a truck ton more depedencies https://techoverflow.net/2018/06/05/how-to-fix-puppetteer-error-while-loading-shared-libraries-libx11-xcb-so-1-cannot-open-shared-object-file-no-such-file-or-directory/ So strategy is to do CI in Travis, CD via Docker --- .travis.yml | 22 ++++++++++++++++++---- Dockerfile | 1 - 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 20354a6b..eb8ca4bc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ -language: generic +language: node_js services: - docker @@ -7,15 +7,29 @@ env: - IMAGE_TAG=${TRAVIS_COMMIT::7} before_install: + - curl https://install.meteor.com | /bin/sh + - export PATH="$HOME/.meteor:$PATH" - pip install --user awscli - export PATH=$PATH:$HOME/.local/bin + # Used in deploy.sh - curl -o $HOME/.local/bin/ecs-cli https://s3.amazonaws.com/amazon-ecs-cli/ecs-cli-linux-amd64-latest && chmod +x $HOME/.local/bin/ecs-cli +cache: + directories: + - node_modules + +install: + - meteor npm install + +script: + - npm t + after_success: - - docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"; - docker build -t $DOCKER_CI_REPO_NAME:latest . + # TODO: this should only happen really on branch = master + - docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"; - docker tag $DOCKER_CI_REPO_NAME:latest $DOCKER_CI_REPO_NAME:$IMAGE_TAG - docker push $DOCKER_CI_REPO_NAME:latest - docker push $DOCKER_CI_REPO_NAME:$IMAGE_TAG @@ -53,8 +67,8 @@ matrix: script: PROFILE=$AWS_PROFILE_PROD AWS_ACCESS_KEY_ID=$AWS_ACCOUNT_USER_ID_PROD AWS_SECRET_ACCESS_KEY=$AWS_ACCOUNT_SECRET_PROD - AWS_REGION=$AWS_DEFAULT_REGION . - /deploy.sh -p && + AWS_REGION=$AWS_DEFAULT_REGION + ./deploy.sh -p && AWS_ACCESS_KEY_ID=$AWS_ACCOUNT_USER_ID_PROD AWS_SECRET_ACCESS_KEY=$AWS_ACCOUNT_SECRET_PROD aws cloudfront create-invalidation --distribution-id E173XT6X8V4A18 --paths '/*' diff --git a/Dockerfile b/Dockerfile index fc809225..6e74e928 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,7 +15,6 @@ ENV PATH="/home/node/.meteor:${PATH}" WORKDIR $SRC_DIR RUN npm i RUN meteor npm install --production -RUN npm t RUN meteor build --server-only --directory $BUNDLE_DIR RUN cd ${BUNDLE_DIR}/bundle/programs/server && npm install From 6be0ce0505cfe76a8509952af14f1f83d0504bcd Mon Sep 17 00:00:00 2001 From: Kai Hendry Date: Sun, 9 Feb 2020 13:59:25 +0800 Subject: [PATCH 5/8] Try get CI passing like https://travis-ci.org/unee-t/frontend/jobs/647650881/config --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index eb8ca4bc..2157b529 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,8 @@ language: node_js + +node_js: # node 12 + - lts/* + services: - docker From eca29b8aad1498e5ca02ae8f7b2bea0e7b940d1b Mon Sep 17 00:00:00 2001 From: Kai Hendry Date: Sun, 9 Feb 2020 14:06:39 +0800 Subject: [PATCH 6/8] Build with Node 8 --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2157b529..c3dff644 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: node_js -node_js: # node 12 - - lts/* +node_js: # Node 8 for bcrypt 1.0.3 https://github.com/kelektiv/node.bcrypt.js#version-compatibility + - 8 services: - docker From df329a8360d0d2fef34c90c712ffef64e17af5d1 Mon Sep 17 00:00:00 2001 From: Kai Hendry Date: Sun, 9 Feb 2020 14:10:57 +0800 Subject: [PATCH 7/8] Desperating trying to reproduce https://travis-ci.org/unee-t/frontend/jobs/647650881/config --- .travis.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index c3dff644..85b8d565 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: node_js -node_js: # Node 8 for bcrypt 1.0.3 https://github.com/kelektiv/node.bcrypt.js#version-compatibility - - 8 +node_js: + - lts/* services: - docker @@ -26,6 +26,7 @@ cache: install: - meteor npm install + - meteor npm install --save bcrypt script: - npm t From c4b0bf36d9abf3d87ca544a3a18d1fa8dbc3ea35 Mon Sep 17 00:00:00 2001 From: Kai Hendry Date: Sun, 9 Feb 2020 15:48:42 +0800 Subject: [PATCH 8/8] Disable tests --- .travis.yml | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/.travis.yml b/.travis.yml index 85b8d565..c49d793b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,36 +1,16 @@ -language: node_js - -node_js: - - lts/* - -services: - - docker +language: generic env: global: - IMAGE_TAG=${TRAVIS_COMMIT::7} before_install: - - curl https://install.meteor.com | /bin/sh - - export PATH="$HOME/.meteor:$PATH" - - pip install --user awscli - - export PATH=$PATH:$HOME/.local/bin # Used in deploy.sh + - export PATH=$PATH:$HOME/.local/bin - curl -o $HOME/.local/bin/ecs-cli https://s3.amazonaws.com/amazon-ecs-cli/ecs-cli-linux-amd64-latest && chmod +x $HOME/.local/bin/ecs-cli -cache: - directories: - - node_modules - -install: - - meteor npm install - - meteor npm install --save bcrypt - -script: - - npm t - after_success: - docker build -t $DOCKER_CI_REPO_NAME:latest . # TODO: this should only happen really on branch = master @@ -74,6 +54,7 @@ matrix: AWS_SECRET_ACCESS_KEY=$AWS_ACCOUNT_SECRET_PROD AWS_REGION=$AWS_DEFAULT_REGION ./deploy.sh -p && + # TODO distribition ID should probably be an ENV variable AWS_ACCESS_KEY_ID=$AWS_ACCOUNT_USER_ID_PROD AWS_SECRET_ACCESS_KEY=$AWS_ACCOUNT_SECRET_PROD aws cloudfront create-invalidation --distribution-id E173XT6X8V4A18 --paths '/*'