mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-30 10:11:23 +02:00
write netrc file in build images
This commit is contained in:
parent
f3709922b3
commit
f9eda30f3e
@ -66,27 +66,23 @@ func (r *pipeline) run() error {
|
||||
secrets = append(secrets, &model.Secret{
|
||||
Name: "DRONE_NETRC_USERNAME",
|
||||
Value: w.Netrc.Login,
|
||||
Images: r.config.netrc, // TODO(bradrydzewski) use the command line parameters here
|
||||
Events: []string{model.EventDeploy, model.EventPull, model.EventPush, model.EventTag},
|
||||
Images: []string{"*"},
|
||||
Events: []string{"*"},
|
||||
})
|
||||
secrets = append(secrets, &model.Secret{
|
||||
Name: "DRONE_NETRC_PASSWORD",
|
||||
Value: w.Netrc.Password,
|
||||
Images: r.config.netrc,
|
||||
Events: []string{model.EventDeploy, model.EventPull, model.EventPush, model.EventTag},
|
||||
Images: []string{"*"},
|
||||
Events: []string{"*"},
|
||||
})
|
||||
secrets = append(secrets, &model.Secret{
|
||||
Name: "DRONE_NETRC_MACHINE",
|
||||
Value: w.Netrc.Machine,
|
||||
Images: r.config.netrc,
|
||||
Events: []string{model.EventDeploy, model.EventPull, model.EventPush, model.EventTag},
|
||||
Images: []string{"*"},
|
||||
Events: []string{"*"},
|
||||
})
|
||||
}
|
||||
|
||||
for _, secret := range secrets {
|
||||
fmt.Printf("SECRET %s %s\n", secret.Name, secret.Value)
|
||||
}
|
||||
|
||||
trans := []compiler.Transform{
|
||||
builtin.NewCloneOp("git", true),
|
||||
builtin.NewCacheOp(
|
||||
|
@ -34,7 +34,7 @@ func (v *podOp) VisitRoot(node *parse.RootNode) error {
|
||||
service.Container = runner.Container{
|
||||
Name: v.name,
|
||||
Alias: "ambassador",
|
||||
Image: "busybox",
|
||||
Image: "busybox:latest",
|
||||
Entrypoint: []string{"/bin/sleep"},
|
||||
Command: []string{"86400"},
|
||||
Volumes: []string{node.Path, node.Base},
|
||||
|
@ -36,14 +36,14 @@ func (v *shellOp) VisitContainer(node *parse.ContainerNode) error {
|
||||
"/bin/sh", "-c",
|
||||
}
|
||||
node.Container.Command = []string{
|
||||
"echo $CI_CMDS | base64 -d | /bin/sh -e",
|
||||
"echo $DRONE_SCRIPT | base64 -d | /bin/sh -e",
|
||||
}
|
||||
if node.Container.Environment == nil {
|
||||
node.Container.Environment = map[string]string{}
|
||||
}
|
||||
node.Container.Environment["HOME"] = "/root"
|
||||
node.Container.Environment["SHELL"] = "/bin/sh"
|
||||
node.Container.Environment["CI_CMDS"] = toScript(
|
||||
node.Container.Environment["DRONE_SCRIPT"] = toScript(
|
||||
node.Root().Path,
|
||||
node.Commands,
|
||||
)
|
||||
@ -72,7 +72,17 @@ func toScript(base string, commands []string) string {
|
||||
// setupScript is a helper script this is added to the build to ensure
|
||||
// a minimum set of environment variables are set correctly.
|
||||
const setupScript = `
|
||||
echo $DRONE_NETRC > $HOME/.netrc
|
||||
if [ -n "$DRONE_NETRC_MACHINE" ]; then
|
||||
cat <<EOF > $HOME/.netrc
|
||||
machine $DRONE_NETRC_MACHINE
|
||||
login $DRONE_NETRC_USERNAME
|
||||
password $DRONE_NETRC_PASSWORD
|
||||
EOF
|
||||
fi
|
||||
|
||||
unset DRONE_NETRC_USERNAME
|
||||
unset DRONE_NETRC_PASSWORD
|
||||
unset DRONE_SCRIPT
|
||||
|
||||
%s
|
||||
`
|
||||
|
@ -23,7 +23,7 @@ func Test_shell(t *testing.T) {
|
||||
|
||||
g.Assert(len(c.Container.Entrypoint)).Equal(0)
|
||||
g.Assert(len(c.Container.Command)).Equal(0)
|
||||
g.Assert(c.Container.Environment["CI_CMDS"]).Equal("")
|
||||
g.Assert(c.Container.Environment["DRONE_SCRIPT"]).Equal("")
|
||||
})
|
||||
|
||||
g.It("should set entrypoint, command and environment variables", func() {
|
||||
@ -37,8 +37,8 @@ func Test_shell(t *testing.T) {
|
||||
ops.VisitContainer(c)
|
||||
|
||||
g.Assert(c.Container.Entrypoint).Equal([]string{"/bin/sh", "-c"})
|
||||
g.Assert(c.Container.Command).Equal([]string{"echo $CI_CMDS | base64 -d | /bin/sh -e"})
|
||||
g.Assert(c.Container.Environment["CI_CMDS"] != "").IsTrue()
|
||||
g.Assert(c.Container.Command).Equal([]string{"echo $DRONE_SCRIPT | base64 -d | /bin/sh -e"})
|
||||
g.Assert(c.Container.Environment["DRONE_SCRIPT"] != "").IsTrue()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
@ -34,6 +34,8 @@ func (s *Secret) MatchImage(image string) bool {
|
||||
for _, pattern := range s.Images {
|
||||
if match, _ := filepath.Match(pattern, image); match {
|
||||
return true
|
||||
} else if pattern == "*" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
|
@ -29,7 +29,7 @@ func TestSecret(t *testing.T) {
|
||||
g.It("should match any image", func() {
|
||||
secret := Secret{}
|
||||
secret.Images = []string{"*"}
|
||||
g.Assert(secret.MatchImage("golang")).IsTrue()
|
||||
g.Assert(secret.MatchImage("custom/golang")).IsTrue()
|
||||
})
|
||||
g.It("should match any event", func() {
|
||||
secret := Secret{}
|
||||
|
Loading…
Reference in New Issue
Block a user