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