Skip to content

Commit

Permalink
Add jammy-desktop image
Browse files Browse the repository at this point in the history
  • Loading branch information
dometto committed Sep 30, 2024
1 parent 1576f0e commit bf35afc
Show file tree
Hide file tree
Showing 10 changed files with 253 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build_and_deploy_dispatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
- ubuntu/focal
- ubuntu/focal-desktop
- ubuntu/jammy
- ubuntu/jammy-desktop
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/build_and_deploy_ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
- ubuntu/focal
- ubuntu/focal-desktop
- ubuntu/jammy
- ubuntu/jammy-desktop
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/cron_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
- ubuntu/focal
- ubuntu/jammy
- ubuntu/focal-desktop
- ubuntu/jammy-desktop
env:
ANSIBLE_VERSION: 2.15.5
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/prune.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ jobs:
env:
OWNER: orgs/UtrechtUniversity
PACKAGE_NAME: SRC-test-workspace
KEEP_MIN: 6
KEEP_MIN: 8
PER_PAGE: 100
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ This repository provides a set of scripts and [Packer](https://www.packer.io/) i
| ghcr.io/utrechtuniversity/src-test-workspace | ubuntu_focal | Ubuntu 20.04 |
| ghcr.io/utrechtuniversity/src-test-workspace | ubuntu_focal_desktop | Ubuntu 20.04 with xfce4 |
| ghcr.io/utrechtuniversity/src-test-workspace | ubuntu_jammy | Ubuntu 22.04 |
| ghcr.io/utrechtuniversity/src-test-workspace | ubuntu_jammy_desktop | Ubuntu 22.04 with xfce4 |
| ghcr.io/utrechtuniversity/src-test-workspace | ubuntu_focal-pilot | Ubuntu 20.04, latest version of [base components](#how-it-works). |
| ghcr.io/utrechtuniversity/src-test-workspace | ubuntu_focal-desktop-pilot | Ubuntu 20.04 with xfce4, latest version of [base components](#how-it-works) |
| ghcr.io/utrechtuniversity/src-test-workspace | ubuntu_jammy-pilot | Ubuntu 22.04, latest version of [base components](#how-it-works) |

| ghcr.io/utrechtuniversity/src-test-workspace | ubuntu_jammy-desktop-pilot | Ubuntu 22.04 with xfce4, latest version of [base components](#how-it-works) |

The repository provides:

Expand Down
3 changes: 3 additions & 0 deletions base/ubuntu/Containerfile_jammy-desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM docker.io/ubuntu:jammy
RUN apt update -y && DEBIAN_FRONTEND=noninteractive apt install -y --no-install-recommends systemd
RUN ln -s /lib/systemd/systemd /sbin/init
2 changes: 1 addition & 1 deletion ubuntu/focal/variables.auto.pkrvars.hcl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
container_repo = "ghcr.io/utrechtuniversity/src-test-workspace:ubuntu_focal"
container_repo = "ghcr.io/utrechtuniversity/src-test-workspace:ubuntu_focal"
img_tag = "ubuntu_focal"
container_base_img = "src-base-ubuntu_focal:latest"
vagrant_base_img = "ubuntu/focal64"
Expand Down
235 changes: 235 additions & 0 deletions ubuntu/jammy-desktop/src-ubuntu.pkr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
variable "source_repo" {
default = "https://github.com/utrechtuniversity/src-test-workspace"
type = string
}

variable "container_repo" {
default = ""
type = string
}

variable "ansible_host" {
default = "packer-src"
type = string
}

variable "enabled_sources" {
default = [
"source.vagrant.ubuntu",
"source.docker.ubuntu",
"source.podman.ubuntu",
]
type = list(string)
}

variable "img_tag_suffix" {
default = "" # no tag suffix by default
type = string
}

variable "workspace_ansible_version" {
default = "9.1.0"
type = string
}

variable "common_ansible_args" {
default = [
"-b",
"--scp-extra-args", # This is required because of a bug in Packer when using SSH>=9.0: https://github.com/hashicorp/packer-plugin-ansible/issues/100
"'-O'",
"-vvvv"
]
type = list(string)
}

variable "co_plugin_args" {
type = map(string)
default = {
"co_totp" = false,
"co_researchdrive" = false,
"co_irods" = false,
"owner_id" = "mocked_id",
"co_user_api_endpoint" = "github.com",
"co_token" = "mocked_token",
"co_name" = "test_co",
"co_id" = "testimage",
"co_passwordless_sudo" = true,
"workspace_id" = "mocked",
"workspace_name" = "src-test-workspace"
}
}

variable "base_packages" {
# It is currently necessary to install jinja2 as an apt package to keep jinja at version ~=2.
# If we don't, jinja2 will be installed by pip as a dependency of ansible (in the external plugin)
# That will cause version 3.1 of jinja to be installed, and this is not compatible with ansible 2.9.
# Ansible 2.9.22 fixes this issue: https://github.com/ansible/ansible/issues/77413
default = "python3 python3-jinja2 python3-virtualenv systemd sudo openssl git gpg gpg-agent cron rsync init tzdata ssh"
type = string
}

variable "extra_packages" {
default = ""
type = string
}

variable "extra_post_commands" {
default = ""
type = string
}

variable "testuser" {
type = map(string)
default = {
username = "testuser"
password = "letmein"
}
}

variable "target_arch" {
default = "linux/amd64"
type = string
}

variable "container_base_img" {
default = ""
type = string
}

variable "vagrant_base_img" {
default = ""
type = string
}

variable "img_name" {
default = "src-test-workspace"
type = string
}

variable "img_tag" {
default = ""
type = string
}

local "ansible_host" {
expression = "${var.ansible_host}-${var.img_tag}"
}

local "dummy_plugin_args" {
expression = {
"remote_ansible_version" = "${var.workspace_ansible_version}",
"remote_plugin" = {
"script_type" = "Ansible PlayBook",
"script_folder" = "../dummy-plugin",
"path" = "dummy.yml",
"parameters" = {},
"arguments" = "-i 127.0.0.1,"
}
}
}

packer {
required_plugins {
podman = {
version = ">=v0.1.0"
source = "github.com/polpetta/podman"
}
docker = {
version = "~> 1"
source = "github.com/hashicorp/docker"
}
ansible = {
source = "github.com/hashicorp/ansible"
version = "~> 1"
}
vagrant = {
source = "github.com/hashicorp/vagrant"
version = "~> 1"
}
}
}

source "podman" "ubuntu" {
image = var.container_base_img
pull = false
commit = true
run_command = ["-d", "-i", "--platform", var.target_arch, "--systemd", "always", "--name", local.ansible_host, var.container_base_img, "/sbin/init"]
changes = [
"LABEL org.opencontainers.image.source=${var.source_repo}"
]
}

source "docker" "ubuntu" {
image = var.container_base_img
platform = var.target_arch
pull = false
commit = true
run_command = ["-d", "-i", "-t", "--privileged", "--name", local.ansible_host, var.container_base_img, "/sbin/init"]
changes = [
"LABEL org.opencontainers.image.source=${var.source_repo}"
]
}

source "vagrant" "ubuntu" {
communicator = "ssh"
source_path = var.vagrant_base_img
provider = "virtualbox"
add_force = true
}

build {
sources = var.enabled_sources

provisioner "shell" {
only = ["docker.ubuntu"]
inline = ["apt update && DEBIAN_FRONTEND=noninteractive apt install --no-install-recommends -y ${var.base_packages} ${var.extra_packages}"]
}

provisioner "ansible" {
playbook_file = "./plugin-os/plugin-os.yml"
extra_arguments = concat(var.common_ansible_args, [
"--skip-tags",
"skip_on_container",
"--extra-vars",
"rsc_os_ip=127.0.0.1 rsc_os_fqdn=${local.ansible_host}.test cloud_type=OpenStack",
])
}

provisioner "ansible" {
playbook_file = "./plugin-co/plugin-co.yml"
extra_arguments = concat(var.common_ansible_args, [
"--extra-vars",
jsonencode(var.co_plugin_args),
])
}

provisioner "ansible" {
playbook_file = "./plugin-external-plugin/plugin-external-plugin.yml"
extra_arguments = concat(var.common_ansible_args, [
"--extra-vars",
jsonencode(local.dummy_plugin_args),
])
}

# The autoremove command run below removes recommended and suggested packages installed by 'apt installs' executed by the components executed above.
# This makes for a smaller image (~260MB), but it may result in errors if further components implicitly rely on those recommended packages.
provisioner "shell" {
inline = [
"useradd -m -s $(which bash) -p $(openssl passwd -1 ${var.testuser.password}) ${var.testuser.username}",
"mkdir -p /etc/rsc/ && echo ${var.testuser.username} > /etc/rsc/managedgroups",
"mkdir -p /var/tmp",
"apt-get autoremove -y -o APT::Autoremove::RecommendsImportant=0 -o APT::Autoremove::SuggestsImportant=0 && apt-get autoclean -y && apt-get clean -y", "rm -rf /tmp/* /var/tmp* /usr/share/doc/* /root/.ansible* /usr/share/man/* /root/.cache /etc/rsc/plugins/*",
"mkdir -p /usr/share/man/man1", # The step above removed all the man pages content, but this directory needs to be present as an install target for subsequent apt installs by components.
var.extra_post_commands
]
}

post-processor "docker-tag" {
only = ["docker.ubuntu"]
repository = "${var.container_repo}${var.img_tag_suffix}"
}
post-processor "shell-local" {
only = ["docker.ubuntu"]
inline = ["docker system prune -f"]
}
}
7 changes: 7 additions & 0 deletions ubuntu/jammy-desktop/variables.auto.pkrvars.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
container_repo = "ghcr.io/utrechtuniversity/src-test-workspace:ubuntu_jammy-desktop"
img_tag = "ubuntu_focal-desktop"
container_base_img = "src-base-ubuntu_jammy-desktop:latest"
vagrant_base_img = "ubuntu/jammy64"
extra_packages = "gdm3 xfce4 xrdp xauth xorgxrdp"
extra_post_commands = "update-alternatives --set x-session-manager /usr/bin/xfce4-session"
workspace_ansible_version = "9.1.0"
2 changes: 1 addition & 1 deletion ubuntu/jammy/variables.auto.pkrvars.hcl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
container_repo = "ghcr.io/utrechtuniversity/src-test-workspace:ubuntu_jammy"
container_repo = "ghcr.io/utrechtuniversity/src-test-workspace:ubuntu_jammy"
img_tag = "ubuntu_jammy"
container_base_img = "src-base-ubuntu_jammy:latest"
vagrant_base_img = "ubuntu/jammy64"
Expand Down

0 comments on commit bf35afc

Please sign in to comment.