From 5b0bc385e80b59b3045b6e4e20ba160e0b8f196c Mon Sep 17 00:00:00 2001 From: Siddharth Kannan Date: Sat, 21 Nov 2020 20:06:00 +0900 Subject: [PATCH 1/4] Add basic circle CI config --- .circleci/config.yml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..5d9c0dc --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,33 @@ +version: 2.1 +orbs: + shallow-checkout: datacamp/shallow-checkout@0.0.2 +# TODO: Add the shallow checkout orb +# orbs: +# ruby: circleci/ruby@0.1.2 + +jobs: + build: + machine: + image: ubuntu-2004:202010-01 + steps: + - checkout + - run: + name: Where are we? + command: pwd + - run: + name: Ensure docker exists + command: docker version + - run: + name: Build image + command: | + IMAGE_NAME=cutouts + IMAGE_TAG=latest + IMAGE=$IMAGE_NAME:$IMAGE_TAG + docker build -t $IMAGE . + docker image inspect $IMAGE + +workflows: + version: 2 + build_and_test: + jobs: + - build From a9e95c9c83e5fec82dafd64a6a539e2a6d8e6d5e Mon Sep 17 00:00:00 2001 From: Siddharth Kannan Date: Sat, 21 Nov 2020 20:20:21 +0900 Subject: [PATCH 2/4] Login and push to Docker Hub --- .circleci/config.yml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 5d9c0dc..93e7d8f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -18,13 +18,18 @@ jobs: name: Ensure docker exists command: docker version - run: - name: Build image + name: Login to DockerHub command: | - IMAGE_NAME=cutouts - IMAGE_TAG=latest + docker login -u $DOCKERHUB_USERNAME -p $DOCKERHUB_PASSWORD + - run: + name: Build and push image to DockerHub + command: | + IMAGE_NAME=icyflame2/cutouts + IMAGE_TAG=$CIRCLE_BRANCH-$CIRCLE_SHA1 IMAGE=$IMAGE_NAME:$IMAGE_TAG + docker build -t $IMAGE . - docker image inspect $IMAGE + docker push $IMAGE workflows: version: 2 From ec5a784a21a9081d6d0b7228ee4e8ae1f289bb3d Mon Sep 17 00:00:00 2001 From: Siddharth Kannan Date: Sat, 21 Nov 2020 20:26:31 +0900 Subject: [PATCH 3/4] Run tests before building the docker image --- .circleci/config.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 93e7d8f..67ef1a7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -17,6 +17,14 @@ jobs: - run: name: Ensure docker exists command: docker version + - run: + name: Run tests + command: | + curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-installer | bash + rbenv local + gem install bundler + bundle install + rails test - run: name: Login to DockerHub command: | From a83346bb894cbe517aa18a003d2861eb0d19c60d Mon Sep 17 00:00:00 2001 From: Siddharth Kannan Date: Sat, 21 Nov 2020 22:17:14 +0900 Subject: [PATCH 4/4] Add script to run tests before building docker image --- .circleci/config.yml | 8 -------- Dockerfile | 2 ++ run-tests.sh | 11 +++++++++++ 3 files changed, 13 insertions(+), 8 deletions(-) create mode 100755 run-tests.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index 67ef1a7..93e7d8f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -17,14 +17,6 @@ jobs: - run: name: Ensure docker exists command: docker version - - run: - name: Run tests - command: | - curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-installer | bash - rbenv local - gem install bundler - bundle install - rails test - run: name: Login to DockerHub command: | diff --git a/Dockerfile b/Dockerfile index a19bc24..2a0e037 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,4 +12,6 @@ COPY . /src WORKDIR /src RUN bundle install +RUN /src/run-tests.sh + ENTRYPOINT [ "/src/start-server.sh" ] diff --git a/run-tests.sh b/run-tests.sh new file mode 100755 index 0000000..323bb79 --- /dev/null +++ b/run-tests.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +if [ ! -d /node/bin ]; +then + echo "Node must be present at node/bin" + exit 42 +fi + +export PATH="$PATH:/node/bin" +cd /src +bundle exec rails test