Exemplo n.º 1
0
Arquivo: swift.go Projeto: armab/drone
func (s *Swift) Write(f *buildfile.Buildfile) {
	var target string
	// All options are required, so ensure they are present
	if len(s.Username) == 0 || len(s.Password) == 0 || len(s.AuthURL) == 0 || len(s.Region) == 0 || len(s.Source) == 0 || len(s.Container) == 0 {
		f.WriteCmdSilent(`echo "Swift: Missing argument(s)"`)
		return
	}

	// If a target was provided, prefix it with a /
	if len(s.Target) > 0 {
		target = fmt.Sprintf("/%s", strings.TrimPrefix(s.Target, "/"))
	}

	// debugging purposes so we can see if / where something is failing
	f.WriteCmdSilent(`echo "Swift: Publishing..."`)

	// install swiftly using PIP
	f.WriteCmdSilent("[ -f /usr/bin/sudo ] || pip install swiftly 1> /dev/null 2> /dev/null")
	f.WriteCmdSilent("[ -f /usr/bin/sudo ] && sudo pip install swiftly 1> /dev/null 2> /dev/null")

	// Write out environment variables
	f.WriteEnv("SWIFTLY_AUTH_URL", s.AuthURL)
	f.WriteEnv("SWIFTLY_AUTH_USER", s.Username)
	f.WriteEnv("SWIFTLY_AUTH_KEY", s.Password)
	f.WriteEnv("SWIFTLY_REGION", s.Region)

	f.WriteCmd(fmt.Sprintf(`swiftly put -i %s %s%s`, s.Source, s.Container, target))
}
Exemplo n.º 2
0
func (n *Nodejitsu) Write(f *buildfile.Buildfile) {
	if len(n.Token) == 0 || len(n.User) == 0 {
		return
	}

	f.WriteEnv("username", n.User)
	f.WriteEnv("apiToken", n.Token)

	// Install the jitsu command line interface then
	// deploy the configured app.
	f.WriteCmdSilent("[ -f /usr/bin/sudo ] || npm install -g jitsu")
	f.WriteCmdSilent("[ -f /usr/bin/sudo ] && sudo npm install -g jitsu")
	f.WriteCmd("jitsu deploy")
}
Exemplo n.º 3
0
// WriteBuild adds only the build steps to the build script,
// omitting publish and deploy steps. This is important for
// pull requests, where deployment would be undesirable.
func (b *Build) WriteBuild(f *buildfile.Buildfile) {
	// append environment variables
	for _, env := range b.Env {
		parts := strings.SplitN(env, "=", 2)
		if len(parts) != 2 {
			continue
		}
		f.WriteEnv(parts[0], parts[1])
	}

	// append build commands
	for _, cmd := range b.Script {
		f.WriteCmd(cmd)
	}
}
Exemplo n.º 4
0
func (m *Modulus) Write(f *buildfile.Buildfile) {
	if len(m.Token) == 0 || len(m.Project) == 0 {
		return
	}
	f.WriteEnv("MODULUS_TOKEN", m.Token)

	// Verify npm exists, otherwise we cannot install the
	// modulus command line utility.
	f.WriteCmdSilent("[ -f /usr/bin/npm ] || echo ERROR: npm is required for modulus.io deployments")
	f.WriteCmdSilent("[ -f /usr/bin/npm ] || exit 1")

	// Install the Modulus command line interface then deploy the configured
	// project.
	f.WriteCmdSilent("[ -f /usr/bin/sudo ] || npm install -g modulus")
	f.WriteCmdSilent("[ -f /usr/bin/sudo ] && sudo npm install -g modulus")
	f.WriteCmd(fmt.Sprintf("modulus deploy -p %q", m.Project))
}
Exemplo n.º 5
0
Arquivo: s3.go Projeto: armab/drone
func (s *S3) Write(f *buildfile.Buildfile) {

	// skip if AWS key or SECRET are empty. A good example for this would
	// be forks building a project. S3 might be configured in the source
	// repo, but not in the fork
	if len(s.Key) == 0 || len(s.Secret) == 0 {
		return
	}

	// debugging purposes so we can see if / where something is failing
	f.WriteCmdSilent("echo 'publishing to Amazon S3 ...'")

	// install the AWS cli using PIP
	f.WriteCmdSilent("[ -f /usr/bin/sudo ] || pip install awscli 1> /dev/null 2> /dev/null")
	f.WriteCmdSilent("[ -f /usr/bin/sudo ] && sudo pip install awscli 1> /dev/null 2> /dev/null")

	f.WriteEnv("AWS_ACCESS_KEY_ID", s.Key)
	f.WriteEnv("AWS_SECRET_ACCESS_KEY", s.Secret)

	// make sure a default region is set
	if len(s.Region) == 0 {
		s.Region = "us-east-1"
	}

	// make sure a default access is set
	// let's be conservative and assume private
	if len(s.Access) == 0 {
		s.Access = "private"
	}

	// if the target starts with a "/" we need
	// to remove it, otherwise we might adding
	// a 3rd slash to s3://
	if strings.HasPrefix(s.Target, "/") {
		s.Target = s.Target[1:]
	}

	switch s.Recursive {
	case true:
		f.WriteCmd(fmt.Sprintf(`aws s3 cp %s s3://%s/%s --recursive --acl %s --region %s`, s.Source, s.Bucket, s.Target, s.Access, s.Region))
	case false:
		f.WriteCmd(fmt.Sprintf(`aws s3 cp %s s3://%s/%s --acl %s --region %s`, s.Source, s.Bucket, s.Target, s.Access, s.Region))
	}
}
Exemplo n.º 6
0
Arquivo: azure.go Projeto: armab/drone
func (a *Azure) Write(f *buildfile.Buildfile) {
	if len(a.StorageAccount) == 0 || len(a.StorageAccessKey) == 0 || len(a.StorageContainer) == 0 || len(a.Source) == 0 {
		return
	}

	f.WriteCmdSilent("echo 'publishing to Azure Storage ...'")

	// install Azure xplat CLI
	f.WriteCmdSilent("[ -f /usr/bin/sudo ] || npm install -g azure-cli 1> /dev/null 2> /dev/null")
	f.WriteCmdSilent("[ -f /usr/bin/sudo ] && sudo npm install -g azure-cli 1> /dev/null 2> /dev/null")

	f.WriteEnv("AZURE_STORAGE_ACCOUNT", a.StorageAccount)
	f.WriteEnv("AZURE_STORAGE_ACCESS_KEY", a.StorageAccessKey)

	// if target isn't specified, set to source
	if len(a.Target) == 0 {
		a.Target = a.Source
	}

	f.WriteCmd(fmt.Sprintf(`azure storage blob upload --container %s %s %s`, a.StorageContainer, a.Source, a.Target))
}
Exemplo n.º 7
0
Arquivo: ssh.go Projeto: armab/drone
// Write down the buildfile
func (s *SSH) Write(f *buildfile.Buildfile) {
	host := strings.SplitN(s.Target, " ", 2)
	if len(host) == 1 {
		host = append(host, "22")
	}
	if _, err := strconv.Atoi(host[1]); err != nil {
		host[1] = "22"
	}

	// Is artifact created?
	artifact := false

	for _, a := range s.Artifacts {
		if a == "GITARCHIVE" {
			artifact = createGitArchive(f)
			break
		}
	}

	if !artifact {
		if len(s.Artifacts) > 1 {
			artifact = compress(f, s.Artifacts)
		} else if len(s.Artifacts) == 1 {
			f.WriteEnv("ARTIFACT", s.Artifacts[0])
			artifact = true
		}
	}

	if artifact {
		scpCmd := "scp -o StrictHostKeyChecking=no -P %s -r ${ARTIFACT} %s"
		f.WriteCmd(fmt.Sprintf(scpCmd, host[1], host[0]))
	}

	if len(s.Cmd) > 0 {
		sshCmd := "ssh -o StrictHostKeyChecking=no -p %s %s %q"
		f.WriteCmd(fmt.Sprintf(sshCmd, host[1], strings.SplitN(host[0], ":", 2)[0], s.Cmd))
	}
}
Exemplo n.º 8
0
Arquivo: ssh.go Projeto: armab/drone
func compress(f *buildfile.Buildfile, files []string) bool {
	cmd := "tar -cf ${ARTIFACT} %s"
	f.WriteEnv("ARTIFACT", "${PWD##*/}.tar.gz")
	f.WriteCmdSilent(fmt.Sprintf(cmd, strings.Join(files, " ")))
	return true
}
Exemplo n.º 9
0
Arquivo: ssh.go Projeto: armab/drone
func createGitArchive(f *buildfile.Buildfile) bool {
	f.WriteEnv("COMMIT", "$(git rev-parse HEAD)")
	f.WriteEnv("ARTIFACT", "${PWD##*/}-${COMMIT}.tar.gz")
	f.WriteCmdSilent("git archive --format=tar.gz --prefix=${PWD##*/}/ ${COMMIT} > ${ARTIFACT}")
	return true
}
Exemplo n.º 10
0
// Write adds commands to run that will publish a Github release.
func (g *Github) Write(f *buildfile.Buildfile) {
	if len(g.Artifacts) == 0 || g.Tag == "" || g.Token == "" || g.User == "" || g.Repo == "" {
		f.WriteCmdSilent(`echo -e "Github Plugin: Missing argument(s)"\n\n`)
		if len(g.Artifacts) == 0 {
			f.WriteCmdSilent(`echo -e "\tartifacts not defined in yaml config" && false`)
		}
		if g.Tag == "" {
			f.WriteCmdSilent(`echo -e "\ttag not defined in yaml config" && false`)
		}
		if g.Token == "" {
			f.WriteCmdSilent(`echo -e "\ttoken not defined in yaml config" && false`)
		}
		if g.User == "" {
			f.WriteCmdSilent(`echo -e "\tuser not defined in yaml config" && false`)
		}
		if g.Repo == "" {
			f.WriteCmdSilent(`echo -e "\trepo not defined in yaml config" && false`)
		}
		return
	}

	// Default name is tag
	if g.Name == "" {
		g.Name = g.Tag
	}

	for _, cmd := range g.Script {
		f.WriteCmd(cmd)
	}

	f.WriteEnv("GITHUB_TOKEN", g.Token)

	// Install github-release
	f.WriteCmd("curl -L -o /tmp/github-release.tar.bz2 https://github.com/aktau/github-release/releases/download/v0.5.2/linux-amd64-github-release.tar.bz2")
	f.WriteCmd("tar jxf /tmp/github-release.tar.bz2 -C /tmp/ && sudo mv /tmp/bin/linux/amd64/github-release /usr/local/bin/github-release")

	// Create the release. Ignore 422 errors, which indicate the tag has already been created.
	// Doing otherwise would create the expectation that every commit should be tagged and released,
	// which is not the norm.
	draftStr := ""
	if g.Draft {
		draftStr = "--draft"
	}
	prereleaseStr := ""
	if g.Prerelease {
		prereleaseStr = "--pre-release"
	}
	f.WriteCmd(fmt.Sprintf(`
result=$(github-release release -u %s -r %s -t %s -n "%s" -d "%s" %s %s || true)
if [[ $result == *422* ]]; then
  echo -e "Release already exists for this tag.";
  exit 0
elif [[ $result == "" ]]; then
  echo -e "Release created.";
else
  echo -e "Error creating release: $result"
  exit 1
fi
`, g.User, g.Repo, g.Tag, g.Name, g.Description, draftStr, prereleaseStr))

	// Upload files
	artifactStr := strings.Join(g.Artifacts, " ")
	f.WriteCmd(fmt.Sprintf(`
for f in %s; do
    # treat directories and files differently
    if [ -d $f ]; then
        for ff in $(ls $f); do
            echo -e "uploading $ff"
            github-release upload -u %s -r %s -t %s -n $ff -f $f/$ff
        done
    elif [ -f $f ]; then
        echo -e "uploading $f"
        github-release upload -u %s -r %s -t %s -n $f -f $f
    else
        echo -e "$f is not a file or directory"
        exit 1
    fi
done
`, artifactStr, g.User, g.Repo, g.Tag, g.User, g.Repo, g.Tag))
}