0% found this document useful (0 votes)
6 views

Codeship Using Docker and Codeship For NodeJS Development

Uploaded by

Rodrigo Galhardo
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Codeship Using Docker and Codeship For NodeJS Development

Uploaded by

Rodrigo Galhardo
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

KELLY ANDREWS

CODESHIP DEVELOPER ADVOCATE

Using Docker and


Codeship for NodeJS
Development

CO D E S H I P.CO M - B LO G .CO D E S H I P.CO M - R E S O U RC E S .CO D E S H I P.CO M


Share this

Codeship Guid
e 

About the Author.


Kelly J. Andrews is the Developer Advocate at Codeship.
When he's not busy defending JavaScript, you can find
him somewhere singing karaoke. If you see him in the
wild, ask him to do a magic trick.

Codeship is a fully customizable hosted Continuous


Integration and Delivery platform that helps you
build, test, and deploy web applications fast and with
confidence.

Learn more about Codeship here.

-2-
Share this

Codeship Guid
e 

Using Docker and


Codeship for NodeJS
Development
Docker is an amazing tool for developers. It allows us
to build and replicate images on any host, removing
the inconsistencies of dev environments and reducing
onboarding timelines considerably.

To provide an example of how you might move to


containerized development, I built a simple todo API
using NodeJS, Express, and PostgreSQL using Docker
Compose for development, testing, and eventually in
my CI/CD pipeline.
ABOUT THIS EBOOK

The first part of this eBook will cover developing and testing
a NodeJS app with Docker compose. The second part will
focus on how to further create a CI/CD pipeline for your app
using Codeship.

-3-
Share this

Codeship Guid
e 

Part 1: Using Docker


Compose for NodeJS
Development
This tutorial requires you to have a few items before you
can get started.

 Install Docker Community Edition


 Install Docker Compose
 Download Todo app example – Non-Docker branch

The todo app here is essentially a stand-in, and you


could replace it with your own application. Some of the
setup here is specific for this application, and the needs
of your application may not be covered, but it should be a
good starting point for you to get the concepts needed to
Dockerize your own applications.

Creating the Dockerfile

At the foundation of any Dockerized application, you


will find a Dockerfile . The Dockerfile contains all of
the instructions used to build out the application image.
You can set this up by installing NodeJS and all of its
dependencies, however, the Docker ecosystem has an
image repository with a NodeJS image already created
and ready to use.

-4-
Share this

Codeship Guid
e 

In the root directory of the application, create a new


Dockerfile .
CODE

1 /> touch Dockerfile

Open the newly created Dockerfile in your favorite


editor. The first instruction, FROM , will tell Docker to use
the prebuilt NodeJS image. There are several choices, but
this project uses the node:7.7.2-alpine image. For more
details about why I'm using alpine here over the other
options, you can read this post.
CODE

1 FROM node:7.7.2-alpine

If you run docker build . , you will see something


similar to the following:

1 Sending build context to Docker daemon 249.3 kB


2 Step 1/1 : FROM node:7.7.2-alpine
3 7.7.2-alpine: Pulling from library/node
4 709515475419: Pull complete
5 1a7746e437f7: Pull complete
CODE

6 662ac7b95f9d: Pull complete


7 Digest: sha256:6dcd183eaf2852dd8c1079642c04cc2d1f777e4b34f2a534cc0ad328a98d7f73
8 Status: Downloaded newer image for node:7.7.2-alpine
9 ---> 95b4a6de40c3
10 Successfully built 95b4a6de40c3

-5-
Share this

Codeship Guid
e 

With only one instruction in the Dockerfile, this doesn't


do too much, but it does show you the build process
without too much happening. At this point, you now have
an image created, and running docker images will show
you the images you have available:

1 REPOSITORY TAG IMAGE ID CREATED SIZE


CODE

2 node 7.7.2-alpine 95b4a6de40c3 6 weeks ago 59.2 MB

The Dockerfile needs more instructions to build out


the application. Currently it's only creating an image
with NodeJS installed, but we still need our application
code to run inside the container. Let's add some more
instructions to do this and build this image again.

