Skip to content

Commit

Permalink
Merge pull request #3 from kaweezle/feature/podman
Browse files Browse the repository at this point in the history
✨ Make a podman image
  • Loading branch information
antoinemartin authored Feb 16, 2023
2 parents c3c59b5 + 00434f9 commit 03a4e36
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .github/workflows/base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ jobs:
context: docker
secrets: inherit

build-podman:
needs: [build-base]
uses: ./.github/workflows/build-box.yml
with:
context: podman
secrets: inherit

release-rootfses:
needs: [build-base, build-docker]
runs-on: ubuntu-latest
Expand Down
7 changes: 6 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ FROM ghcr.io/kaweezle/alpine-boxes-base:${BASE_VERSION}
USER root

RUN apk add --no-cache docker && \
rc-update add docker default
rc-update add docker default && \
addgroup alpine docker

COPY ./wsl.conf /etc/wsl.conf
COPY dockeralias.ps1 /dockeralias.ps1

USER alpine

17 changes: 17 additions & 0 deletions docker/dockeralias.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function RunDockerInWsl {
# Take $Env:DOCKER_WSL or 'docker' if undefined
$DockerWSL = if ($null -eq $Env:DOCKER_WSL) { "docker" } else { $Env:DOCKER_WSL }
# Try to find an existing distribution with the name
$existing = Get-ChildItem HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss | Where-Object { $_.GetValue('DistributionName') -eq $DockerWSL }
if ($null -eq $existing) {
# Fail if the distribution doesn't exist
throw "The WSL distribution [$DockerWSL] does not exist !"
} else {
# Ensure docker is started
wsl -d $DockerWSL -u root openrc default
# Perform the requested command
wsl -d $DockerWSL /usr/bin/docker $args
}
}

Set-Alias -Name docker -Value RunDockerInWsl
7 changes: 7 additions & 0 deletions docker/wsl.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# this doesn't work as WSL will kill the process 15 seconds after it has started
# If this is run from the command line, this won't happen.
# [boot]
# command = openrc default

[user]
default = alpine
15 changes: 15 additions & 0 deletions podman/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ARG BASE_VERSION=latest

FROM ghcr.io/kaweezle/alpine-boxes-base:${BASE_VERSION}

USER root

RUN apk add --no-cache podman && \
echo alpine:100000:65536 >>/etc/subuid && \
echo alpine:100000:65536 >>/etc/subgid

COPY ./oci2wsl.sh /usr/local/bin/oci2wsl
COPY ./dockeralias.ps1 /dockeralias.ps1
COPY ./wsl.conf /etc/wsl.conf

USER alpine
15 changes: 15 additions & 0 deletions podman/dockeralias.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function RunPodmanInWsl {
# Take $Env:PODMAN_WSL or 'docker' if undefined
$PodmanWSL = if ($null -eq $Env:PODMAN_WSL) { "podman" } else { $Env:PODMAN_WSL }
# Try to find an existing distribution with the name
$existing = Get-ChildItem HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss | Where-Object { $_.GetValue('DistributionName') -eq $PodmanWSL }
if ($null -eq $existing) {
# Fail if the distribution doesn't exist
throw "The WSL distribution [$PodmanWSL] does not exist !"
} else {
# Perform the requested command
wsl -d $PodmanWSL -u alpine /usr/bin/podman $args
}
}

Set-Alias -Name docker -Value RunPodmanInWsl
38 changes: 38 additions & 0 deletions podman/oci2wsl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env zsh

usage() {
echo "oci2wsl: Create a WSL distribution from an OCI image"
echo
echo "Usage: oci2wsl <image> <name> <directoy>"
echo
exit 1
}

if [ $# -ne 3 ]; then
usage
fi

image="$1"
name="$2"
directory="$3"

if [ ! -d "$directory" ]; then
echo "Error! $directory is not a directory."
usage
fi

ID=$(podman create -q $image 2>/dev/null)
if [ -z "$ID" ]; then
echo "Error! creation of container from $image impossible."
exit 1
fi

podman export $ID | wsl.exe --import $name $directory -

if [ $? -ne 0 ]; then
echo "Error! Creation of the image impossible!"
podman rm $ID >/dev/null
exit 1
fi

podman rm $ID >/dev/null
2 changes: 2 additions & 0 deletions podman/wsl.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[user]
default = alpine

0 comments on commit 03a4e36

Please sign in to comment.