1
0
Fork 0

feat(build): add alpine image job from salty-dog

This commit is contained in:
ssube 2019-11-09 20:02:22 -06:00 committed by Sean Sube
parent f9b1a813b7
commit 67237eac81
5 changed files with 81 additions and 37 deletions

1
.gitignore vendored
View File

@ -10,4 +10,5 @@ temp/
*.swp *.swp
*.tmp *.tmp
package-lock.json
yarn-error.log yarn-error.log

View File

@ -11,14 +11,15 @@ stages:
# build jobs # build jobs
build-node: build-node:
stage: build
extends: extends:
- .build-node - .build-node
stage: build
script: script:
- make ci - make ci
artifacts: artifacts:
when: always
expire_in: 1 day expire_in: 1 day
paths: paths:
- out/ - out/
@ -28,31 +29,60 @@ build-node:
policy: pull-push policy: pull-push
paths: paths:
- node_modules/ - node_modules/
- out/api
- out/cache
- out/tmp
build-image-branch: build-image-alpine-branch:
stage: image
extends: extends:
- .build-docker - .build-docker
- .deploy-branches
dependencies:
- build-node
build-image-tag:
stage: image stage: image
except:
- tags
script:
- ./scripts/docker-build.sh --push --default
variables:
IMAGE_ARCH: alpine
build-image-alpine-tag:
extends: extends:
- .build-docker - .build-docker
- .deploy-tags stage: image
only:
- tags
script:
- ./scripts/docker-build.sh --push --default
variables:
IMAGE_ARCH: alpine
dependencies: build-image-stretch-branch:
- build-node 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 jobs
publish-npm: publish-npm:
stage: publish
extends: extends:
- .build-node - .build-node
- .deploy-tags stage: publish
only:
- tags
dependencies: dependencies:
- build-node - build-node
@ -68,15 +98,6 @@ climate-pending:
script: script:
- cc-test-reporter before-build - 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: climate-success:
stage: status-post stage: status-post
extends: extends:
@ -99,27 +120,24 @@ codecov-success:
- make upload-codecov - make upload-codecov
github-pending: github-pending:
stage: status-pre
extends: extends:
- .build-curl - .build-curl
stage: status-pre
script: script:
- ${CI_PROJECT_DIR}/scripts/github-status.sh pending - ./scripts/github-status.sh pending
github-failure: github-failure:
stage: status-post
extends: extends:
- .build-curl - .build-curl
stage: status-post
when: on_failure when: on_failure
script: script:
- ${CI_PROJECT_DIR}/scripts/github-status.sh failure - ./scripts/github-status.sh failure
github-success: github-success:
stage: status-post
extends: extends:
- .build-curl - .build-curl
stage: status-post
when: on_success when: on_success
script: script:
- ${CI_PROJECT_DIR}/scripts/github-status.sh success - ./scripts/github-status.sh success

16
Dockerfile.alpine Normal file
View File

@ -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" ]

View File

@ -1,5 +1,4 @@
FROM node:12-stretch FROM node:12-stretch
# alpine may be smaller, but comes with a 10-15% perf hit
COPY package.json /app/package.json COPY package.json /app/package.json
COPY yarn.lock /app/yarn.lock COPY yarn.lock /app/yarn.lock

View File

@ -1,17 +1,27 @@
#! /bin/bash #! /bin/bash
IMAGE_PUSH="${1:---skip}" IMAGE_PUSH="${1:---skip}"
IMAGE_DEFAULT="${2:---skip}"
IMAGE_NAME="${CI_PROJECT_PATH}" IMAGE_NAME="${CI_PROJECT_PATH}"
IMAGE_TAG="$(echo "${CI_COMMIT_TAG:-${CI_COMMIT_REF_SLUG}}" | sed -r 's/[^-_a-zA-Z0-9]/-/g')" 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_SHORT="${IMAGE_NAME}:${IMAGE_TAG}"
IMAGE_FULL="${IMAGE_NAME}:${IMAGE_TAG}-${IMAGE_ARCH}"
echo "Building image: ${IMAGE_FULL}" echo "Building image: ${IMAGE_FULL}"
docker build -t "${IMAGE_FULL}" . docker build -f "Dockerfile.${IMAGE_ARCH}" -t "${IMAGE_FULL}" .
if [[ "${IMAGE_PUSH}" == "--push" ]]; if [[ "${IMAGE_PUSH}" == "--push" ]];
then then
echo "Pushing image: ${IMAGE_FULL}" echo "Pushing image: ${IMAGE_FULL}"
docker push "${IMAGE_FULL}" docker push "${IMAGE_FULL}"
fi fi
if [[ "${IMAGE_DEFAULT}" == "--default" ]];
then
echo "Pushing image (default architecture): ${IMAGE_SHORT}"
docker tag "${IMAGE_FULL}" "${IMAGE_SHORT}"
docker push "${IMAGE_SHORT}"
fi