This particular Docker file uses , COPY , and


RUN
WORKDIR . You can read more about those on Docker's
reference page to get a deeper understanding.

Let's add the instructions to the Dockerfile now:

1 FROM node:7.7.2-alpine
2
3 WORKDIR /usr/app
4
CODE

5 COPY package.json .
6 RUN npm install --quiet
7
8 COPY . .

-6-
Share this

Codeship Guid
e 

Here is what is happening:

 Set the working directory to /usr/app


 Copy the package.json file to /usr/app
 Install node_modules
 Copy all the files from the project’s root to /usr/app

You can now run docker build . again, and see the
results:

1 Sending build context to Docker daemon 249.3 kB


2 Step 1/5 : FROM node:7.7.2-alpine
3 ---> 95b4a6de40c3
4 Step 2/5 : WORKDIR /usr/app
5 ---> e215b737ca38
6 Removing intermediate container 3b0bb16a8721
7 Step 3/5 : COPY package.json .
8 ---> 930082a35f18
9 Removing intermediate container ac3ab0693f61
10 Step 4/5 : RUN npm install --quiet
CODE

11 ---> Running in 46a7dcbba114


12
13 ### NPM MODULES INSTALLED ###
14
15 ---> 525f662aeacf
16 ---> dd46e9316b4d
17 Removing intermediate container 46a7dcbba114
18 Step 5/5 : COPY . .
19 ---> 1493455bcf6b
20 Removing intermediate container 6d75df0498f9
21 Successfully built 1493455bcf6b

You have now successfully created the application image


using Docker. Currently, however, our app won’t do much
since we still need a database, and we want to connect
everything together. This is where Docker Compose will
help us out.

-7-
Share this

Codeship Guid
e 

Docker Compose Services

Now that you know how to create an image with a


Dockerfile , let’s create an application as a service
and connect it to a database. Then we can run some
setup commands and be on our way to creating that
new todo list.

Create the file docker-compose.yml .


CODE

1 /> touch docker-compose.yml

The Docker Compose file will define and run the


containers based on a configuration file. We are using
compose file version 2 syntax, and you can read up on it
on Docker's site.

An important concept to understand is that Docker


Compose spans "buildtime" and "runtime." Up until now,
we have been building images using docker build .
which is "buildtime." This is when our containers are
actually built.

We can think of "runtime" as what happens once our


containers are built and being used.

Compose triggers "buildtime" — instructing our images


and containers to build — but it also populates data
used at "runtime," such as env vars and volumes. This

-8-
Share this

Codeship Guid
e 

is important to be clear on. For instance, when we add


things like volumes and command , they will override
the same things that may have been set up via the
Dockerfile at "buildtime."

Open your docker-compose.yml file in your editor, and


copy paste the following lines:

1 version: '2'
2 services:
3 web:
4 build: .
5 command: npm run dev
6 volumes:
7 - .:/usr/app/
8 - /usr/app/node_modules
9 ports:
CODE

10 - "3000:3000"
11 depends_on:
12 - postgres
13 environment:
14 DATABASE_URL: postgres://todoapp@postgres/todos
15 postgres:
16 image: postgres:9.6.2-alpine
17 environment:
18 POSTGRES_USER: todoapp
19 POSTGRES_DB: todos

The web service


The first directive in the web service is to build the image
based on our Dockerfile . This will recreate the image
we used before, but it will now be named according to the
project we are in, nodejsexpresstodoapp . After that, we
are giving the service some specific instructions on how it
should operate:

-9-
Share this

Codeship Guid
e 

 command: npm run dev – Once the image is built, and


the container is running, the npm run dev command
will start the application.
 volumes: – This section will mount paths between the
host and the container.
 .:/usr/app/ – This will mount the root directory to our
working directory in the container.
 /usr/app/node_modules – This will mount the node_
modules directory to the host machine using the
buildtime directory.
 environment: – The application itself expects the
environment variable DATABASE_URL to run. This is set in
db.js .
 ports: – This will publish the container’s port, in this
case 3000 , to the host as port 3000 .

