From e6c180b1856ba5adf9be3dded076143f29c34e5d Mon Sep 17 00:00:00 2001 From: Daniel Cesario Date: Sat, 9 Sep 2017 12:54:01 +0200 Subject: [PATCH 1/6] Removing not relevant database test --- t/dbconnection.t | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) 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(); From 822cfaae8bd55398ab2670a15a3f3af93ee0858a Mon Sep 17 00:00:00 2001 From: Daniel Cesario Date: Sat, 9 Sep 2017 13:44:36 +0200 Subject: [PATCH 2/6] swaping docker layers (Dockerfile was broken) docker `COPY` was introducing files using root user, so hypnotoad was not able to create the PID files on `./script` --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index f925f38..81c9351 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,12 +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 - USER 1001 EXPOSE 8080 ENTRYPOINT ["/opt/project-x/entrypoint.sh"] From bf83eabff46fdd95fce2e75db2ce262404e3a500 Mon Sep 17 00:00:00 2001 From: Daniel Cesario Date: Sat, 9 Sep 2017 13:46:15 +0200 Subject: [PATCH 3/6] forcing morbo to use IPv4 binds (Morbo execution was broken) the base builddep stretch image comes with IPv6 disabled so morbo was failing to bind. So just using IPv4. --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 8ef6a5b636ea959136368147288e24b2926ea0c5 Mon Sep 17 00:00:00 2001 From: Daniel Cesario Date: Sat, 9 Sep 2017 15:20:14 +0200 Subject: [PATCH 4/6] Adding Circle ci config --- .circleci/config.yml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..be0170a --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,34 @@ +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 \ No newline at end of file From c0b8cfabd7b418842b829689d269983f155eff33 Mon Sep 17 00:00:00 2001 From: Daniel Cesario Date: Sun, 10 Sep 2017 01:36:22 +0200 Subject: [PATCH 5/6] Docker Image - CircleCI Automatic Push --- .circleci/config.yml | 30 +++++++++++++++++++++++++++++- Makefile | 7 +++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index be0170a..1b56bf6 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -31,4 +31,32 @@ jobs: - run: name: Run Tests - command: carton exec prove -lv \ No newline at end of file + 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/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) From 93aaf14b98ce8177de121dfa3e50e6148b0beb8c Mon Sep 17 00:00:00 2001 From: Daniel Cesario Date: Sun, 10 Sep 2017 16:28:48 +0200 Subject: [PATCH 6/6] adjusting dockerfile for ephimeral Openshift User --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 81c9351..9698eea 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,8 @@ 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/ + && chown -R xman:xman /opt/project-x/ \ + && chmod 0757 /opt/project-x/script/ USER 1001 EXPOSE 8080