use circleci for docker builds

This commit is contained in:
2021-08-02 15:29:34 +03:00
committed by Stepan Usatiuk
parent a0567f60fa
commit ee642f970d

View File

@@ -1,122 +1,151 @@
version: 2 version: 2
jobs: jobs:
test-backend: test-backend:
docker: docker:
- image: circleci/node:14 - image: circleci/node:14
- image: circleci/mariadb:latest - image: circleci/mariadb:latest
environment: environment:
MYSQL_ALLOW_EMPTY_PASSWORD: "true" MYSQL_ALLOW_EMPTY_PASSWORD: "true"
MYSQL_DATABASE: photos_test MYSQL_DATABASE: photos_test
MYSQL_USER: photos MYSQL_USER: photos
MYSQL_PASSWORD: photos MYSQL_PASSWORD: photos
MYSQL_HOST: "localhost" MYSQL_HOST: "localhost"
working_directory: ~/photos
steps: working_directory: ~/photos
- checkout
- restore_cache: steps:
keys: - checkout
- backend-dependencies-{{ checksum "package.json" }}
- run: - restore_cache:
name: install backend deps keys:
command: npm i - backend-dependencies-{{ checksum "package.json" }}
- save_cache: - run:
paths: name: install backend deps
- node_modules command: npm i
key: backend-dependencies-{{ checksum "package.json" }}
- run: - save_cache:
name: test backend paths:
command: npm test - node_modules
key: backend-dependencies-{{ checksum "package.json" }}
test-frontend:
docker:
- image: circleci/node:14
working_directory: ~/photos/frontend
steps: - run:
- checkout: name: test backend
command: npm test
- restore_cache: test-frontend:
keys: docker:
- backend-dependencies-{{ checksum "package.json" }} - image: circleci/node:14
- run: working_directory: ~/photos/frontend
name: install backend deps
command: npm i
- save_cache: steps:
paths: - checkout:
- node_modules
key: backend-dependencies-{{ checksum "package.json" }}
- restore_cache: - restore_cache:
keys: keys:
- frontend-dependencies-{{ checksum "package.json" }} - backend-dependencies-{{ checksum "package.json" }}
- run: - run:
name: install frontend deps name: install backend deps
command: cd frontend && npm i command: npm i
- save_cache: - save_cache:
paths: paths:
- frontend/node_modules - node_modules
key: frontend-dependencies-{{ checksum "package.json" }} key: backend-dependencies-{{ checksum "package.json" }}
- run: - restore_cache:
name: test frontend keys:
command: cd frontend && npm test - frontend-dependencies-{{ checksum "package.json" }}
test-frontend-build: - run:
docker: name: install frontend deps
- image: circleci/node:14 command: cd frontend && npm i
working_directory: ~/photos/frontend
steps: - save_cache:
- checkout: paths:
- frontend/node_modules
key: frontend-dependencies-{{ checksum "package.json" }}
- restore_cache: - run:
keys: name: test frontend
- backend-dependencies-{{ checksum "package.json" }} command: cd frontend && npm test
- run: test-frontend-build:
name: install backend deps docker:
command: npm i - image: circleci/node:14
- save_cache: working_directory: ~/photos/frontend
paths:
- node_modules
key: backend-dependencies-{{ checksum "package.json" }}
- restore_cache: steps:
keys: - checkout:
- frontend-dependencies-{{ checksum "package.json" }}
- run: - restore_cache:
name: install frontend deps keys:
command: cd frontend && npm i - backend-dependencies-{{ checksum "package.json" }}
- save_cache: - run:
paths: name: install backend deps
- frontend/node_modules command: npm i
key: frontend-dependencies-{{ checksum "package.json" }}
- run: - save_cache:
name: test frontend paths:
command: cd frontend && npm run build - node_modules
key: backend-dependencies-{{ checksum "package.json" }}
- restore_cache:
keys:
- frontend-dependencies-{{ checksum "package.json" }}
- run:
name: install frontend deps
command: cd frontend && npm i
- save_cache:
paths:
- frontend/node_modules
key: frontend-dependencies-{{ checksum "package.json" }}
- run:
name: build frontend
command: cd frontend && npm run build
build:
machine:
image: ubuntu-2004:202107-01
working_directory: ~/photos
steps:
- checkout
- run:
name: log in to docker hub
command: echo "$DOCKER_PASSWORD" | docker login --username $DOCKER_USERNAME --password-stdin
- run:
name: install emulators
command: docker run --privileged --rm tonistiigi/binfmt --install all
- run:
name: create docker builder
command: docker buildx create --use
- run:
name: build and push to docker hub
#command: docker buildx build --push --platform linux/arm/v7,linux/arm64/v8,linux/amd64 --tag stepanusatiuk/photos:latest .
command: docker buildx build --push --platform linux/amd64 --tag stepanusatiuk/photos:latest .
workflows: workflows:
version: 2 version: 2
test: test-build:
jobs: jobs:
- test-backend - test-backend
- test-frontend
- test-frontend-build:
requires:
- test-frontend - test-frontend
- test-frontend-build:
requires:
- test-frontend
- build:
requires:
- test-backend
- test-frontend
- test-frontend-build