The DATABASE_URL is the connection string. postgres://


todoapp@postgres/todos connects using the todoapp
user, on the host postgres , using the database todos .

The Postgres service


Like the NodeJS image we used, the Docker Store has a
prebuilt image for PostgreSQL. Instead of using a build
directive, we can use the name of the image, and Docker
will grab that image for us and use it. In this case, we are
using postgres:9.6.2-alpine . We could leave it like that,
but it has environment variables to let us customize it
a bit.

- 10 -
Share this

Codeship Guid
e 

environment: – This particular image accepts a couple


environment variables so we can customize things to
our needs. POSTGRES_USER: todoapp – This creates
the user todoapp as the default user for PostgreSQL.
POSTGRES_DB: todos – This will create the default
database as todos.

Running the Application

Now that we have our services defined, we can build the


application using docker-compose up . This will show the
images being built and eventually starting. After the initial
build, you will see the names of the containers being
created.

1 Pulling postgres (postgres:9.6.2-alpine)...


2 9.6.2-alpine: Pulling from library/postgres
3 627beaf3eaaf: Pull complete
4 e351d01eba53: Pull complete
5 cbc11f1629f1: Pull complete
6 2931b310bc1e: Pull complete
7 2996796a1321: Pull complete
8 ebdf8bbd1a35: Pull complete
9 47255f8e1bca: Pull complete
CODE

10 4945582dcf7d: Pull complete


11 92139846ff88: Pull complete
12 Digest: sha256:7f3a59bc91a4c80c9a3ff0430ec012f7ce82f906ab0a2d7176fcbbf24ea9f893
13 Status: Downloaded newer image for postgres:9.6.2-alpine
14 Building web
15 ...
16 Creating nodejsexpresstodoapp_postgres_1
17 Creating nodejsexpresstodoapp_web_1
18 ...
19 web_1 | Your app is running on port 3000

- 11 -
Share this

Codeship Guid
e 

At this point, the application is running, and you will see


log output in the console. You can also run the services as
a background process using docker-compose up -d .
During development, I prefer to run without -d and
create a second terminal window to run other commands.
If you want to run it as a background process and view the
logs, you can run docker-compose logs .

At a new command prompt, you can run


docker-compose ps to view your running containers.
You should see something like the following:

1 Name Command State Ports


2 -----------------------------------------------------------------------------------------
CODE

3 nodejsexpresstodoapp_postgres_1 docker-entrypoint.sh postgres Up 5432/tcp


4 nodejsexpresstodoapp_web_1 npm run dev Up 0.0.0.0:3000-
>3000/tcp

This will tell you the name of the services, the command
used to start it, its current state, and the ports.
Notice nodejsexpresstodoapp_web_1 has listed the port
as 0.0.0.0:3000->3000/tcp . This tells us that you can
access the application using localhost:3000/todos on
the host machine.

1 /> curl localhost:3000/todos


CODE

2
3 []

- 12 -
Share this

Codeship Guid
e 

The package.json file has a script to automatically build


the code and migrate the schema to PostgreSQL. The
schema and all of the data in the container will persist
as long as the postgres:9.6.2-alpine image is not
removed.

Eventually, however, it would be good to check how your


app will build with a clean setup. You can run docker-
compose down , which will clear things that are built and
let you see what is happening with a fresh start.

Feel free to check out the source code, play around a bit,
and see how things go for you.

Testing the Application

The application itself includes some integration tests


built using jest . There are various ways to go about
testing with Docker, including creating Dockerfile.test
and docker-compose.test.yml files specific for the test
environment. That's a bit beyond the current scope of
this article, but I want to show you how to run the tests
using the current setup.

The current containers are running using the project


name nodejsexpresstodoapp . This is a default from the
directory name. If we attempt to run commands, it will
use the same project, and containers will restart. This is
what we don't want.

- 13 -
Share this

Codeship Guid
e 

Instead, we will use a different project name to run the


application, isolating the tests into their own environment.
Since containers are ephemeral (short-lived), running
your tests in a separate set of containers makes certain
that your app is behaving exactly as it should in a clean
environment.

