I have a Jenkins server that is running within a Docker container. I custom build the Jenkins image with Docker, Docker Compose and Terraform installed on it.
I run it locally on my Mac, here’s the Dockerfile that configures the Jenkins server:
FROM jenkins/jenkins:latest
USER root
# Install dependencies
RUN apt-get update &&
apt-get install -y --no-install-recommends
apt-transport-https
ca-certificates
curl
gnupg
lsb-release
software-properties-common
awscli
python3
python3-pip
python3-venv
# Install Docker using Docker convenience script
RUN curl -fsSL https://get.docker.com -o get-docker.sh &&
sh get-docker.sh
# Add Jenkins user to Docker group
RUN usermod -aG docker jenkins
# Install Docker Compose
ENV DOCKER_COMPOSE_VERSION=1.29.0
RUN curl -L "https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose &&
chmod +x /usr/local/bin/docker-compose
# Install Terraform
ENV TERRAFORM_VERSION=1.8.1
ENV ARCHITECTURE=arm
RUN curl -fsSL https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_${ARCHITECTURE}.zip -o terraform.zip &&
unzip terraform.zip -d /usr/local/bin &&
rm terraform.zip
# Create and activate a virtual environment
RUN python3 -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Install required Python libraries
RUN pip install --no-cache-dir requests boto3
USER root
When I run a Jenkins pipeline that eventually reaches a Terraform stage, I get this error:
+ terraform init
/var/jenkins_home/workspace/resume-app-pipeline/resume-app-iac@tmp/durable-fe149f76/script.sh.copy: 1: terraform: Exec format error
When I enter the Docker container that is running the Jenkins server and manually try to input a Terraform command, I get this error:
root@9ac5b490404d:/# terraform --version
bash: /usr/local/bin/terraform: cannot execute binary file: Exec format error
root@9ac5b490404d:/#
This started to happen yesterday after I upgraded to 1.8.1 from 1.7.5.
I have tried to chmod +x /usr/local/bin/terraform
, no luck. Really not sure what is causing this.