dawarich/.circleci/config.yml
2025-02-02 22:18:41 +01:00

121 lines
3 KiB
YAML

version: 2.1
executors:
docker-executor:
machine:
image: ubuntu-2204:current
orbs:
ruby: circleci/ruby@2.1.4
browser-tools: circleci/browser-tools@1.4.8
jobs:
test:
docker:
- image: cimg/ruby:3.3.4
environment:
RAILS_ENV: test
- image: cimg/postgres:13.3-postgis
environment:
POSTGRES_USER: postgres
POSTGRES_DB: test_database
POSTGRES_PASSWORD: mysecretpassword
- image: redis:7.0
steps:
- checkout
- run:
name: Install Bundler
command: gem install bundler
- run:
name: Bundle Install
command: bundle install --jobs=4 --retry=3
- run:
name: Database Setup
command: |
bundle exec rails db:create
bundle exec rails db:schema:load
- run:
name: Run RSpec tests
command: bundle exec rspec
- store_artifacts:
path: coverage
build-and-push:
docker:
- image: cimg/base:current
environment:
DOCKER_CLI_EXPERIMENTAL: enabled
steps:
- checkout
- run:
name: Set branch variable
command: |
if [ -z "$CIRCLE_BRANCH" ]; then
echo 'export BUILD_BRANCH=master' >> $BASH_ENV
else
echo "export BUILD_BRANCH=$CIRCLE_BRANCH" >> $BASH_ENV
fi
- setup_remote_docker:
version: 20.10.24
docker_layer_caching: true
- run:
name: Install dependencies
command: npm install
- run:
name: Login to Docker Hub
command: echo "$DOCKERHUB_TOKEN" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin
- run:
name: Set Docker tags
command: |
if [[ -n "$CIRCLE_TAG" ]]; then
VERSION="${CIRCLE_TAG}"
else
VERSION="latest"
fi
TAGS="freikin/dawarich:${VERSION}"
if [[ "$CIRCLE_TAG" =~ rc ]]; then
TAGS="${TAGS},freikin/dawarich:rc"
else
TAGS="${TAGS},freikin/dawarich:latest"
fi
echo "export DOCKER_TAGS=\"$TAGS\"" >> $BASH_ENV
- run:
name: Build and push (arm64)
command: |
docker buildx create --use
docker buildx build --platform linux/arm64 \
--file ./docker/Dockerfile.dev \
--tag freikin/dawarich:${VERSION} \
--push .
- run:
name: Build and push (other architectures)
command: |
docker buildx build --platform linux/amd64,linux/arm/v7,linux/arm/v6 \
--file ./docker/Dockerfile.dev \
--tag freikin/dawarich:${VERSION} \
--push .
workflows:
version: 2
build-and-test:
jobs:
- test
- build-and-push:
filters:
branches:
only:
- master
- dev
tags:
only: /.*/ # Match ANY tag name