In your terminal, run the following command:


CODE

1 /> docker-compose -p tests run -p 3000 --rm web npm run watch-tests

You should see jest run through integration tests and


wait for changes.

The docker-compose command accepts several options,


followed by a command. In this case, you are using
-p tests to run the services under the tests project
name. The command being used is run , which will
execute a one-time command against a service.

Since the docker-compose.yml file specifies a port, we


use -p 3000 to create a random port to prevent port
collision. The --rm option will remove the containers
when we stop the containers. Finally, we are running in the
web service npm run watch-tests .

- 14 -
Share this

Codeship Guid
e 

Part 2: Using Codeship


for NodeJS Application
Deployments
This part of the tutorial requires you to have a few items
before you can get started:

 Codeship account
 Codeship Jet CLI
 Heroku account
 GitHub, Bitbucket, or GitLab account

In our example, we are deploying our code directly into


Heroku without Docker. While we will be using Docker
locally and in CI/CD, Codeship Pro allows us to deploy
Docker apps to production even when production is not
using Docker, such as classic Heroku. The deployment in
this case can be exchanged with any other server, image
repository, or Docker host.

Essentially, you can modify this example to suit your


needs, by using any Docker image that does what
you need, eg, deploy to AWS. Our documentation has
examples that you can review.

- 15 -
Share this

Codeship Guid
e 

Testing NodeJS Apps with Codeship

Continuous integration is defined as follows:

"In software engineering, continuous integration (CI)


is the practice of merging all developer working
copies to a shared mainline (like a master branch)
several times a day."

We want to automate all of this with Codeship so every


pushed commit will be built and tested prior to allowing
a merge. Let's set up the necessary files and test our
pipeline locally.

Codeship services file


The first file we need to create is the Codeship services
definition file. This will instruct Codeship as to the
services we need during the build.
CODE

1 #> touch codeship-services.yml

The codeship-services.yml syntax is directly influenced


by Docker Compose syntax, and the docker-compose.yml
file created in the first part gets us most of the way there.
Open the codeship-services.yml in your editor, copy
the following code, and paste there.

- 16 -
Share this

Codeship Guid
e 

1 web:
2 build: .
3 links:
4 - postgres
5 environment:
6 DATABASE_URL: postgres://todoapp@postgres/todos
CODE

7 cache: true
8 postgres:
9 image: postgres:9.6.2-alpine
10 environment:
11 POSTGRES_USER: todoapp
12 POSTGRES_DB: todos

The differences from the original docker-compose.yml


file to define the codeship-services.yml file are quite
minimal here. Next we can define the actual steps to run
during the build and automated tests.

Codeship steps file


The next file to create is the codeship-steps.yml file,
which will tell Codeship what steps to run and in what
order. You can learn more about the codeship-steps.yml
file in our documentation. Go ahead and create the new
steps file and open it up in your editor.
CODE

1 #> touch codeship-steps.yml

Each step defined in the file is


codeship-steps.yml
based on what you define as your pipeline. This example
starts with a lint test and integration test, and

- 17 -
Share this

Codeship Guid
e 

eventually will deploy the code as well. Your pipeline can


be completely customized to suit your specific needs.

1 - type: parallel
2 steps:
3 - name: lint
4 service: web
CODE

5 command: npm run lint


6 - name: tests
7 service: web
8 command: npm test -- --forceExit

The steps here run in parallel: lint and tests .


Running our tests simultaneously works great here,
because if either of these tests fail, the build will fail,
and saves us some time overall. You can find more
information on Codeship Pro step types here.

Bin scripts
Now that things are more automated, we end up
introducing a small race case that we can easily get
around with some simple scripts. As the project is built,
the integration tests require that Postgres is running
to perform the migrations. We can't guarantee that will
happen with the codeship-services.yml file alone. One
approach is to check that the database is available before
starting the migration.

1 #> mkdir bin && touch bin/{wait-for-postgres,ci}


CODE

2 #> chmod +x bin/**

- 18 -
Share this

Codeship Guid
e 

wait-for postgres
The contents of the wait-for-postgres script are the
following:

