うちのいぬ Tech Blog

Tech Blog of Uchinoinu/My dog

How to use new wercker to deploy to Heroku

日本語はこちら uchinoinu.hatenablog.jp

What I want to do

local --(git push origin master)--> bitbucket --> wercker --(passしたら)--> heroku

Problems

wercker is difficult to use for me

f:id:susanne:20160615083256p:plain

Recently, wercker is really changeable.

Free plan is wonderful! but difficult to use.

Less documents. Lots of articles of last version wercker, so difficult to find valid one in internet.

So for catching up, read blog and twitter

Now(15/jun/2016), wercker use docker, has workflow, pipeline system.

New wercker.yml

Minimum one.

In build pipeline, run bundle install, set postgres, run rspec, send notification to slack. In deploy pipeline, deploy to heroku, run rake db:migrate, send noti to slack.

box: ruby
build:
    steps:
        - bundle-install

        - rails-database-yml:
            service: postgresql-docker

        - script:
            name: echo ruby information
            code: |
                echo "ruby version $(ruby --version) running"
                echo "from location $(which ruby)"
                echo -p "gem list: $(gem list)"

        - script:
            name: rspec
            code: bundle exec rspec

    after-steps:
        # notify to Slack
        - wantedly/pretty-slack-notify:
            webhook_url: $SLACK_WEBHOOK_URL_BUILD
            channel: $SLACK_WEBHOOK_CHANNEL_BUILD

deploy:
    steps:
      - heroku-deploy:
          install-toolbelt: true
          key: $HEROKU_KEY
          key-name: HEROKU_KEY_PAIR
          user: $HEROKU_USER
          app-name: $HEROKU_APP_NAME
      - script:
          name: Update database
          code: heroku run rake db:migrate --app $HEROKU_APP_NAME
    after-steps:
      - wantedly/pretty-slack-notify:
          webhook_url: $SLACK_WEBHOOK_URL_DEPLOY
          channel: $SLACK_WEBHOOK_CHANNEL_DEPLOY

What I took much time

What I should create

f:id:susanne:20160615084453p:plain

Some articles say, you should create step, but application is valid in my case.

Only build pipeline, where is deploy?

Though deploy pipeline is written in wercker.yml, only build was run in wercker default setting.

wercker has workflow system, workflow is composed by pipelines.

pipeline means build or deploy in wercker.yml.

In default setting of wercker, no deploy was set in workflow. So you should set deploy.

f:id:susanne:20160615084717p:plain

how to set new pipeline

tap Manage Workflow.

f:id:susanne:20160615085249p:plain

You land at setting page of workflow and pipeline. f:id:susanne:20160615085344p:plain f:id:susanne:20160615085413p:plain

Here you can add new pipeline.

New pipeline setting page. f:id:susanne:20160615085513p:plain

Set name, figure pipeline name in wercker, set when to run.

(In next page, set scm noti, you can see result of CI in Github or Bitbucket)

f:id:susanne:20160615085808p:plain

Adding new pipeline, you can add the one to workflow.

Then flow of build to deploy is completed.

Environment Variables are unreadable

Setting variables for whole app, sometimes unreadable.

Setting var in each pipeline is better.

Could not deploy to Heroku

Trust official reference. devcenter.wercker.com

Task

after-step is not included on screen of wercker.(Because after-step....) Not so clean. So I want to set new pipeline of it.

Reference

qiita.com