Skip to content
This repository was archived by the owner on Jun 10, 2019. It is now read-only.

Commit 93e1286

Browse files
RickRalexspence
RickR
authored andcommitted
Builds/publishes docker container in travis
1 parent 7567f19 commit 93e1286

File tree

5 files changed

+60
-5
lines changed

5 files changed

+60
-5
lines changed

.env

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
COMPOSE_PROJECT_NAME=operationcodefrontend
12
PORT=4000
23
GA_TRACKER_ID=UA-75642413-1
34
NODE_ENV=development

.travis.yml

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
language: node_js
2-
node_js:
3-
"node"
4-
cache: yarn
1+
# Since we build and test in Docker we dont
2+
# need node at build time
3+
language: c
4+
5+
#cache: yarn
6+
#sudo: required
7+
#
8+
#install: true
9+
10+
services:
11+
- docker
12+
13+
script:
14+
- make travis
15+
- if [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_BRANCH" == "master" ]; then make publish; fi

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ RUN npm install
1313
COPY . /usr/src/app
1414

1515
# Build and optimize react app
16-
RUN npm run build
16+
RUN yarn run build
1717

1818
EXPOSE 8080
1919

Makefile

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
NODE_CONTAINER := web
2+
3+
.PHONY: build
4+
build:
5+
docker-compose build
6+
7+
.PHONY: test
8+
test:
9+
docker-compose run ${NODE_CONTAINER} bash -c 'cd /usr/src/app && yarn test'
10+
11+
publish: build
12+
bin/publish
13+
14+
travis: build test
15+

bin/publish

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bash
2+
3+
# Publishes the most recent web container to docker hubs repo.
4+
# This script assumes docker push works.
5+
# You must set up docker push on your own.
6+
7+
set -eu
8+
9+
DOCKER_REPO="operationcode/operationcode_frontend"
10+
11+
ROOT_DIR="$(dirname $0)/.."
12+
cd $ROOT_DIR
13+
14+
PROJECT_NAME=$(grep COMPOSE_PROJECT_NAME $ROOT_DIR/.env | cut -d= -f2)
15+
16+
IMAGE_NAME="${PROJECT_NAME}_web"
17+
IMAGE_ID=$(docker images $IMAGE_NAME:latest --format "{{.ID}}")
18+
19+
if [ -n "$DOCKER_USERNAME" ]; then echo "Found username"; fi
20+
if [ -n "$DOCKER_PASSWORD" ]; then echo "Found password"; fi
21+
22+
if [ -n "$DOCKER_USERNAME" ] && [ -n "$DOCKER_PASSWORD" ]; then
23+
echo "Logging in using ENV creds"
24+
docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
25+
fi
26+
27+
docker tag $IMAGE_ID $DOCKER_REPO
28+
docker push $DOCKER_REPO

0 commit comments

Comments
 (0)