1 #!/bin/sh
2 # wait-for-postgres
3 set -e
4
5 TIMEOUT=60
6 COUNT=0
7
CODE

8 until pg_isready -h "postgres" -p "5432" || [ $COUNT -eq $TIMEOUT ];


9 do
10 echo $COUNT
11 echo $TIMEOUT
12 sleep 1
13 COUNT=$((COUNT+1))
14 done

I am relying on the pg_isreadyfunction to check for


the readiness of the postgres database. If it isn’t ready,
we sleep for a second and try again. We need to make a
small change to the Dockerfile to add the pg_isready
function.

- 19 -
Share this

Codeship Guid
e 

CODE

1 RUN apk update && apk add postgresql

The function times out after 60 seconds, but you can


tweak that if you see it taking longer. It typically takes
only a few seconds to connect.

ci
The ci script is as follows:

1 #!/bin/sh
2 set -e
3
CODE

4 bin/wait-for-postgres
5 time npm run migrate
6
7 time $1

Not too much heavy lifting here. This script runs the
wait-for-postgres script to finish up, then it will
perform the migration, and the last line takes the first
parameter and will run that. This allows me to change a
line in codeship-steps.yml to run this script first.

1 - name: tests
CODE

2 service: web
3 command: bin/ci "npm test -- --forceExit" # change the command here

Local testing with Codeship Jet CLI


We are able to test our setup locally using
Codeship Jet CLI . If you haven't done it yet, check out

- 20 -
Share this

Codeship Guid
e 

our Getting Started with Codeship Jet CLI documentation.


Codeship Jet CLI will run through the steps file just as it
would on Codeship. This is a quick way to catch errors early
before committing and pushing to your repository.

1 #> jet steps


CODE

2 ## build stuff, run tests ##


3 {StepFinished=step_name:"tests" type:STEP_FINISHED_TYPE_SUCCESS}

If you see the final result above, you have set everything
up correctly. If you receive instead type:STEP_FINISHED_
TYPE_ERROR , something didn't go right and you should
check some things. Codeship Jet CLI will produce a log
that you can review to try to locate the problem. Having
the ability to catch any errors prior to pushing to your
repository makes this a particularly powerful tool in the
Codeship arsenal.

The finished version of this project is also available on


GitHub, in case you get stuck and want to skip ahead.

- 21 -
Share this

Codeship Guid
e 

Setting Up Your Codeship Pro Project

The next phase is to set up the Codeship project, so that


new pushes into your repository will kick off the build. In
this step, we will make sure you have a repository set up,
create the project, and push a build.

Source code management setup


Log into your GitHub, Bitbucket, or GitLab account and
create a new repo there that you have admin access
to. Grab the clone URL and switch to the Codeship
application.

Create project
When your repo is ready to go, you can now set up the
Codeship project.

- 22 -
Share this

Codeship Guid
e 

Navigate to Projects, then click the "New Project" button.

Connect your SCM by selecting the source code


management (SCM) tool you set up in the previous step.

If you originally signed up with an SCM different than above, we will


connect to the service during this step.

- 23 -
Share this

Codeship Guid
e 

Choose your repository by copy/pasting the Repository


Clone URL link from the previous step. Click the Connect
button.

- 24 -
Share this

Codeship Guid
e 

Configure your project by clicking the "Select Pro Project"


button.

Your project is set up at this time, and any code


committed and pushed to the repository will now run
builds automatically.

Push your first build


Let's run a build now. In your command line, or using
your favorite git tool, make sure the repo is initialized,
connect the remote, add the files, commit, and push.

1 /> git init


2 /> git remote add origin <<YOUR_REPOSITORY_CLONE_URL>>
CODE

3 /> git add .


4 /> git commit -am "initial build"
5 /> git push -u origin master

- 25 -
Share this

Codeship Guid
e 

If you head back to Codeship and click into your project,


you should see the build running. Make sure at this point
you get a green build. Otherwise you may need to go
back and check some things:

 Make sure you have added all of your files to your repo.
 Review your codeship-services.yml and
