addons-server/.circleci/config.yml

117 строки
3.5 KiB
YAML

# These environment variables must be set in CircleCI UI
#
# DOCKERHUB_REPO - docker hub repo, format: <username>/<repo>
# DOCKER_USER - Login user for docker hub
# DOCKER_PASS - Login password for docker hub user
version: 2.1
references:
defaults-release: &defaults-release
machine:
image: ubuntu-2004:current
working_directory: "~/addons-server"
commands:
make_release:
description: "Builds and pushes a Docker image"
parameters:
push:
type: boolean
default: false
image_tag:
type: string
default: "latest"
steps:
- run:
name: Set environment variables
command: |
echo 'export DOCKER_VERSION=<< parameters.image_tag >>' >> $BASH_ENV
echo 'export DOCKER_COMMIT=$CIRCLE_SHA1' >> $BASH_ENV
echo 'export VERSION_BUILD_URL=$CIRCLE_BUILD_URL' >> $BASH_ENV
echo 'export BUILDX_BAKE_METADATA_FILE=metadata.json' >> $BASH_ENV
echo 'export DOCKER_PROGRESS=plain' >> $BASH_ENV
- when:
condition: << parameters.push >>
steps:
- run:
name: Push mode activated
command: |
# CircleCI casts boolean paramters as binary 0/1 integers
# when they are passed via environment: variables.
# CircleCI will not reasonably work with conditional expressions
# Our Makefile is expecting any non-empty value to indicate a push.
# So we must explicitly set the value
# only if the "condition" passes at the configuration level
echo 'export DOCKER_PUSH=true' >> $BASH_ENV
- run:
name: Create .env and version.json files
command: |
# We must defined a .env file for the docker-compose config
# The values will be inferred by what is set in the bash env above.
make -f Makefile-os setup
- run:
name: Docker build config
command: |
make docker_compose_config
cat $BASH_ENV
- run:
name: Build docker image (push = << parameters.push >>)
command: |
docker version
docker login -u "${DOCKERHUB_USER}" -p "${DOCKERHUB_PASS}"
make -f Makefile-os build_docker_image
- when:
condition: << parameters.push >>
steps:
- run:
name: Print Digest
command: |
cat ${BUILDX_BAKE_METADATA_FILE} | jq -r '.web."containerimage.digest"'
jobs:
# Add to a workflow, if you want to test the docker build in circleci
build-image:
<<: *defaults-release
steps:
- checkout
- make_release:
image_tag: circle-${CIRCLE_BRANCH}
# explicitly don't push
push: false
release-master:
<<: *defaults-release
steps:
- checkout
- make_release:
image_tag: latest
push: true
release-tag:
<<: *defaults-release
steps:
- checkout
- make_release:
image_tag: "${CIRCLE_TAG}"
push: true
workflows:
version: 2
default-workflow:
jobs:
# Uncomment if you want to test the docker build
# - build-image
- release-master:
filters:
branches:
only: master
tags:
ignore: /.*/
- release-tag:
filters:
tags:
only: /.*/
branches:
ignore: /.*/