diff --git a/.gitignore b/.gitignore index 9fb1ed6..f377c3c 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,5 @@ temp/ *.swp *.tmp +package-lock.json yarn-error.log diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3f74cee..19a8ad7 100755 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -11,14 +11,15 @@ stages: # build jobs build-node: - stage: build extends: - .build-node + stage: build script: - make ci artifacts: + when: always expire_in: 1 day paths: - out/ @@ -28,31 +29,60 @@ build-node: policy: pull-push paths: - node_modules/ + - out/api + - out/cache + - out/tmp -build-image-branch: - stage: image +build-image-alpine-branch: extends: - .build-docker - - .deploy-branches - - dependencies: - - build-node - -build-image-tag: stage: image + except: + - tags + script: + - ./scripts/docker-build.sh --push --default + variables: + IMAGE_ARCH: alpine + +build-image-alpine-tag: extends: - .build-docker - - .deploy-tags + stage: image + only: + - tags + script: + - ./scripts/docker-build.sh --push --default + variables: + IMAGE_ARCH: alpine - dependencies: - - build-node +build-image-stretch-branch: + extends: [.build-docker] + stage: image + except: + - tags + script: + - ./scripts/docker-build.sh --push + variables: + IMAGE_ARCH: stretch + +build-image-stretch-tag: + extends: + - .build-docker + stage: image + only: + - tags + script: + - ./scripts/docker-build.sh --push + variables: + IMAGE_ARCH: stretch # publish jobs publish-npm: - stage: publish extends: - .build-node - - .deploy-tags + stage: publish + only: + - tags dependencies: - build-node @@ -68,15 +98,6 @@ climate-pending: script: - cc-test-reporter before-build -climate-failure: - stage: status-post - extends: - - .build-climate - - when: on_failure - script: - - cc-test-reporter after-build --debug --exit-code 1 - climate-success: stage: status-post extends: @@ -99,27 +120,24 @@ codecov-success: - make upload-codecov github-pending: - stage: status-pre extends: - .build-curl - + stage: status-pre script: - - ${CI_PROJECT_DIR}/scripts/github-status.sh pending + - ./scripts/github-status.sh pending github-failure: - stage: status-post extends: - .build-curl - + stage: status-post when: on_failure script: - - ${CI_PROJECT_DIR}/scripts/github-status.sh failure + - ./scripts/github-status.sh failure github-success: - stage: status-post extends: - .build-curl - + stage: status-post when: on_success script: - - ${CI_PROJECT_DIR}/scripts/github-status.sh success + - ./scripts/github-status.sh success diff --git a/Dockerfile.alpine b/Dockerfile.alpine new file mode 100644 index 0000000..a685a6c --- /dev/null +++ b/Dockerfile.alpine @@ -0,0 +1,16 @@ +FROM node:12-alpine + +COPY package.json /app/package.json +COPY yarn.lock /app/yarn.lock + +WORKDIR /app + +RUN yarn install --production + +COPY . /app + +RUN yarn global add file:$(pwd) +ENV PATH="${PATH}:$(yarn global bin)" + +ENTRYPOINT [ "node", "/app/out/index.js" ] +CMD [ "--help" ] diff --git a/Dockerfile b/Dockerfile.stretch similarity index 77% rename from Dockerfile rename to Dockerfile.stretch index 92c6819..c9c1d79 100644 --- a/Dockerfile +++ b/Dockerfile.stretch @@ -1,5 +1,4 @@ FROM node:12-stretch -# alpine may be smaller, but comes with a 10-15% perf hit COPY package.json /app/package.json COPY yarn.lock /app/yarn.lock @@ -14,4 +13,4 @@ RUN yarn global add file:$(pwd) ENV PATH="${PATH}:$(yarn global bin)" ENTRYPOINT [ "node", "/app/out/index.js" ] -CMD [ "--help" ] \ No newline at end of file +CMD [ "--help" ] diff --git a/scripts/docker-build.sh b/scripts/docker-build.sh index 849986f..bce104d 100755 --- a/scripts/docker-build.sh +++ b/scripts/docker-build.sh @@ -1,17 +1,27 @@ #! /bin/bash IMAGE_PUSH="${1:---skip}" +IMAGE_DEFAULT="${2:---skip}" IMAGE_NAME="${CI_PROJECT_PATH}" -IMAGE_TAG="$(echo "${CI_COMMIT_TAG:-${CI_COMMIT_REF_SLUG}}" | sed -r 's/[^-_a-zA-Z0-9]/-/g')" -IMAGE_FULL="${IMAGE_NAME}:${IMAGE_TAG}" +IMAGE_TAG="$(echo "${CI_COMMIT_TAG:-${CI_COMMIT_REF_SLUG}}" | sed -r 's/[^-_a-zA-Z0-9\\.]/-/g')" + +IMAGE_SHORT="${IMAGE_NAME}:${IMAGE_TAG}" +IMAGE_FULL="${IMAGE_NAME}:${IMAGE_TAG}-${IMAGE_ARCH}" echo "Building image: ${IMAGE_FULL}" -docker build -t "${IMAGE_FULL}" . +docker build -f "Dockerfile.${IMAGE_ARCH}" -t "${IMAGE_FULL}" . if [[ "${IMAGE_PUSH}" == "--push" ]]; then echo "Pushing image: ${IMAGE_FULL}" docker push "${IMAGE_FULL}" fi + +if [[ "${IMAGE_DEFAULT}" == "--default" ]]; +then + echo "Pushing image (default architecture): ${IMAGE_SHORT}" + docker tag "${IMAGE_FULL}" "${IMAGE_SHORT}" + docker push "${IMAGE_SHORT}" +fi