codeship-steps.yml files.
 Run Codeship Jet CLI locally to double-check it works
locally.

Once you have the CI working, you can move on to the


deployment section, where we will automatically deploy
our code to Heroku.

Continuous Deployment to Heroku


with Codeship Pro

So far, we have the integration steps running, and every


new commit will run tests to make sure that the code is
ready to merge.

When the branch is master, however, we want to run


another step to actually deploy the application when the
tests are passing.

- 26 -
Share this

Codeship Guid
e 

Creating the Heroku app


You can create an application using the Heroku UI, which
is the simplest way to get started. If you are familiar with
the Heroku CLI, you can also perform these steps using
that as well. Once you have the application created, there
are a some steps to get everything Codeship needs for
the deployment.

Heroku PostgreSQL add-on


These steps will set up the Heroku PostgreSQL add-on
for your app to use as its database when deployed.

1. Click Resources.
2. Under Add-ons, search for postgres .
3. In the results dropdown, click Heroku Postgres.
4. Leave the selection as Hobby Dev – Free, then click
Provision.

Get your Heroku API key


1. Click on your avatar in the upper right, then click Account
Settings.
2. Near the bottom of the settings page, you will find an API
key. Click Reveal.
3. Copy the API key.

- 27 -
Share this

Codeship Guid
e 

Set this up in a deployment.env file with your terminal:


CODE

1 /> echo "HEROKU_API_KEY=YOUR_API_KEY_HERE" > deployment.env

Create the Heroku procfile


This is a simple one-liner, but it's required for Heroku to run
the application:
CODE

1 /> echo "web npm start" > Procfile

Encrypting with Codeship Jet CLI


Since we have some sensitive keys that we will need to
use, Codeship Jet CLI provides some encryption tools
to secure your keys. In this instance, it's an environment
variable needed for the deployment, however you can
encrypt all of your secrets. For more information, you
can read the Codeship documentation on Encrypting
Environment Variables.

In the Codeship UI, follow these steps:

1. Click Projects, then the project you are currently working in.
2. Click Settings, then click General.
3. Locate and copy the AES Key .

- 28 -
Share this

Codeship Guid
e 

In your terminal, include:


CODE

1 /> echo "YOUR_AES_KEY" > codeship.aes

NOTE: Make sure that both codeship.aes and deployment.env are ignored in
your .gitignore file. Since they contain sensitive data, you don't want these to be
pushed into your repository.

All that's left to do is encrypt the deployment.env file.


We do this using Codeship Jet CLI .
CODE

1 #> jet encrypt deployment.env deployment.env.encrypted

The deployment.env.encrypted will then be included in


your repository and decrypted in Codeship.

Adding the Heroku deployment service


In Codeship Pro, we are able to create any service we
need using Docker. What this means to you is that if it
runs on Docker, it runs on Codeship. In this example, we
are using a service that Codeship provides specifically
for Heroku deployment. Let's add the service to the end
of our codeship-services.yml file.

1 web:
2 build: .
CODE

3 links:
4 - postgres

- 29 -
Share this

Codeship Guid
e 

5 environment:
6 DATABASE_URL: "postgres://todoapp@postgres/todos"
7 cached: true
8 postgres:
9 image: postgres:9.6.2-alpine
10 environment:
CODE

11 POSTGRES_USER: todoapp
12 POSTGRES_DB: todos
13 deploy: # added this service
14 image: codeship/heroku-deployment
15 encrypted_env_file: deployment.env.encrypted
16 volumes:
17 - ./:/deploy

Note that we add the encrypted_env_file here. This


instructs Codeship as to which file to use to find the
Heroku API key used inside the container.

Adding the deployment step


The only steps left is to tell Codeship when to use the
deploy service. Open up the codeship-steps.yml file
and add the following:

1 - type: parallel
2 steps:
3 - name: lint
4 service: web
CODE

5 command: npm run lint


6 - name: tests
7 service: web
8 command: bin/ci "npm test -- --forceExit"

- 30 -
Share this

Codeship Guid
e 

9 - name: deploy # added this step


