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 2 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
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,38 @@ 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)

# 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,7 @@ 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
tests_must_pass_commands = _generate_tests_must_pass_commands(config)

file_list_vector = File[
Expand Down Expand Up @@ -149,7 +150,11 @@ 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
mount_ssh = any(map(r->occursin("git@", r), registry_urls)) ? "--mount=type=ssh " : ""
Libbum marked this conversation as resolved.
Show resolved Hide resolved
push!(step_list_vector, RunStep(mount_ssh * "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
3 changes: 3 additions & 0 deletions src/types_config.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ struct Config
exclude_packages_from_sysimage::Vector{String}
julia_cpu_target::String
julia_version::Union{String, VersionNumber}
registry_urls::Vector{String}
make_sysimage::Bool
no_test::Vector{String}
packagecompiler_installation_command::String
Expand All @@ -28,6 +29,7 @@ function Config(pkgs::AbstractVector{<:AbstractDict{<:Symbol,<:AbstractString}}
_default_julia_cpu_target(),
julia_version::Union{AbstractString, VersionNumber} =
_default_julia_version(),
registry_urls = String[],
make_sysimage::Bool =
true,
no_test =
Expand All @@ -51,6 +53,7 @@ function Config(pkgs::AbstractVector{<:AbstractDict{<:Symbol,<:AbstractString}}
exclude_packages_from_sysimage,
julia_cpu_target,
julia_version,
registry_urls,
make_sysimage,
no_test,
packagecompiler_installation_command,
Expand Down