Jim Lynch Codes
  • Blog
  • About Jim

Writings about one coder's stories & experiences.

Creating A CNAME Domain File On A Travis CI Server

1/19/2017

0 Comments

 
This is an interesting problem that I just solved yesterday- creating a CNAME file from a Travis CI server.

The Issue

My finished site that was built and published from Travis CI server was giving me a 404 page.
Picture
Well, when I went into the settings for the Github repository and added my custom domain name everything worked!
Picture
However, I'm trying to set up continuous deployment with Travis CI where the CI server runs the deployment script to host the files. So, I needed an automated way to create this CNAME file. 

One Possible Solution

Luckily, there's many simple ways of creating a file with some text in BASH. The one that I ended up incorporating makes use of the echo command. The contents of the file is just a string being echoes, and we then redirect that result (using the > symbol) into a file named CNAME. The final code would look like this:
echo 'ng-nj.com' > ./dist/CNAME

An Example Travis Config And Deploy Script

Here is an example of a Travis.yml file. It first installs the environment, npm, and all that stuff. Then we run the unit tests (gulp test) and build the project (gulp build). If those finish successfully then it will run the deploy.sh file.
sudo: true
language: node_js
node_js:
- 5.11.1
before_install:
- if [ "${TRAVIS_NODE_VERSION}" == "0.8" ]; then npm install -g npm@2.11.1; fi
install:
- node --version
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- pwd
- npm install
- npm install bower
- bower install
script:
- ls
- gulp test
- gulp build
after_script:
- echo ran script
after_success:
- git config credential.helper "store --file=.git/credentials"
- echo "https://${GH_TOKEN}:@github.com/ng-nj.org.git" > .git/credentials
- echo 'Success'
- ls
- git config --global user.email "your.email@emailhost.com"
- git config --global user.name "YourGithubHandle"
- bash ./deploy.sh
- echo Sent to gh-pages!
matrix:
  fast_finish: true
notifications:
  irc:
    channels:
    - irc.freenode.orgi#unshift
    on_success: change
    on_failure: change
env:
  global:
  - GH_REF: github.com/ng-nj/ng-nj.org.git
  - secure: SYSJERymKf2YiJPculxBGF2C7g2CA9aSZNTYorCHZUpGjsooJGZnw4CFrioK9ElhIQNAZV/dne9CMNw531w8/bB2VOMvXDS26m0lSJZTN86mKpz5+IT7uQ+96ObUpBslxZ8J2+SiYAwvjXKmfrFIYNuT/cwUHAgDEARRdVZbMLfGupIszD9H0whMUnZQEimC75IyY7GB+35ZJov3OgpTsN4LQfkhwNkzX7J3vt2hGrO92hgtvAO7eINLvtTycaqQNpDjxr6dv5XEzPm8M3YqDOEjv/BFDuG6hGnORe15SPiPo3/kOHKv/fN+SbjSsk/5zIxCxUmIWQTQMhtDWyoBaUesKQO8PCKwMIbjxZh3xnA4fJ/QkVJUe6xz8yzsdE184r/n97Rv9RkcZCY7iIGbp17hpavgfooJ0qFhfgPyU18XaxAYiK0SFie+XLXEAm6BMWRmjASNZ0YEShgzbjzsRfhohF2teGOxh4DMce4UnCIl28brXMUjo1j7ptLMls6C/zjU8h94r/q5rsISzkkTQjdJRlp4mLyeBbqW/tVef5VSgkFnDKy2qScpG6n0LYQW1bAHv/NnB0/80jZD+JpeuAwUjvSjFpWWFC0b4iwLuiziRAQFXw6KUhNBX+7cho9k03Erl543qFXhothQOSmixF2Co1GeaH9Ps1DKuQk9O5M=
The code below is the full deploy.sh script. In the very first line we can see the new echo command that creates the CNAME. Then we simply push the files over to where our public project is being hosted (in this case gh-pages branch on Github).
echo 'ng-nj.com' > ./dist/CNAME
git push origin :gh-pages

git add --all
git commit -m 'commit from ontario'
git subtree push --prefix dist/ origin gh-pages

echo "Deployed successfully."  
0 Comments

Your comment will be posted after it is approved.


Leave a Reply.

    ​Author

    Picture
    The posts on this site are written and maintained by Jim Lynch. About Jim...
    Picture
    Follow @JimLynchCodes
    Follow @JimLynchCodes

    Categories

    All
    Actionscript 3
    Angular
    AngularJS
    Automated Testing
    AWS Lambda
    Behavior Driven Development
    Blockchain
    Blogging
    Business Building
    C#
    C / C++
    ClojureScript / Clojure
    Coding
    Community Service
    CS Philosophy
    Css / Scss
    Dev Ops
    Firebase
    Fitness
    Flash
    Front End
    Functional Programming
    Git
    Go Lang
    Haskell
    Illustrations
    Investing
    Java
    Javascript
    Lean
    Life
    Linux
    Logic Pro
    Music
    Node.js
    Planning
    Productivity
    Professionalism
    Python
    React
    Redux / Ngrx
    Refactoring
    Reusable Components
    Rust
    Security
    Serverless
    Shell Scripting
    Swift
    Test Driven Development
    Things
    TypeScript
    Useful Sites
    Useful Tools
    Video
    Website Development
    WebStorm
    Writing

    Archives

    March 2023
    August 2021
    February 2021
    January 2021
    October 2020
    September 2020
    May 2020
    April 2020
    February 2020
    January 2020
    December 2019
    October 2019
    September 2019
    August 2019
    July 2019
    June 2019
    May 2019
    April 2019
    March 2019
    February 2019
    January 2019
    December 2018
    November 2018
    October 2018
    September 2018
    August 2018
    June 2018
    May 2018
    April 2018
    March 2018
    February 2018
    January 2018
    December 2017
    November 2017
    October 2017
    September 2017
    August 2017
    July 2017
    May 2017
    April 2017
    March 2017
    February 2017
    January 2017
    December 2016
    November 2016
    October 2016
    September 2016
    August 2016
    July 2016
    June 2016
    May 2016
    April 2016
    March 2016
    February 2016
    January 2016
    December 2015
    November 2015
    October 2015

    RSS Feed

  • Blog
  • About Jim
JimLynchCodes © 2023