Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add private registry capability #105

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,39 @@ SimpleContainerGenerator.create_dockerfile(pkgs;
run(`docker build -t my_docker_username/my_image_name .`)
```

### Example 8

```julia
import SimpleContainerGenerator

mkpath("my_image_name")
cd("my_image_name")

# Add private registries. General will always be included as a backup.
# The first method uses your ssh credentials, whereas the second requires a
# Personal Access Token.
registry_urls = ["git@github.com:MyCompany/MyPrivateRegistry.git",
"https://username:githubPAT@github.com/MyCompany/AnotherRegistry.git"]

# Optionally, override the URL of your privately registered package. Useful if your registry
# stores the URIs of your packages as git+ssh, but you wish to use PATs in your workflow.
pkgs = [
(name = "Foo", url = "https://username:githubPAT@github.com/MyCompany/MyPackage.jl.git",),
(name = "Bar", ),
(name = "Baz", ),
]
julia_version = v"1.4.0"

SimpleContainerGenerator.create_dockerfile(pkgs;
julia_version = julia_version,
output_directory = pwd(),
registry_urls = registry_urls,
mount_ssh = true) # Only required if using the ssh method

# Note: you may need to `ssh-add` your key before this command will work.
run(`DOCKER_BUILDKIT=1 docker build --ssh default -t my_docker_username/my_image_name .`)
```

## Docker cheatsheet

| Command | Description |
Expand Down
7 changes: 6 additions & 1 deletion src/config_to_template.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ function Template(config::Config)
apt_install = _generate_apt_install_command(config)
julia_url, asc_url = _get_julia_url(config)
parent_image = config.parent_image
registry_urls = config.registry_urls
mount_ssh_string = config.mount_ssh ? "--mount=type=ssh " : ""
tests_must_pass_commands = _generate_tests_must_pass_commands(config)

file_list_vector = File[
Expand Down Expand Up @@ -149,7 +151,10 @@ function Template(config::Config)
push!(step_list_vector, RunStep("chmod 555 /usr/bin/julia"))
push!(step_list_vector, RunStep("chmod 555 /usr/bin/no_sysimage_julia"))
#
push!(step_list_vector, RunStep("cd /tmp; JULIA_DEBUG=all SIMPLECONTAINERGENERATOR_CONTAINER_NO_TEMP_DEPOT=\"true\" /usr/bin/no_sysimage_julia /opt/simplecontainergenerator_containers/install_packages.jl"))
if any(map(r->occursin("git@github", r), registry_urls))
push!(step_list_vector, RunStep("mkdir -p -m 600 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts"))
end
push!(step_list_vector, RunStep(mount_ssh_string * "cd /tmp; JULIA_DEBUG=all SIMPLECONTAINERGENERATOR_CONTAINER_NO_TEMP_DEPOT=\"true\" /usr/bin/no_sysimage_julia /opt/simplecontainergenerator_containers/install_packages.jl"))
#
push!(step_list_vector, RunStep("cd /tmp; JULIA_DEBUG=all /opt/bin/julia /opt/simplecontainergenerator_containers/backups_of_simplecontainergenerator_1.jl"))
push!(step_list_vector, RunStep("cd /tmp; JULIA_DEBUG=all /opt/bin/julia /opt/simplecontainergenerator_containers/backups_of_simplecontainergenerator_2.jl"))
Expand Down
11 changes: 11 additions & 0 deletions src/generate_install_packages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ function _to_packagespec_string(pkgs::AbstractVector{<:AbstractDict})
return "Pkg.Types.PackageSpec[$(join(pkg_strings, ", "))]"
end

function _to_registries_string(registry_urls::Vector{String})
registries = String[]
for registry in registry_urls
push!(registries, "Pkg.Registry.add(Pkg.RegistrySpec(url = \"" * registry * "\"))")
end
isempty(registries) || push!(registries, "Pkg.Registry.add(Pkg.RegistrySpec(url = \"https://github.com/JuliaRegistries/General.git\"))")
return registries
end

function _generate_install_packages_content(config::Config)
pkgs = config.pkgs
no_test = config.no_test
Expand All @@ -30,8 +39,10 @@ function _generate_install_packages_content(config::Config)
end
end
pkgs_string = _to_packagespec_string(pkgs)
registries = _to_registries_string(config.registry_urls)
lines = String[
"import Pkg",
registries...,
"Pkg.add($(pkgs_string))",
"for name in $(pkg_names_to_test) # pkg_names_to_test",
"Pkg.add(name)",
Expand Down
6 changes: 6 additions & 0 deletions src/types_config.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ struct Config
exclude_packages_from_sysimage::Vector{String}
julia_cpu_target::String
julia_version::Union{String, VersionNumber}
registry_urls::Vector{String}
mount_ssh::Bool
make_sysimage::Bool
no_test::Vector{String}
packagecompiler_installation_command::String
Expand All @@ -28,6 +30,8 @@ function Config(pkgs::AbstractVector{<:AbstractDict{<:Symbol,<:AbstractString}}
_default_julia_cpu_target(),
julia_version::Union{AbstractString, VersionNumber} =
_default_julia_version(),
registry_urls = String[],
mount_ssh::Bool = false,
make_sysimage::Bool =
true,
no_test =
Expand All @@ -51,6 +55,8 @@ function Config(pkgs::AbstractVector{<:AbstractDict{<:Symbol,<:AbstractString}}
exclude_packages_from_sysimage,
julia_cpu_target,
julia_version,
registry_urls,
mount_ssh,
make_sysimage,
no_test,
packagecompiler_installation_command,
Expand Down