-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from opspec-pkgs/multi-registry-auth
add multi registry auth
- Loading branch information
Showing
8 changed files
with
142 additions
and
46 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,14 @@ | ||
name: compile | ||
description: compiles the bin from go source code | ||
inputs: | ||
srcDir: | ||
dir: | ||
description: dir containing source code for bin | ||
default: . | ||
run: | ||
op: | ||
ref: github.com/opspec-pkgs/golang.build.bin#2.0.0 | ||
inputs: | ||
name: setAuths | ||
srcDir: | ||
goVersion: 1.15 |
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
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 |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
|
||
set -e | ||
|
||
/setAuths | ||
|
||
buildctl-daemonless.sh \ | ||
build \ | ||
--frontend dockerfile.v0 \ | ||
|
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,66 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/base64" | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
) | ||
|
||
//RegistryCreds holds auth info for a registry | ||
type RegistryCreds struct { | ||
Username string | ||
Password string | ||
Registry string | ||
} | ||
|
||
// ConfigFile holds a config file | ||
type ConfigFile struct{ | ||
Auths map[string]ConfigFileAuth `json:"auths"` | ||
} | ||
|
||
// ConfigFileAuth holds a config file entry | ||
type ConfigFileAuth struct { | ||
Auth string `json:"auth"` | ||
} | ||
|
||
func main() { | ||
registryCreds := []RegistryCreds{} | ||
registryCredsJSON := os.Getenv("registryCreds") | ||
err := json.Unmarshal([]byte(registryCredsJSON), ®istryCreds) | ||
if nil != err { | ||
panic(err) | ||
} | ||
|
||
auths := map[string]ConfigFileAuth{} | ||
|
||
for _, creds := range registryCreds { | ||
auths[creds.Registry] = ConfigFileAuth{ | ||
Auth: base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", creds.Username, creds.Password))), | ||
} | ||
} | ||
|
||
configFile := ConfigFile{ | ||
Auths: auths, | ||
} | ||
|
||
configFileBytes, err := json.Marshal(configFile) | ||
if nil != err { | ||
panic(err) | ||
} | ||
|
||
err = os.MkdirAll("/root/.docker", 0777) | ||
if nil != err { | ||
panic(err) | ||
} | ||
|
||
err = ioutil.WriteFile( | ||
"/root/.docker/config.json", | ||
configFileBytes, | ||
0777, | ||
) | ||
if nil != err { | ||
panic(err) | ||
} | ||
} |
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