10 tag: master
CODE

11 service: deploy
12 command: codeship_heroku deploy /deploy nodejs-express-todoapp

What this codeship-steps.yml file indicates now is that


if the branch, listed as tag , is equal to master , it will
run the deploy service. If we push to any other branch,
everything will run except the deployment. You can
read more about the tag and exclude attributes and
limiting steps in Codeship Pro.

The image codeship/heroku-deployment has the


command codeship_heroku deploy , which accepts
two parameters: the path of the files and the name of
the Heroku app. In this case, these are /deploy and
nodejs-express-todoapp . As long as all tests pass and
the branch is master , our code will be deployed to
Heroku.

The codeship/heroku-deployment image is running


several commands to test for proper access to the
application, tarball the code, and deploy to Heroku with
their API. Just to reiterate, this can be anything you need
it to be, eg, deployment to AWS. If it runs in a Docker
container, Codeship Pro can run it.

- 31 -
Share this

Codeship Guid
e 

Starting the build on Codeship Pro


Now we can push these changes into our SCM and let
Codeship take it from here.

1 git add .
CODE

2 git commit -am "adding deployment"


3 git push

Make sure you have added your and


codeship.aes
deployment.env files to .gitignore . You want to
ignore these files so you are not publicly exposing secrets
in your repository. Do that now if you haven't already.

Head over to your Codeship Pro project and watch your


build and deployment from the dashboard.

- 32 -
Share this

Codeship Guid
e 

Conclusion

This eBook covered quite a bit. Initially, we are tasked


with testing and deploying our application manually. This
process is not only tedious, it takes up someone's time
and is error prone.

First we covered setting up our local development and


testing workflow using Docker Compose. We then used
Codeship Pro and Jet CLI to automate our steps even
further. Now we are able to push a new commit to
master , which then runs our tests and deploys to
Heroku all through Codeship Pro.

Here are some of the resources used for this tutorial:

Docker
 Docker Community Edition
 Dockerfile Reference
 Docker Compose Overview
 Docker Compose CLI

Docker Images Used


 Node
 PostgreSQL
 Codeship Heroku Deployment

- 33 -
Share this

Codeship Guid
e 

Codeship Pro
 Codeship Pro Documentation
 Codeship Jet CLI Docs
 Encrypting Environment Variables
 Codeship Steps Docs
 Codeship Services Docs

Article Resources
 Using Docker Compose for NodeJS Development
 NodeJS Express Todo App Repo
 Alpine Based Docker Images Make a Difference in Real
World Apps

Additional Tools and Resources Used


 Jest
 Express JS
 Heroku
 GitHub
 Bitbucket
 GitLab
 PostgreSQL
 Todo Backend

- 34 -
Share this

Codeship Guid
e 

More Codeship Resources.

Breaking up your Monolith into


Microservices.
EBOOKS

In this eBook you will learn about the basics of


"decomposing" a monolith into microservices.
Download this eBook

How Docker Streamlines


Production Deployments.
EBOOKS

In this eBook you will learn how Docker helps ensure


a modern software development workflow.
Download this eBook

Running a MEAN Web APP in


Docker Containers on AWS.
EBOOKS

In this eBook, we break down all the steps it takes to


successfully install and run a web application built on
the MEAN stack.
Download this eBook

- 35 -
Share this

Codeship Guid
e 

About Codeship.
Codeship is a hosted Continuous Integration service that fits all your needs.
Codeship Basic provides pre-installed dependencies and a simple setup UI
that let you incorporate CI and CD in only minutes. Codeship Pro has native
Docker support and gives you full control of your CI and CD setup while
providing the convenience of a hosted solution.

Codeship Basic Codeship Pro


A simple out-of-the-box Continuous A fully customizable hosted
Integration service that just works. Continuous Integration service.

Starting at $0/month. Starting at $0/month.

Works out of the box Customizability & Full Autonomy

Preinstalled CI dependencies Local CLI tool

Optimized hosted infrastructure Dedicated single-tenant instances

Quick & simple setup Deploy anywhere

LEARN MORE LEARN MORE

You might also like