Skip to content

Commit

Permalink
Merge pull request #345 from smerle33/PR_Review1110274614
Browse files Browse the repository at this point in the history
feat(locale): add the local setup within packer
  • Loading branch information
smerle33 authored Sep 29, 2022
2 parents 1cc0fa4 + 908fa73 commit 12643f0
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 9 deletions.
3 changes: 3 additions & 0 deletions locals.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
],
)
}
6 changes: 0 additions & 6 deletions provisioning/docker-jenkins-agent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions provisioning/ubuntu-provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions sources.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -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\"]",
Expand Down
4 changes: 4 additions & 0 deletions variables.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,7 @@ variable "docker_namespace" {
type = string
default = "jenkinsciinfra"
}
variable "locale" {
type = string
default = "en_US.UTF-8"
}

0 comments on commit 12643f0

Please sign in to comment.