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
*.tmp
package-lock.json
yarn-error.log

View File

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

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
# 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" ]
CMD [ "--help" ]

View File

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