Running Azure DevOps container agents on OpenShift
Intro
Although a lot of companies are moving towards the cloud, for many the on premise data centers are still important, either as an isolated, secure environment for data and work that should not leave the intranet, or as hybrid solutions (for example, data on premise, processing in the cloud).
This doesn't prevent modern software development, it means that in most cases new software is written for containers. Data centers run a docker management layer like Kubernetes or OpenShift, enabling not just running containers but also maintaining the entire virtual infrastructure with load balancing and network provisioning capacity.
For in house development, this might also mean that you will want to run your own Azure DevOps pipeline agents. For Kubernetes, this is simple, but for OpenShift there are a couple of things you need to take into account.
Disclaimer I am not in any way or form an OpenShift specialist, the following observations came because I needed a build agent on an OpenShift (4) cluster and these were the issues I had to resolve. These are quite possibly not the best solutions, so feel free to contribute to the Github repo.
User permissions
#!/bin/sh if ! whoami &> /dev/null; then if [ -w /etc/passwd ]; then echo "${USER_NAME:-default}:x:$(id -u):0:${USER_NAME:-default} user:${HOME}:/sbin/nologin" >> /etc/passwd fi fi exec "$@"
Run once
### rest of the start.sh file ###
cleanup() { if [ -e config.sh ]; then print_header "Cleanup. Removing Azure Pipelines agent..." ./config.sh remove --unattended \ --auth PAT \ --token $(cat "$AZP_TOKEN_FILE") fi } # `exec` the node runtime so it's aware of TERM and INT signals # AgentService.js understands how to handle agent self-update and restart exec ./externals/node/bin/node ./bin/AgentService.js interactive --once & wait $! # We expect the above process to exit when it runs once, # so we now run a cleanup process to remove this agent # from the pool cleanup
Proxy and tooling
Proxy, root CA and Java
# If your company uses a proxy: ENV http_proxy=http://company.proxy.url:8080/ ENV https_proxy=http://company.proxy.url:8080/ ENV no_proxy=.company.internal.net
# If your company uses its own Root Certificate Authority WORKDIR /certtemp RUN for CERT in "http://company.pki.url/ROOTCA.crt" \ "http://company.pki.url/ADDITIONAL-ROOTCA.crt" \ "http://company.pki.url/ETC.crt" \ do curl ${CERT} --output /certtemp/$(basename ${CERT}); \ openssl x509 -in /certtemp/$(basename ${CERT}) -inform DER -out /usr/local/share/ca-certificates/$(basename ${CERT}); \ done RUN update-ca-certificates
.Net Core
The different versions of .Net Core are added by registering the Microsoft repository, then using the apt-get mechanism to install.
# Add Microsoft debian repo RUN curl https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb --output packages-microsoft-prod.deb RUN dpkg -i packages-microsoft-prod.deb # Install dotnet core 2.1, 3.1 and 5.0 RUN apt-get update \ && apt-get install -y --no-install-recommends \ powershell \ apt-transport-https \ dotnet-sdk-5.0 \ dotnet-sdk-3.1 \ dotnet-sdk-2.1
Node.js & Typescript
# Add Node.js 14.x LTS RUN curl -sL https://deb.nodesource.com/setup_lts.x | bash - # Install nodejs, npm and typescript RUN apt-get update \ && apt-get install -y nodejs \ node-typescript
Comments
Post a Comment