docker-backuppc/.circleci/config.yml
2020-03-01 17:46:21 +01:00

89 lines
2.8 KiB
YAML

version: 2
workflows:
version: 2
main-pipeline:
jobs:
- build-n-test:
filters:
branches:
only: /.*/
tags:
only: /.*/
- deploy:
requires:
- build-n-test
filters:
branches:
only: /^(master|4|3)$/
tags:
only: /.*/
- trigger-dockerhub:
requires:
- build-n-test
filters:
branches:
only: master
jobs:
build-n-test:
machine: true
steps:
- checkout
- run:
name: Build container
command: |
docker pull adferrand/backuppc || true
docker build --pull --cache-from adferrand/backuppc -t adferrand/backuppc .
- run:
name: Test container (unit tests)
command: |
mkdir -p ./bin
curl -fsSL https://goss.rocks/install | GOSS_DST=./bin sh
GOSS_PATH=./bin/goss GOSS_SLEEP=2 GOSS_FILES_PATH=./tests ./bin/dgoss run adferrand/backuppc
- run:
name: Test container (integration tests)
command: |
docker run --name backuppc-integration --detach -p 8080:8080 adferrand/backuppc
sleep 5
output=`curl http://backuppc:password@localhost:8080/BackupPC_Admin`
echo "Expect the backupp configuration page without errors"
grep "The servers PID is" <(echo $output)
docker rm -f backuppc-integration
- run:
name: Save container
command: |
mkdir -p workspace
docker save adferrand/backuppc | gzip -c -1 > workspace/docker-backuppc.tar.gz
- persist_to_workspace:
root: workspace
paths:
- docker-backuppc.tar.gz
deploy:
machine: true
steps:
- attach_workspace:
at: /tmp/workspace
- run:
name: Load container
command:
docker load < /tmp/workspace/docker-backuppc.tar.gz
- run:
name: Login to DockerHub
command:
echo "${DOCKER_PASS}" | docker login -u ${DOCKER_USER} --password-stdin
- deploy:
name: Deploy to DockerHub
command: |
if [ ${CIRCLE_BRANCH} = master ]; then DOCKER_TAG=latest; else DOCKER_TAG=${CIRCLE_TAG:-${CIRCLE_BRANCH}}; fi
echo ${DOCKER_TAG}
docker tag adferrand/backuppc adferrand/backuppc:${DOCKER_TAG}
docker push adferrand/backuppc:${DOCKER_TAG}
trigger-dockerhub:
machine: true
steps:
- deploy:
name: Trigger DockerHub build
command: |
curl -H "Content-Type: application/json" --data '{"docker_tag": "master"}' -X POST https://registry.hub.docker.com/u/adferrand/backuppc/trigger/463a9d6d-4293-42bb-861f-72e450a22656/