Skip to content
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

IBM i and GitHub Codespaces: The future of development #54

Open
worksofliam opened this issue Oct 27, 2021 · 0 comments
Open

IBM i and GitHub Codespaces: The future of development #54

worksofliam opened this issue Oct 27, 2021 · 0 comments
Labels
blog Personal interests ilerpg ILE RPG topics nodejs Node.js topics odbc Stuff about ODBC

Comments

@worksofliam
Copy link
Owner

worksofliam commented Oct 27, 2021

If you've never heard of GitHub Codespaces before, I hope that you will leave this post wanting to try it.

As a preface: I do all of my development in VS Code on my local machine. I write mostly Node.js, COBOL, and RPG. That is my day-to-day. What this post will show is how you can achieve it with GitHub Codespaces. It may also be possible with Python too, but I didn't try that.

GitHub Codespaces is Visual Studio Code but in the browser, made for managing repositories on GitHub. But because a codespace gives you access to an entire Linux environment, you can do what you want with it. And because it's VS Code, you get access to all the extensions available.

See more about GitHub Codespaces on its website.

Setting up a Codespace

  1. Create an empty repository on GitHub with an initial file (a readme is fine!)
  2. Click the big green button that says 'Code'
  3. Go onto the Codespaces tab
  4. Click 'New codespace'

image

Connection notes

I am quite aware that a majority of users run their IBM i behind a VPN. As of right now, GitHub Codespaces does not allow users to configure a VPN for their codespace to use (though it is possible to actually do it, that is another post). I did read that Azure Codespaces may allow this in the future (for those using Azure and its network features) which might allow you to reach out to your IBM i instances.

If you're just trying this, pub400 works perfectly fine to play with.

June 2022 update: OpenVPN is a working option when using a Codespace or GitPod: https://github.com/codespaces-contrib/codespaces-openvpn

COBOL, RPG, and traditional IBM i development

Welcome to the future, because you can now write all of your COBOL, RPG and other ILE languages directly in the cloud. How cool! First, you need the Code for IBM i extension. This is free for everyone. You can find it on the Marketplace:

image

Following the installation, you can connect to your system:

image

After you've connected successfully, you can use Code for IBM i just like you would normally - except in a browser!

image

See more about Code for IBM i here.

Node.js

Writing a Node.js app is awesome and the fact we can now write a Node.js app that talks to IBM i is even better for me!

Node.js takes a bit of setup to get going when working with the ODBC driver, so we need the following things:

  • IBM i ODBC driver for Linux
  • unixodbc
  • odbc

First go and download the 'ACS Linux App Pkg' from the IBM website.

When the .zip has been downloaded, you want to extract it to find the .deb inside: It is at ./x86_64/ibm-iaccess-1.1.0.15-1.0.amd64.deb, though you may have a different version. You are able to upload files right into the Codespace. You can go to the Explorer panel, right click and select 'Upload':

image

You should select the file mentioned above and then see it appear in the directory in the Codespace.

image

Next, for the real installation steps. You need to run these commands in the Terminal with the Codespace. You can open the Terminal by pressing Control / Command + J, and selecting Terminal.

  1. sudo apt install unixodbc
    • will install unixodbc
  2. sudo apt install ./ibm-iaccess-1.1.0.15-1.0.amd64.deb
    • installs the file we uploaded, which is the IBM i ODBC driver.
  3. npm i odbc
    • this will fetch the ODBC module from npm and likely build it automatically. Luckily, Codespaces has all the build tools preinstalled so we don't have to worry about anything!

Now you're ready to write some Node.js! Here's an example script I used to test ODBC and it worked great!

const odbc = require('odbc');

async function connectToDatabase() {
    const connectionString = [
        `Driver=IBM i Access ODBC Driver`,
        `System=${process.env.DB2_SYSTEM}`,
        `UID=${process.env.DB2_UID}`,
        `Password=${process.env.DB2_PASSWORD}`,
        `DBQ=,*USRLIBL`,
        `Naming=1`,
      ].join(';');

    const connection = await odbc.connect(connectionString);
    // connection1 is now an open Connection

    const results = await connection.query('SELECT * FROM SAMPLE.DEPARTMENT');

    console.log(results);
}

connectToDatabase();

image

@worksofliam worksofliam added blog Personal interests nodejs Node.js topics ilerpg ILE RPG topics odbc Stuff about ODBC labels Oct 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blog Personal interests ilerpg ILE RPG topics nodejs Node.js topics odbc Stuff about ODBC
Projects
None yet
Development

No branches or pull requests

1 participant