Merge branch 'registry-credentials' into 'master'

Refactor CI

See merge request timvisee/send!26
This commit is contained in:
Tim Visée 2022-09-14 14:37:33 +00:00
commit 9e188bc76c

View file

@ -1,10 +1,22 @@
image: "node:15-slim"
stages: stages:
- test - test
- artifact
- release - release
# Build Send, run npm tests
test:
stage: test
image: "node:15-slim"
only:
- api
- branches
- chat
- merge_requests
- pushes
- schedules
- tags
- triggers
- web
before_script: before_script:
# Install dependencies # Install dependencies
- apt-get update - apt-get update
@ -16,90 +28,44 @@ before_script:
- sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' - sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
- apt-get update - apt-get update
- apt-get install -y google-chrome-stable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf libxss1 --no-install-recommends - apt-get install -y google-chrome-stable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf libxss1 --no-install-recommends
# Build Send, run npm tests
test:
stage: test
script: script:
- npm ci - npm ci
- npm run lint - npm run lint
- npm test - npm test
# Build Docker image, export Docker image artifact
artifact-docker:
stage: artifact
image: docker:latest
needs: []
services:
- docker:dind
variables:
IMG_FILE: "send:git-$CI_COMMIT_SHORT_SHA.tar"
IMG_NAME: "send:git-$CI_COMMIT_SHORT_SHA"
before_script: []
script:
- docker build -t $IMG_NAME .
- docker image save -o $IMG_FILE $IMG_NAME
artifacts:
name: artifact-docker
paths:
- $IMG_FILE
expire_in: 1 week
# Release public Docker image for the master branch
release-docker-master:
stage: release
image: docker:latest
dependencies:
- artifact-docker
services:
- docker:dind
only:
- master
variables:
IMG_IMPORT_FILE: "send:git-$CI_COMMIT_SHORT_SHA.tar"
IMG_IMPORT_NAME: "send:git-$CI_COMMIT_SHORT_SHA"
IMG_NAME: "registry.gitlab.com/timvisee/send:master-$CI_COMMIT_SHORT_SHA"
before_script: []
script:
# Login in to registry
- 'docker login registry.gitlab.com -u $DOCKER_USER -p $DOCKER_PASS'
# Load existing, retag for new image images
- docker image load -i $IMG_IMPORT_FILE
- docker tag $IMG_IMPORT_NAME $IMG_NAME
# Publish tagged image
- docker push $IMG_NAME
- 'echo "Docker image artifact published, available as:" && echo " docker pull $IMG_NAME"'
# Release public Docker image for a version tag
release-docker: release-docker:
stage: release stage: release
image: docker:latest image: docker:latest
dependencies:
- artifact-docker
services: services:
- docker:dind - docker:dind
only: only:
- /^v(\d+\.)*\d+$/ - api
variables: - branches
IMG_IMPORT_FILE: "send:git-$CI_COMMIT_SHORT_SHA.tar" - chat
IMG_IMPORT_NAME: "send:git-$CI_COMMIT_SHORT_SHA" - merge_requests
IMG_NAME: "registry.gitlab.com/timvisee/send:$CI_COMMIT_REF_NAME" - pushes
IMG_NAME_LATEST: "registry.gitlab.com/timvisee/send:latest" - schedules
before_script: [] - tags
- triggers
- web
script: script:
# Login in to registry - docker login "$CI_REGISTRY" -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD"
- 'docker login registry.gitlab.com -u $DOCKER_USER -p $DOCKER_PASS' - docker build -t send .
- |
# Load existing, retag for new image images if [ "$CI_PIPELINE_SOURCE" == "merge_request_event" ]; then
- docker image load -i $IMG_IMPORT_FILE IMAGE_NAMES="$CI_REGISTRY_IMAGE/mr:$CI_MERGE_REQUEST_IID"
- docker tag $IMG_IMPORT_NAME $IMG_NAME elif [ "$CI_COMMIT_TAG" != "" ]; then
- docker tag $IMG_IMPORT_NAME $IMG_NAME_LATEST IMAGE_NAMES="$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG $CI_REGISTRY_IMAGE:latest"
else
# Publish tagged image IMAGE_NAMES="$CI_REGISTRY_IMAGE/$CI_COMMIT_BRANCH:$CI_COMMIT_SHORT_SHA"
- docker push $IMG_NAME fi
- docker push $IMG_NAME_LATEST - |
for image in $IMAGE_NAMES; do
- 'echo "Docker image artifact published, available as:" && echo " docker pull $IMG_NAME_LATEST" && echo " docker pull $IMG_NAME"' docker tag send $image
docker push $image
done
- |
echo "Container image pushed. You can pull it with";
for image in $IMAGE_NAMES; do
echo "docker pull $image"
done