From c8e87568e002952bd6a0e1fdd6b1e35c6d6436a5 Mon Sep 17 00:00:00 2001 From: smerle33 Date: Fri, 16 Sep 2022 15:11:30 +0200 Subject: [PATCH 1/2] feat(locale): add the local setup within packer --- locals.pkr.hcl | 3 +++ provisioning/docker-jenkins-agent.sh | 6 ------ provisioning/ubuntu-provision.sh | 8 ++++++++ sources.pkr.hcl | 6 +++--- variables.pkr.hcl | 4 ++++ 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/locals.pkr.hcl b/locals.pkr.hcl index 39bf1449f..962e1c6e4 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)}:${element(split("_", var.locale),0)}", + "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..ce6cd22cb 100755 --- a/provisioning/ubuntu-provision.sh +++ b/provisioning/ubuntu-provision.sh @@ -51,6 +51,14 @@ function copy_custom_scripts() { chmod a+x /usr/local/bin/add_auth_key_to_user.sh } +## Set the locale +function set_local(){ + echo "LC_ALL=${LC_ALL}" >> /etc/environment + echo "${LANG} ${element(split('.', var.locale),1)}" >> /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 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" +} From 9cea9f3c7cf84640b68e8860d3c4a29f68e78bde Mon Sep 17 00:00:00 2001 From: smerle33 Date: Fri, 16 Sep 2022 17:20:09 +0200 Subject: [PATCH 2/2] add locale --- locals.pkr.hcl | 2 +- provisioning/ubuntu-provision.sh | 25 ++++++++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/locals.pkr.hcl b/locals.pkr.hcl index 962e1c6e4..d13aa7d9a 100644 --- a/locals.pkr.hcl +++ b/locals.pkr.hcl @@ -28,7 +28,7 @@ locals { "AGENT_OS_TYPE=${var.agent_os_type}", "AGENT_OS_VERSION=${var.agent_os_version}", "LANG=${var.locale}", - "LANGUAGE=${element(split(".", var.locale),0)}:${element(split("_", var.locale),0)}", + "LANGUAGE=${element(split(".", var.locale),0)}:C", "LC_ALL=${var.locale}", ], ) diff --git a/provisioning/ubuntu-provision.sh b/provisioning/ubuntu-provision.sh index ce6cd22cb..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 @@ -52,11 +70,11 @@ function copy_custom_scripts() { } ## Set the locale -function set_local(){ +function set_locale(){ echo "LC_ALL=${LC_ALL}" >> /etc/environment - echo "${LANG} ${element(split('.', var.locale),1)}" >> /etc/locale.gen + echo "${LANG} ${LANG##*.}" >> /etc/locale.gen echo "LANG=${LANG}" > /etc/locale.conf - locale-gen ${LANG} + locale-gen "${LANG}" } ## All the clean for apt @@ -452,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)