-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
e2e: add a test for using private registry with podman driver
This PR adds an e2e test case that stands up a private docker registry and has a podman task run a container from an image in that private registry. Currently the podman driver only supports basic user:pass authentication embeded in the task. We can use this registry to iterate on future support for credentials helpers, etc.
- Loading branch information
Showing
5 changed files
with
252 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# Copyright (c) HashiCorp, Inc. | ||
# SPDX-License-Identifier: MPL-2.0 | ||
|
||
# This job runs a podman task using a container stored in a private registry | ||
# configured with basic authentication. The registry.hcl job should be running | ||
# and healthy before running this job. The registry_address and registry_port | ||
# HCL variables must be provided. | ||
|
||
variable "registry_address" { | ||
type = string | ||
description = "The HTTP address of the local registry" | ||
default = "localhost" | ||
} | ||
|
||
variable "registry_port" { | ||
type = number | ||
description = "The HTTP port of the local registry" | ||
} | ||
|
||
variable "registry_username" { | ||
type = string | ||
description = "The Basic Auth username of the local registry" | ||
default = "e2euser" | ||
} | ||
|
||
variable "registry_password" { | ||
type = string | ||
description = "The Basic Auth password of the local registry" | ||
default = "e2epassword" | ||
} | ||
|
||
locals { | ||
registry_auth = base64encode("${var.registry_username}:${var.registry_password}") | ||
} | ||
|
||
job "auth_basic" { | ||
type = "batch" | ||
|
||
constraint { | ||
attribute = "${attr.kernel.name}" | ||
value = "linux" | ||
} | ||
|
||
group "basic" { | ||
reschedule { | ||
attempts = 0 | ||
unlimited = false | ||
} | ||
|
||
network { | ||
mode = "host" | ||
} | ||
|
||
task "echo" { | ||
driver = "podman" | ||
|
||
# template { | ||
# data = <<EOH | ||
# { | ||
# "auths": { | ||
# "${var.registry_address}:${var.registry_port}": { | ||
# "auth": "${local.registry_auth}" | ||
# } | ||
# } | ||
# } | ||
# EOH | ||
# destination = "local/auth.json" | ||
# } | ||
|
||
config { | ||
image = "${var.registry_address}:${var.registry_port}/docker.io/library/bash:private" | ||
args = ["echo", "The auth basic test is OK!"] | ||
|
||
auth { | ||
username = "e2euser" | ||
password = "e2epassword" | ||
tls_verify = false | ||
} | ||
} | ||
|
||
resources { | ||
cpu = 50 | ||
memory = 32 | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
# Copyright (c) HashiCorp, Inc. | ||
# SPDX-License-Identifier: MPL-2.0 | ||
|
||
# This job stands up a private container registry for use in e2e tests. | ||
# In a post start task we then upload some default images for convenience. | ||
# | ||
# <address>:<port>/docker.io/library/bash:private | ||
# <address>:<port>/docker.io/library/python:private | ||
# | ||
# Note that the <address>:<port> is dynamic and can be found using NSD. | ||
# Note that credentials are required (e.g. podman login), and are | ||
# user: e2euser | ||
# password: e2epassword | ||
|
||
job "registry" { | ||
type = "service" | ||
|
||
constraint { | ||
attribute = "${attr.kernel.name}" | ||
value = "linux" | ||
} | ||
|
||
group "registry-server" { | ||
|
||
reschedule { | ||
attempts = 0 | ||
unlimited = false | ||
} | ||
|
||
network { | ||
mode = "host" | ||
port "registryhttp" {} | ||
} | ||
|
||
service { | ||
provider = "nomad" | ||
name = "registry" | ||
port = "registryhttp" | ||
check { | ||
name = "registry-http" | ||
type = "http" | ||
path = "/" | ||
interval = "10s" | ||
timeout = "3s" | ||
} | ||
} | ||
|
||
task "registry" { | ||
driver = "podman" | ||
|
||
template { | ||
data = <<EOH | ||
e2euser:$2y$05$QpRvGkM/CMG.AG/G7Uh6guULMIlv1ZvjwfPa6dNjdkH.fhTzcpLDC | ||
EOH | ||
destination = "local/auth.txt" | ||
} | ||
|
||
config { | ||
image = "docker.io/library/registry:2" | ||
ports = ["registryhttp"] | ||
network_mode = "host" | ||
} | ||
|
||
env { | ||
REGISTRY_HTTP_ADDR = "${NOMAD_ADDR_registryhttp}" | ||
REGISTRY_AUTH = "htpasswd" | ||
REGISTRY_AUTH_HTPASSWD_REALM = "Registry Realm" | ||
REGISTRY_AUTH_HTPASSWD_PATH = "local/auth.txt" | ||
} | ||
|
||
resources { | ||
cpu = 50 | ||
memory = 128 | ||
} | ||
} | ||
|
||
|
||
task "registry-preload" { | ||
user = "root" | ||
driver = "raw_exec" | ||
|
||
lifecycle { | ||
hook = "poststart" | ||
sidecar = false | ||
} | ||
|
||
template { | ||
data = <<EOH | ||
{ | ||
"auths": { | ||
"localhost:{{- env "NOMAD_PORT_registryhttp" -}}": { | ||
"auth": "ZTJldXNlcjplMmVwYXNzd29yZA==" | ||
} | ||
} | ||
} | ||
EOH | ||
destination = "local/auth.json" | ||
} | ||
|
||
template { | ||
data = <<EOH | ||
set -euo pipefail | ||
podman pull docker.io/library/bash:5 | ||
podman pull docker.io/library/python:3 | ||
podman push --tls-verify=false --authfile=local/auth.json docker.io/library/bash:5 localhost:{{- env "NOMAD_PORT_registryhttp" -}}/docker.io/library/bash:private | ||
podman push --tls-verify=false --authfile=local/auth.json docker.io/library/python:3 localhost:{{- env "NOMAD_PORT_registryhttp" -}}/docker.io/library/python:private | ||
EOH | ||
destination = "local/script.sh" | ||
} | ||
|
||
config { | ||
command = "bash" | ||
args = ["-c", "chmod +x local/script.sh && local/script.sh"] | ||
} | ||
|
||
resources { | ||
cpu = 50 | ||
memory = 32 | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters