diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..1b56bf6 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,62 @@ +version: 2 +jobs: + + build: + working_directory: /opt/project-x + docker: + - image: perl:5.24 + - image: postgres:9.6-alpine + environment: + DB_HOST: localhost + steps: + - run: cpanm Carton + + - checkout + + # Download and cache dependencies + - restore_cache: + keys: + - dependency-cache-{{ checksum "cpanfile.snapshot" }} + # fallback to using the latest cache if no exact match is found + - dependency-cache- + + - run: + name: Install Dependencies + command: carton install + + - save_cache: + key: dependency-cache-{{ checksum "cpanfile.snapshot" }} + paths: + - ./local + + - run: + name: Run Tests + command: carton exec prove -lv + + - setup_remote_docker + + - run: + name: Install Docker client + when: on_success + command: | + if [ "${CIRCLE_BRANCH}" == "circle-ci" ]; then + set -x + VER="17.03.0-ce" + curl -L -o /tmp/docker-$VER.tgz https://get.docker.com/builds/Linux/x86_64/docker-$VER.tgz + tar -xz -C /tmp -f /tmp/docker-$VER.tgz + mv /tmp/docker/* /usr/bin + else + echo "Not master branch so no docker required" + fi + + - run: + name: Build and Push Docker Image + when: on_success + shell: /bin/bash + command: | + if [ "${CIRCLE_BRANCH}" == "circle-ci" ]; then + docker login -u ${DOCKER_LOGIN} -p ${DOCKER_PASSWORD} + make update push_ci + else + echo "Not master branch, So no push to DockerHub" + fi diff --git a/Dockerfile b/Dockerfile index f925f38..9698eea 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,11 +9,12 @@ COPY ./cpanfile cpanfile RUN carton install +COPY ./ /opt/project-x + RUN groupadd -r xman -g 1001 \ && useradd -u 1001 -r -g xman -d /opt/project-x/ -s /sbin/nologin -c "Docker image user" xman \ - && chown -R xman:xman /opt/project-x/ - -COPY ./ /opt/project-x + && chown -R xman:xman /opt/project-x/ \ + && chmod 0757 /opt/project-x/script/ USER 1001 EXPOSE 8080 diff --git a/Makefile b/Makefile index e25869d..07097bb 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,9 @@ RELEASE_VERSION ?= latest LOCAL_IMAGE := $(NAME):$(RELEASE_VERSION) REMOTE_IMAGE := $(NAMESPACE)/$(LOCAL_IMAGE) +CIRLE_SHA1 ?= '' +REMOTE_IMAGE_CI := $(NAMESPACE)/$(NAME):$(CIRCLE_SHA1) + # Environment General Settings ENVIRONMENT ?= devel SECRETS_URL ?= 'https://www.dropbox.com/s/p9x87ffn19rdr0c/secrets.mk.gpg' @@ -92,6 +95,10 @@ tag: ## Tag IMAGE_NAME push: tag ## Push to the docker registry docker push $(REMOTE_IMAGE) +push_ci: + docker tag $(LOCAL_IMAGE) $(REMOTE_IMAGE_CI) + docker push $(REMOTE_IMAGE_CI) + pull: ## Pull the docker from the Registry docker pull $(REMOTE_IMAGE) diff --git a/entrypoint.sh b/entrypoint.sh index cef1a83..b82104e 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,7 +1,7 @@ #!/bin/bash if [ ${ENVIRONMENT} == "devel" ]; then - exec carton exec morbo -l http://[::]:8080 "$@" + exec carton exec morbo -l http://[0.0.0.0]:8080 "$@" else exec carton exec hypnotoad -f "$@" fi diff --git a/t/dbconnection.t b/t/dbconnection.t index dd68a7e..9c4a7c4 100644 --- a/t/dbconnection.t +++ b/t/dbconnection.t @@ -9,14 +9,7 @@ is $pg->dsn, "dbi:Pg:dbname=postgres;host=$ENV{'DB_HOST'};port=5432", 'r is $pg->username, "$ENV{'DB_USER'}", 'right username'; is $pg->password, "$ENV{'DB_PASS'}", 'right password'; -my $options = {AutoCommit => 1, - AutoInactiveDestroy => 1, - PrintError => 0, - RaiseError => 1 - }; - -is_deeply $pg->options, $options, 'right options'; - +#Check database connection ok $pg->db->ping, 'connected'; done_testing();