CircleCI build failing normally, but passing locally and on SSH server

ruby

#1

Here’s my configuration:

# Ruby CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-ruby/ for more details
#
version: 2
general:
  branches:
    only:
     - feature/circleci
jobs:
  build:
    docker:
      # specify the version you desire here
      # - image: ruby:2.3.1
      
      # Specify service dependencies here if necessary
      # CircleCI maintains a library of pre-built images
      # documented at https://circleci.com/docs/2.0/circleci-images/
      - image: akashagarwal7/doubtfire-api
      - image: circleci/mysql:5.7
        environment:
        - MYSQL_ALLOW_EMPTY_PASSWORD=yes
        - MYSQL_DATABASE=doubtfire_staging
        - MYSQL_ALLOW_EMPTY_PASSWORD=true
        - MYSQL_ROOT_HOST=%
        - MYSQL_HOST=127.0.0.1

      # - image: circleci/postgres
    environment:
      MYSQL_ALLOW_EMPTY_PASSWORD: yes
      MYSQL_ROOT_PASSWORD: ''
      MYSQL_DATABASE: doubtfire_staging
      DF_STAGING_DB_ADAPTER: mysql2
      DF_STAGING_DB_HOST: 127.0.0.1
      DF_STAGING_DB_PORT: 3306
      DF_STAGING_DB_DATABASE: doubtfire_staging
      DF_STAGING_DB_USERNAME: root
      DF_STAGING_DB_PASSWORD: ''
      DF_SECRET_KEY_BASE: test_staging
      DF_SECRET_KEY_ATTR: test_staging
      DF_SECRET_KEY_DEVISE: test_staging
      BASH_ENV: /root/.bashrc

    steps:
      - checkout

      # Download and cache dependencies
      - restore_cache:
          keys:
          - v1-dependencies-{{ checksum "Gemfile.lock" }}
          # fallback to using the latest cache if no exact match is found
          - v1-dependencies-
      - run:
          name: Add texlive path to PATH env variable
          command: |
            echo 'export PATH=/tmp/texlive/bin/x86_64-linux:$PATH' >> $BASH_ENV
            source $BASH_ENV
            echo $PATH
            ln -s /tmp/texlive/bin/x86_64-linux/lualatex /usr/local/sbin

      - run:
          name: Install dependencies
          command: |
            bundle install --jobs=4 --retry=3 --path vendor/bundle --with staging

      - save_cache:
          paths:
            - ./vendor/bundle
          key: v1-dependencies-{{ checksum "Gemfile.lock" }}

      # Database setup
      - run: RAILS_ENV=staging bundle exec rake db:create
      - run: echo "n" | RAILS_ENV=staging bundle exec rake db:populate
      - run: which lualatex && RAILS_ENV=staging bundle exec rake test

Here’s the Dockerfile that I’m using:

FROM ubuntu:trusty
FROM ruby:2.3.1

RUN apt-get update
RUN apt-get install -y \
  build-essential \
  libpq-dev imagemagick \
  libmagickwand-dev \
  libmagic-dev \
  python-pygments \
  ghostscript

ENV MYSQL_ROOT_HOST=%

COPY ./texlive-install.sh /root/texlive-install.sh
COPY ./texlive.profile /root/texlive.profile

RUN chmod +x ~/texlive-install.sh
RUN ~/texlive-install.sh

Here’s one of the latest builds:
https://circleci.com/gh/akashagarwal7/doubtfire-api/128

In the project we’re using texlive and a tool called lualatex to generate PDFs. However, one of the tests which does generate PDFs is failing when I trigger the build normally, but not when I run rake test locally or when SSH’d into the server. How can I fix this issue? Any help would be much appreciated.


#2

There’s a few possible issues:

  • A server in your build is not ready to receive requests (e.g. MySQL)
  • Your failing build is missing env vars that you have in SSH

I notice also that your PostgreSQL image is commented out - is that deliberate?


#3

Hey @halfer, thank you for replying.
MySQL is receiving and serving requests, that isn’t a problem.
I didn’t set anything new in the SSH environment, simply ran the tests using rake test.

Yup, PostgreSQL is supposed to be commented out for now.


#4

How have you verified this?

No, but you probably have a .bash_profile or similar that sets things up for you (like PATH). I recommend looking at your build step logs to see what the error is.