From 621d35a88ad2bad612dd1195330a8c249fd26cac Mon Sep 17 00:00:00 2001 From: Yen-chi Chen Date: Mon, 31 Jul 2017 09:56:42 -0500 Subject: [PATCH] Build production image (#250) * Build production image * seperate the tool script --- .circleci/config.yml | 38 ++++++++++++++++--------- .circleci/docker-compose-production.yml | 13 +++++++++ .circleci/prepare-docker-compose.sh | 13 +++++++++ 3 files changed, 51 insertions(+), 13 deletions(-) create mode 100644 .circleci/docker-compose-production.yml create mode 100755 .circleci/prepare-docker-compose.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index b4bc906c2..68537142e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -22,19 +22,8 @@ jobs: steps: - checkout - run: - name: Install Docker client - command: | - 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 - - run: - name: Install Docker Compose - command: | - set -x - curl -L https://github.com/docker/compose/releases/download/1.13.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose - chmod +x /usr/local/bin/docker-compose + name: Install Docker client & Docker Compose + command: ./.circleci/prepare-docker-compose.sh - setup_remote_docker - run: name: Build Docker Image @@ -56,6 +45,25 @@ jobs: curl --user ${CIRCLE_API_TOKEN_FOR_DEPLOY}: \ --data build_parameters[CIRCLE_JOB]=build \ https://circleci.com/api/v1.1/project/github/mark86092/goodjob-deploy-ci/tree/www-stage + build_production_docker: + working_directory: ~/app + docker: + - image: buildpack-deps + steps: + - checkout + - run: + name: Install Docker client & Docker Compose + command: ./.circleci/prepare-docker-compose.sh + - setup_remote_docker + - run: + name: Build Docker Image + command: docker-compose -f .circleci/docker-compose-production.yml build + - run: + name: Retag + command: docker tag 059402281999.dkr.ecr.ap-northeast-1.amazonaws.com/goodjob/goodjobshare:production 059402281999.dkr.ecr.ap-northeast-1.amazonaws.com/goodjob/goodjobshare:production-${CIRCLE_SHA1} + - run: docker login -u $AWS_DOCKER_USER -p $AWS_DOCKER_PASS https://059402281999.dkr.ecr.ap-northeast-1.amazonaws.com + - run: docker-compose -f .circleci/docker-compose-production.yml push + - run: docker push 059402281999.dkr.ecr.ap-northeast-1.amazonaws.com/goodjob/goodjobshare:production-${CIRCLE_SHA1} workflows: version: 2 build_and_test: @@ -65,6 +73,10 @@ workflows: filters: branches: only: master + - build_production_docker: + filters: + branches: + only: master - deploy-stage: requires: - build diff --git a/.circleci/docker-compose-production.yml b/.circleci/docker-compose-production.yml new file mode 100644 index 000000000..c91612c70 --- /dev/null +++ b/.circleci/docker-compose-production.yml @@ -0,0 +1,13 @@ +version: "2" +services: + node: + image: 059402281999.dkr.ecr.ap-northeast-1.amazonaws.com/goodjob/goodjobshare:production + build: + context: .. + dockerfile: docker/Dockerfile + args: + - API_HOST=https://tranquil-fortress-92731.herokuapp.com + - CONTENTFUL_API_HOST=https://content.goodjob.life + - FACEBOOK_APP_ID=1750216878594984 + ports: + - 42000:3001 diff --git a/.circleci/prepare-docker-compose.sh b/.circleci/prepare-docker-compose.sh new file mode 100755 index 000000000..a6d808bbc --- /dev/null +++ b/.circleci/prepare-docker-compose.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +set -x + +# install docker +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 + +# prepare docker-compose +curl -L https://github.com/docker/compose/releases/download/1.13.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose +chmod +x /usr/local/bin/docker-compose