Skip to content

Commit

Permalink
Add support for podman
Browse files Browse the repository at this point in the history
  • Loading branch information
dometto committed Jul 30, 2024
1 parent c63333e commit a623679
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build image
id: build-image
run: IMG=${{ matrix.images }} ./pack.sh docker
run: IMG=${{ matrix.images }} ./pack.sh podman
- name: Get image name and tag # grep in the image directory's variables file to find the image name/tag to push to
id: get-image-name
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_and_deploy_dispatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build image
id: build-image
run: IMG=${{ matrix.images }} ./pack.sh docker
run: IMG=${{ matrix.images }} ./pack.sh podman
- name: Get image name and tag # grep in the image directory's variables file to find the image name/tag to push to
id: get-image-name
run: |
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SRC-test-workspace

This repository provides a set of scripts and [Packer](https://www.packer.io/) image definitions for building container and VM images and containers that mimic a SURF Research Cloud (SRC) workspace, for development and testing/CI purposes. The Docker image built from this repo are published as a [GitHub package](https://github.com/orgs/UtrechtUniversity/packages/container/package/src-test-workspace) to https://ghcr.io. The following images are available:
This repository provides a set of scripts and [Packer](https://www.packer.io/) image definitions for building container and VM images and containers that mimic a SURF Research Cloud (SRC) workspace, for development and testing/CI purposes. The container image built from this repo are published as a [GitHub package](https://github.com/orgs/UtrechtUniversity/packages/container/package/src-test-workspace) to https://ghcr.io. The following images are available:

| Image name | Tag | Description|
| -- | -- | -- |
Expand All @@ -15,7 +15,7 @@ The repository provides:

Using these templates, you can build local containers or virtual machines that are as close to a workspace as it would be deployed on Research Cloud as possible!

Each image definition can be used to build either container (Docker) images, or VM images. See [below](#Usage).
Each image definition can be used to build either container images (using Docker or Podman), or VM images. See [below](#Usage).

## Requirements

Expand All @@ -28,9 +28,11 @@ Each image definition can be used to build either container (Docker) images, or

To create the default `ubuntu/focal` image:

`./pack.sh [docker,vagrant]`
`./pack.sh [docker,podman,vagrant]`

For example, `./pack.sh docker` will generate a Docker container based on the template, while `./pack.sh vagrant` will create a vagrant VM based on the same.
- `./pack.sh docker` will generate a Docker container.
- `./pack.sh podman` will generate a Podman container.
- `./pack.sh vagrant` will create a vagrant VM.

To select a different image, use the `IMG` environment variable:

Expand Down
20 changes: 19 additions & 1 deletion pack.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash
VALID_SOURCES="docker, vagrant"
VALID_SOURCES="docker, podman, vagrant"
BASE_IMG_PATH="base"

if [ "$#" -lt 1 ]
then
Expand All @@ -11,6 +12,8 @@ if [ -z "$IMG" ]
then
IMG="ubuntu/focal"
fi
OS_NAME=$(echo "$IMG" | cut -f1 -d/)
OS_VERSION=$(basename "$IMG")

if [ -z "$ARCH" ]
then
Expand All @@ -20,13 +23,28 @@ else
fi
echo "Building image for architecture: $ARCH"

PODMAN_SRC="\"sources.podman.ubuntu\""
DOCKER_SRC="\"sources.docker.ubuntu\""
VAGRANT_SRC="\"sources.vagrant.ubuntu\""
TARGETS=()

build_base_img() {
cmd="${1:-docker}"
BASE_IMG_NAME="$OS_NAME"_"$OS_VERSION"
BASE_BUILD_ARGS="build -t src-base-$BASE_IMG_NAME $BASE_IMG_PATH/$OS_NAME -f $BASE_IMG_PATH/$OS_NAME/Containerfile_$OS_VERSION --platform $ARCH"

echo "Building base image for $OS_NAME $OS_VERSION $ARCH"
eval "$cmd $BASE_BUILD_ARGS"
}

for i in "$@" ; do
if [[ $i == "docker" ]] ; then
TARGETS+=("$DOCKER_SRC")
build_base_img 'docker'
fi
if [[ $i == "podman" ]] ; then
TARGETS+=("$PODMAN_SRC")
build_base_img 'podman'
fi
if [[ $i == "vagrant" ]] ; then
TARGETS+=("$VAGRANT_SRC")
Expand Down
4 changes: 2 additions & 2 deletions ubuntu/focal/variables.auto.pkrvars.hcl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
docker_repo = "ghcr.io/utrechtuniversity/src-test-workspace:ubuntu_focal"
img_tag = "ubuntu_focal"
docker_base_img = "ubuntu:focal"
container_base_img = "src-base-ubuntu_focal:latest"
vagrant_base_img = "ubuntu/focal64"
extra_packages = ""
workspace_ansible_version = "2.9"
workspace_ansible_version = "9.0.0"
2 changes: 1 addition & 1 deletion ubuntu/focal_desktop/variables.auto.pkrvars.hcl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
docker_repo = "ghcr.io/utrechtuniversity/src-test-workspace:ubuntu_focal-desktop"
img_tag = "ubuntu_focal-desktop"
docker_base_img = "ubuntu:focal"
container_base_img = "src-base-ubuntu_focal:latest"
vagrant_base_img = "ubuntu/focal64"
extra_packages = "gdm3 xfce4 xrdp xauth xorgxrdp"
extra_post_commands = "update-alternatives --set x-session-manager /usr/bin/xfce4-session"
Expand Down
2 changes: 1 addition & 1 deletion ubuntu/jammy/variables.auto.pkrvars.hcl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
docker_repo = "ghcr.io/utrechtuniversity/src-test-workspace:ubuntu_jammy"
img_tag = "ubuntu_jammy"
docker_base_img = "ubuntu:jammy"
container_base_img = "src-base-ubuntu_jammy:latest"
vagrant_base_img = "ubuntu/jammy64"
extra_packages = ""
workspace_ansible_version = "2.9"
22 changes: 18 additions & 4 deletions ubuntu/src-ubuntu.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ variable "target_arch" {
type = string
}

variable "docker_base_img" {
variable "container_base_img" {
default = ""
type = string
}
Expand Down Expand Up @@ -124,6 +124,10 @@ local "dummy_plugin_args" {

packer {
required_plugins {
podman = {
version = ">=v0.1.0"
source = "github.com/polpetta/podman"
}
docker = {
version = "~> 1"
source = "github.com/hashicorp/docker"
Expand All @@ -139,12 +143,22 @@ packer {
}
}

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.docker_base_img
image = var.container_base_img
platform = var.target_arch
pull = true
pull = false
commit = true
run_command = ["-d", "-i", "-t", "--name", local.ansible_host, var.docker_base_img, "/bin/bash"]
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}"
]
Expand Down

0 comments on commit a623679

Please sign in to comment.