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

Create a Docker image on each commit and push to Quay #66

Open
wants to merge 8 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
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/.bundle
/.env
/.git
13 changes: 10 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ env:
- RAILS_ENV=test
- RAILS_ENV=test_logs

matrix:
fast_finish: true

before_install:
- gem install bundler -v 1.12.4

Expand All @@ -29,3 +26,13 @@ install:

before_script:
- cp config/database.yml.travis config/database.yml

jobs:
fast_finish: true
include:
- stage: ":ship: it to Quay.io"
sudo: required
dist: trusty
install: skip
before_script: skip
script: ./script/docker-build-and-push
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM ruby:2.3.1

LABEL maintainer Travis CI GmbH <[email protected]>

# throw errors if Gemfile has been modified since Gemfile.lock
RUN bundle config --global frozen 1

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY Gemfile /usr/src/app
COPY Gemfile.lock /usr/src/app

RUN bundle install

COPY . /usr/src/app

CMD RAILS_ENV=${RAILS_ENV-development} bundle exec rake db:migrate
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version: "2"
services:
migrations:
build: .
23 changes: 23 additions & 0 deletions script/docker-build-and-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

set -ev
app_name="migrations"
local_image="travismigrations_$app_name" # Docker Compose removes dashes and expects the name to end with the build app name
quay_image=quay.io/travisci/travis-migrations;

docker-compose build "$app_name";
docker login -u="$QUAY_ROBOT_HANDLE" -p="$QUAY_ROBOT_TOKEN" quay.io;
docker images;

docker tag $local_image $quay_image:$TRAVIS_BRANCH;
docker push $quay_image:$TRAVIS_BRANCH;

docker tag $local_image $quay_image:${TRAVIS_COMMIT:0:7};
docker push $quay_image:${TRAVIS_COMMIT:0:7};

if [ ${TRAVIS_BRANCH} = "master" ]; then
docker tag $local_image $quay_image:latest;
docker push $quay_image:$TRAVIS_BRANCH;
fi

exit 0;