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

build and deploy docker stack in Travis-CI #166

Merged
merged 2 commits into from
Jun 5, 2019
Merged

build and deploy docker stack in Travis-CI #166

merged 2 commits into from
Jun 5, 2019

Conversation

wittejm
Copy link
Contributor

@wittejm wittejm commented Jun 5, 2019

Expands the .travis.yml to build and deploy the Docker stack before running the pytest battery.

I'm making this a separate PR even though it's already feature of #160 . But this is pretty simple and standalone, and will be useful to have in the pipeline independent from finalizing the database features in PR #160.

This is a WIP and partial contribution to issue #165.

needs swarm init command which seems weird that it would be required but ok
using docker stack deploy and not docker-compose
@wittejm
Copy link
Contributor Author

wittejm commented Jun 5, 2019

(Moved this comment over from #160 )
Things I don't like about the current setup but don't have a preferred solution at the mo:

  • The .travis.yml copies .env.example to .env so that pipenv picks up the variables. I like this better than setting env variables in Travis because this way the variables for running pipenv are defined only once. But I'm looking into a more conventional solution.
  • After launching the docker stack, the script sleeps until the stack is fully spun up before running pytest. The in-line sleep loop in the travis file feels hacky? Is there some best practice for this?
  • The build now takes ~4 minutes or so because the docker image builds take a while. I think there is a way to cache unchanged image layers in Travis to speed this up. I'm starting to look into this.

@wittejm wittejm changed the title build and deploy docker stack build and deploy docker stack in Travis-CI Jun 5, 2019
@wittejm wittejm requested a review from NickSchimek June 5, 2019 00:40
.travis.yml Outdated
- docker-ce
before_install:
- docker swarm init
- cp ./.env.example ./.env
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be necessary. Can we add the environment variables to Travis CI?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure we can do it that way

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated and committed. Added the variables in Travis and everything works fine.

.travis.yml Outdated
install:
- pip install pipenv
- pipenv install
- make dev
before_script:
- counter=0 ; while ((counter < 10)) && ! pg_isready --host=$PGHOST --port=$PGPORT --dbname=$PGDATABASE ; do sleep 3; let counter=counter+1; done
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems this is a known issue in the travis community... travis-ci/travis-ci#4842

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, look like some folks there used the same sort of idling loop as a workaround. Nice to feel like this solution is validated. (seems like a problem that Travis should fix though :) )

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, agreed. We could always switch to Circle CI or another CI service if this causes issues in the future. I've used Circle CI with all my other projects, but thought I'd change things up a bit because I got a free sticker from them...

@NickSchimek
Copy link
Member

Thanks for doing this @wittejm . Are you able to add the environment vars to Travis Ci https://travis-ci.com/codeforpdx/recordexpungPDX/settings ?

@wittejm
Copy link
Contributor Author

wittejm commented Jun 5, 2019

@NickSchimek Yep, I was able to add env variables to Travis and now the .env file is unnecessary.

Copy link
Member

@NickSchimek NickSchimek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thanks for doing this @wittejm

@wittejm wittejm merged commit 38fdf2d into codeforpdx:master Jun 5, 2019
@wittejm wittejm deleted the travis-docker-build branch June 12, 2019 18:52
KentShikama pushed a commit that referenced this pull request Mar 20, 2020
build and deploy docker stack in Travis-CI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants