Deploying Alpha Go App Versions to OpenShift

Build it, Tag it, Push it, Run it

Oct. 16, 2023, 12:27 p.m.

When building interconnected, cloud-native applications to be deployed in OpenShift, it is sometimes necessary to test out development versions on a running cluster. This is useful to test the application out in a production like setting where it interfaces with other apps. When deploying Docker images it is possible to use the same production Dockerfile to build and deploy local code.

Doing so is made more complicated by developing these applications on a Mac. Luckily, Go provides the ability to compile a binary for a different OS than the one it is built on using the 'GOOS' env var like:

GOOS=linux go build -v -o ~/bin/linux/pj-rehearse ./cmd/pj-rehearse

Next, it is necessary to use Docker to build and push an image to the registry of your choice. I prefer to use Quay to host my images:

docker build -f images/pj-rehearse/Dockerfile ~/bin/linux -t
docker push

Now that the image is available on the registry, it is possible to utilize it in a deployment in the OpenShift cluster. In order to do that, the production deployment config can be used as a basis. It is necessary to change the name to not conflict with the production version, and to update any routes to make sure that the alpha version doesn't take production traffic. Once these changes have been made, the deployment can be applied.

I utilize this workflow so often that I have created a simple script that only takes the name of the binary I am building and handles the rest:

cd ~/Projects/ci-tools

echo Building linux binary of ${TOOL}
GOOS=linux go build -v -o ~/bin/linux/${TOOL} ./cmd/${TOOL}
echo Building docker image${TOOL}:latest
docker build -f images/${TOOL}/Dockerfile ~/bin/linux -t${TOOL}:latest
echo Pushing docker image${TOOL}:latest
docker push${TOOL}:latest

cd -

Comments about Deploying Alpha Go App Versions to OpenShift

No one has left a comment yet, be the first to voice your opinion on Deploying Alpha Go App Versions to OpenShift!