Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] - CircleCi #28

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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
9 changes: 1 addition & 8 deletions t/dbconnection.t
Original file line number Diff line number Diff line change
Expand Up @@ -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();