Skip to content

Commit 2f58fb1

Browse files
authored
Merge pull request #181 from adriaanm/2.12.x
Set ACL as public-read for uploads to S3
2 parents f892d9d + d870b49 commit 2f58fb1

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

build.sbt

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import com.typesafe.sbt.SbtGit._
2-
import S3._
2+
import ScalaDist.upload
33

44
// so we don't require a native git install
55
useJGit
@@ -16,9 +16,26 @@ Versioning.settings
1616
// are known/understood, at scala/scala-dist#171
1717
scalaVersion := version.value
1818

19-
s3Settings
19+
mappings in upload := Seq()
2020

21-
host in upload := "downloads.typesafe.com.s3.amazonaws.com"
21+
upload := {
22+
import com.amazonaws.{ClientConfiguration, Protocol}
23+
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain
24+
import com.amazonaws.services.s3.AmazonS3ClientBuilder
25+
import com.amazonaws.services.s3.model.{CannedAccessControlList, PutObjectRequest}
26+
27+
// the publishing job runs on an EC2 instance that has access to the S3 bucket via its IAM instance profile
28+
val client = AmazonS3ClientBuilder.defaultClient
29+
30+
val log = streams.value.log
31+
32+
(mappings in upload).value map { case (file, key) =>
33+
log.debug("Uploading "+ file.getAbsolutePath() +" as "+ key)
34+
35+
// since the s3 bucket is in a separate account from where the EC2 CI instances are, must explicitly set acl as public-read
36+
client.putObject(new PutObjectRequest("downloads.typesafe.com", key, file).withCannedAcl(CannedAccessControlList.PublicRead))
37+
}
38+
}
2239

2340
ScalaDist.settings
2441

project/ScalaDist.scala

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import com.typesafe.sbt.packager.MappingsHelper._
66
import com.typesafe.sbt.packager.universal.UniversalPlugin.autoImport.useNativeZip
77
import com.typesafe.sbt.packager.Keys._
88

9-
import com.typesafe.sbt.S3Plugin.S3.upload
9+
import com.amazonaws.services.s3.model.PutObjectResult
1010

1111
// can't call it Universal -- that's taken by the packager
1212
object ScalaDist {
13+
val upload=TaskKey[Seq[PutObjectResult]]("s3-upload","Uploads files to an S3 bucket.")
14+
1315
def createMappingsWith(deps: Seq[(String, ModuleID, Artifact, File)],
1416
distMappingGen: (ModuleID, Artifact, File) => Seq[(File, String)]): Seq[(File, String)] =
1517
deps flatMap {
@@ -88,13 +90,13 @@ object ScalaDist {
8890

8991
// create mappings from the unzip scala-dist zip
9092
contentOf(tmpdir) filter {
91-
case (file, dest) => !(dest.endsWith("MANIFEST.MF") || dest.endsWith("META-INF"))
93+
case (file, dest) => !(dest.endsWith("MANIFEST.MF") || dest.endsWith("META-INF"))
9294
} map {
9395
// make unix scripts executable (heuristically...)
94-
case (file, dest) if (dest startsWith "bin/") && !(dest endsWith ".bat") =>
96+
case (file, dest) if (dest startsWith "bin/") && !(dest endsWith ".bat") =>
9597
file.setExecutable(true, true)
96-
file -> dest
97-
case mapping => mapping
98+
file -> dest
99+
case mapping => mapping
98100
}
99101

100102
// core jars: use simple name for backwards compat

project/plugins.sbt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ scalacOptions ++= Seq("-deprecation", "-feature", "-Xlint")
22

33
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.0.6")
44

5-
addSbtPlugin("com.typesafe.sbt" % "sbt-s3" % "0.9")
5+
libraryDependencies += "com.amazonaws" % "aws-java-sdk-s3" % "1.11.277"
66

77
// git plugin
88
resolvers += "jgit-repo" at "http://download.eclipse.org/jgit/maven"
99

1010
addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "0.6.4")
11+

0 commit comments

Comments
 (0)