diff --git a/locals.pkr.hcl b/locals.pkr.hcl index 39bf1449f..d13aa7d9a 100644 --- a/locals.pkr.hcl +++ b/locals.pkr.hcl @@ -27,6 +27,9 @@ locals { "ARCHITECTURE=${var.architecture}", "AGENT_OS_TYPE=${var.agent_os_type}", "AGENT_OS_VERSION=${var.agent_os_version}", + "LANG=${var.locale}", + "LANGUAGE=${element(split(".", var.locale),0)}:C", + "LC_ALL=${var.locale}", ], ) } diff --git a/provisioning/docker-jenkins-agent.sh b/provisioning/docker-jenkins-agent.sh index c923012ba..6bf285772 100755 --- a/provisioning/docker-jenkins-agent.sh +++ b/provisioning/docker-jenkins-agent.sh @@ -8,12 +8,6 @@ export DEBIAN_FRONTEND=noninteractive # Avoid APT or dpkg asking questions apt-get update --quiet apt-get install --yes --no-install-recommends ca-certificates curl sudo software-properties-common locales -# force the en_US.UTF-8 locale -echo "LC_ALL=en_US.UTF-8" >> /etc/environment -echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen -echo "LANG=en_US.UTF-8" > /etc/locale.conf -locale-gen en_US.UTF-8 - echo "= Retrieve agent.jar" curl --create-dirs --fail --silent --show-error --location --output /usr/share/jenkins/agent.jar "https://repo.jenkins-ci.org/public/org/jenkins-ci/main/remoting/${JENKINS_REMOTING_VERSION}/remoting-${JENKINS_REMOTING_VERSION}.jar" chmod 755 /usr/share/jenkins diff --git a/provisioning/ubuntu-provision.sh b/provisioning/ubuntu-provision.sh index e3daa8232..871fa0b97 100755 --- a/provisioning/ubuntu-provision.sh +++ b/provisioning/ubuntu-provision.sh @@ -6,6 +6,24 @@ set -eux -o pipefail ## Check for environment variables or fail miserably (due to set -u enabled) echo "== Provisiong jenkins-infra agent for ubuntu 20" +case "$(uname -m)" in + x86_64) + if test "${ARCHITECTURE}" != "amd64"; then + echo "Architecture mismatch: $(uname -m) != ${ARCHITECTURE}" + exit 1 + fi + ;; + arm64 | aarch64) # macOS M1 arm64 while ubuntu 20 is aarch64 + if test "${ARCHITECTURE}" != "arm64"; then + echo "Architecture mismatch: $(uname -m) != ${ARCHITECTURE}" + exit 1 + fi + ;; + *) + echo "Unsupported architecture: $(uname -m)" + exit 1 + ;; +esac echo "ARCHITECTURE=${ARCHITECTURE}" export DEBIAN_FRONTEND=noninteractive @@ -51,6 +69,14 @@ function copy_custom_scripts() { chmod a+x /usr/local/bin/add_auth_key_to_user.sh } +## Set the locale +function set_locale(){ + echo "LC_ALL=${LC_ALL}" >> /etc/environment + echo "${LANG} ${LANG##*.}" >> /etc/locale.gen + echo "LANG=${LANG}" > /etc/locale.conf + locale-gen "${LANG}" +} + ## All the clean for apt function clean_apt() { ## Disable and remove Unattended APT upgrades @@ -444,6 +470,7 @@ function sanity_check() { function main() { check_commands copy_custom_scripts + set_locale # Define the locale clean_apt install_ssh_requirements # Ensure that OpenSSH CLI and SSH agent are installed setuser # Define user Jenkins before all (to allow installing stuff in its home dir) diff --git a/sources.pkr.hcl b/sources.pkr.hcl index 9d2b892e2..a0a79e7af 100644 --- a/sources.pkr.hcl +++ b/sources.pkr.hcl @@ -81,9 +81,9 @@ source "docker" "base" { "LABEL version = ${var.image_version}", "LABEL scm_ref = ${var.scm_ref}", "LABEL build_type = ${var.build_type}", - "ENV LANG=en_US.UTF-8", - "ENV LANGUAGE=en_US:en", - "ENV LC_ALL=en_US.UTF-8", + "ENV LANG=${var.locale}", + "ENV LANGUAGE=${element(split(".", var.locale),0)}:${element(split("_", var.locale),0)}", + "ENV LC_ALL=${var.locale}", "ENV AGENT_WORKDIR=/home/jenkins/agent", "WORKDIR /home/jenkins", "ENTRYPOINT [\"/usr/local/bin/jenkins-agent\"]", diff --git a/variables.pkr.hcl b/variables.pkr.hcl index ae126642a..2689e58e4 100644 --- a/variables.pkr.hcl +++ b/variables.pkr.hcl @@ -57,3 +57,7 @@ variable "docker_namespace" { type = string default = "jenkinsciinfra" } +variable "locale" { + type = string + default = "en_US.UTF-8" +}