-
Notifications
You must be signed in to change notification settings - Fork 5
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
Deploying a Node.js + Db2 for i app using Docker (from a Codespace!) #59
Comments
Really love your work @worksofliam 😍 We have this automated where I worked, but never thought to share like you have! It’s nice to see that driver make its way to the package managers, it was always a pain!! |
This is REALLY cool! I have this pie-in-the-sky idea of using docker-compose with docker db2 in a docker dev container for testing new things without even having to touch anything on IBM i. Do you think something like that might work? Frameworks like Laravel have really good database seeding tools that might make this viable... I am very new to the platform in general, but things like this post and Merlin are getting me excited! |
@cole-maxwell1 Cool idea! I guess if you can get node-odbc to work with Db2 LUW then that's a good start! My next worry is differences in how data is returned, connection strings, SQL syntax differences. I'd be interested in seeing a single app run with two different databases, though (Db2 LUW and Db2 for i) |
I wanted to link to this blog post "CONTINUOUS INTEGRATION FOR PHP EXTENSIONS" over at Seiden Group by Calvin Buckley. They are actually using the db2 docker container for their CI tests on ibm_db2 and PDO_IBM PHP projects. Interesting stuff! |
Thanks for the post! I did not realize you could install the odbc driver now from the package manager! I have written a Rest API in NodeJS connecting to our IBM i that is containerized with Docker for an Android App I developed. I use docker compose to create multiple instances of the app running on our linux vm. (see image below of my current docker file) So now going forward i should be able to use apt install after i've updated the repository list??? I am very excited about this MerLin technology coming. Now i just go to figure out how to get my other colleagues still writing in fixed format RPG to use it !!! :-) |
It is quite amazing that this was written 2 yeasrs ago |
Building an app that uses ODBC to talk to Db2 for i takes some work these days. You need ODBC, the chosen driver (Db2 for i /
iaccess
) and unixodbc if you're not on Windows.Up until recently, it's taken some work to get all these pieces. You could easily install unixodbc, but the driver has usually been downloaded from the IBM website behind a signup. Then there is node-odbc which needs to be built on unsupported platforms (where pre-built binaries have not been provided) - luckily, all the major archs (Windows x86, OSX Darwin, Linux, etc) now have pre-built binaries!
Luckily, for all those pieces, they are so easy to get now. Putting all the work into a Dockerfile is the next logical step to make an awesome pipeline.
The latest big change is that IBM now allow you to install
iaccess
(the Db2 for i ODBC driver) through a package manager on Linux (apt
for example). Kevin Adler wrote about that on his blog. Previously, people who were automating this were using their own way to install it.. like making thedeb
available through their own service.This guide will take an existing Node.js app (a basic one) and show you how to deploy it using Docker with a Dockerfile onto Heroku - though it should work with pretty much any cloud services.
Codespaces
I am going to do all this using a GitHub Codespace. I like Codespaces a lot. I can write all my Node.js code, use ODBC and
iaccess
on a Codespace like I can on my local machine.. except I can move between devices and have the same environment.For this guide, you do need
docker
installed on whatever machine you use. We will usedocker
to test our build of the image, and of course you can run the app locally usingdocker
if you wanted.Repo
You can find the repo I used for this demo on my GitHub. I took a basic Node.js + node-odbc example and basically added a Dockerfile - easy.
Checking it works
Open the repo up into VS Code - either on your local machine or in your Codespace. From the Terminal, make sure
docker
is working. You should see all the help text appear.Creating a
Dockerfile
A Dockerfile is used to determine how to build the image and run the app. Here is the contents of the Dockerfile for our demo app.. and I am more than sure it will apply to lots of apps outside of this.
There are some important parts to note here:
FROM node:version
tells the image what it should inherit from. It just happens that there are existing Node.js images, and I can also specify what version of Node.js I want.RUN curl ...
copied directly from Kevin's blog. This adds theiaccess
repo to the local package manager (apt
)RUN apt ...
to update and installiaccess
. This also installsunixodbc
onto the system.ENV PORT=$PORT
sets an environment variable to the value where the image is being built (in our case, Heroku)CMD npm run start
is the command that is used to start the app up.Testing build
Before we can deploy our image, we need to test that it will build. This checks it can run all the commands, etc, provided in the Dockerfile.
npm run docker
docker build --no-cache -t tmp_image .
If it failed, you will know.
Deploying to Heroku
You can use any service you want. Digital Ocean, AWS, Azure, and others, all have their own app services-type infrastructure for you to run apps in the cloud. I have used Heroku before, so I am using it again for this demo.
We will use both Heroku UI and Heroku CLI to deploy our app.
First, we need to log into Heroku from the CLI.
heroku login
from your local machineheroku login -i
if you're using a CodespaceBefore you continue, this is a good time to setup your environment variables for your app instance in Heroku. You can do this under Config Vars in settings:
Next, connect to the the container registry:
Now it's time to build your image on Heroku! Notice I am using the
-a
parameter to specify the app.Finally, deploy the app:
Here is the
/employee
endpoint from my sample being returned from my Heroku app running on a container!The text was updated successfully, but these errors were encountered: