diff --git a/Gopkg.lock b/Gopkg.lock index f551c2e6f..3b2c1960e 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -17,6 +17,14 @@ revision = "aad3f485ee528456e0768f20397b4d9dd941e755" version = "v0.25.0" +[[projects]] + digest = "1:602649ff074ccee9273e1d3b25c4069f13a70fa0c232957c7d68a6f02fb7a9ea" + name = "github.com/Azure/azure-pipeline-go" + packages = ["pipeline"] + pruneopts = "NUT" + revision = "232aee85e8e3a6223a11c0943f7df2ae0fac00e4" + version = "v0.2.2" + [[projects]] digest = "1:f56288257633effcb1743f6fa77d12dd3eaeeb5c78b3de6e199eb1b4780f57f5" name = "github.com/Azure/azure-sdk-for-go" @@ -28,6 +36,14 @@ revision = "4e8cbbfb1aeab140cd0fa97fd16b64ee18c3ca6a" version = "v19.1.0" +[[projects]] + digest = "1:0a1307390445735712b3b914b447cc7ad1974795e50470b7e092cfaa6063f6dd" + name = "github.com/Azure/azure-storage-blob-go" + packages = ["azblob"] + pruneopts = "NUT" + revision = "fc700035fe4a7020f50d49f420b3c088aed57e03" + version = "v0.8.0" + [[projects]] branch = "master" digest = "1:81f8c061c3d18ed1710957910542bc17d2b789c6cd19e0f654c30b35fd255ca5" @@ -445,7 +461,7 @@ version = "v0.2.0" [[projects]] - digest = "1:5924704ec96f00247784c512cc57f45a595030376a7ff2ff993bf356793a2cb0" + digest = "1:c94f3440939c4a6e4ad6db6cd9315c7817ea6c04fe28cfe2aaae2099d2bc3cef" name = "github.com/google/go-containerregistry" packages = [ "pkg/authn", @@ -466,6 +482,7 @@ "pkg/v1/tarball", "pkg/v1/types", "pkg/v1/v1util", + "pkg/v1/validate", ] pruneopts = "NUT" revision = "31e00cede111067bae48bfc2cbfc522b0b36207f" @@ -604,6 +621,14 @@ revision = "81db2a75821ed34e682567d48be488a1c3121088" version = "0.5" +[[projects]] + branch = "master" + digest = "1:e0e7ecd8a4d1faddfb4b7e8a59684f803aa7f45489e25a64bb25d63691d4fc7a" + name = "github.com/mattn/go-ieproxy" + packages = ["."] + pruneopts = "NUT" + revision = "f9202b1cfdeb0c82ddd3dc1e8e9cd94b3c0c1b13" + [[projects]] digest = "1:d0164259ed17929689df11205194d80288e8ae25351778f7a3421a24774c36f8" name = "github.com/mattn/go-shellwords" @@ -957,12 +982,13 @@ [[projects]] branch = "master" - digest = "1:f3e57ce909415ab28ce6c6db1fa7bf7a9134c8d9cb53663775d766b515a665d8" + digest = "1:d3ff7173b1da34e8fc91c30e8695c830bf5d7d7b0851fb8bdfb71fa862e9cf00" name = "golang.org/x/net" packages = [ "context", "context/ctxhttp", "http/httpguts", + "http/httpproxy", "http2", "http2/hpack", "idna", @@ -1372,6 +1398,7 @@ analyzer-version = 1 input-imports = [ "cloud.google.com/go/storage", + "github.com/Azure/azure-storage-blob-go/azblob", "github.com/aws/aws-sdk-go/aws", "github.com/aws/aws-sdk-go/aws/session", "github.com/aws/aws-sdk-go/service/s3", @@ -1395,6 +1422,7 @@ "github.com/google/go-containerregistry/pkg/v1/random", "github.com/google/go-containerregistry/pkg/v1/remote", "github.com/google/go-containerregistry/pkg/v1/tarball", + "github.com/google/go-containerregistry/pkg/v1/validate", "github.com/google/go-github/github", "github.com/karrick/godirwalk", "github.com/minio/HighwayHash", diff --git a/Gopkg.toml b/Gopkg.toml index 64aa95abe..d77fa3382 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -50,3 +50,7 @@ required = [ [[constraint]] name = "github.com/minio/HighwayHash" version = "1.0.0" + +[[constraint]] + name = "github.com/Azure/azure-storage-blob-go" + version = "0.8.0" diff --git a/README.md b/README.md index 11577d87b..44ccb5876 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,7 @@ You will need to store your build context in a place that kaniko can access. Right now, kaniko supports these storage solutions: - GCS Bucket - S3 Bucket +- Azure Blob Storage - Local Directory - Git Repository @@ -123,14 +124,18 @@ When running kaniko, use the `--context` flag with the appropriate prefix to spe | Source | Prefix | Example | |---------|---------|---------| -| Local Directory | dir://[path to a directory in the kaniko container] | `dir:///workspace` | -| GCS Bucket | gs://[bucket name]/[path to .tar.gz] | `gs://kaniko-bucket/path/to/context.tar.gz` | -| S3 Bucket | s3://[bucket name]/[path to .tar.gz] | `s3://kaniko-bucket/path/to/context.tar.gz` | -| Git Repository | git://[repository url][#reference] | `git://github.com/acme/myproject.git#refs/heads/mybranch` | +| Local Directory | dir://[path to a directory in the kaniko container] | `dir:///workspace` | +| GCS Bucket | gs://[bucket name]/[path to .tar.gz] | `gs://kaniko-bucket/path/to/context.tar.gz` | +| S3 Bucket | s3://[bucket name]/[path to .tar.gz] | `s3://kaniko-bucket/path/to/context.tar.gz` | +| Azure Blob Storage| https://[account].[azureblobhostsuffix]/[container]/[path to .tar.gz] | `https://myaccount.blob.core.windows.net/container/path/to/context.tar.gz` | +| Git Repository | git://[repository url][#reference] | `git://github.com/acme/myproject.git#refs/heads/mybranch` | If you don't specify a prefix, kaniko will assume a local directory. For example, to use a GCS bucket called `kaniko-bucket`, you would pass in `--context=gs://kaniko-bucket/path/to/context.tar.gz`. +### Using Azure Blob Storage +If you are using Azure Blob Storage for context file, you will need to pass [Azure Storage Account Access Key](https://docs.microsoft.com/en-us/azure/storage/common/storage-configure-connection-string?toc=%2fazure%2fstorage%2fblobs%2ftoc.json) as an evironment variable named `AZURE_STORAGE_ACCESS_KEY` through Kubernetes Secrets + ### Using Private Git Repository You can use `Personal Access Tokens` for Build Contexts from Private Repositories from [GitHub](https://blog.github.com/2012-09-21-easier-builds-and-deployments-using-git-over-https-and-oauth/). diff --git a/pkg/buildcontext/buildcontext.go b/pkg/buildcontext/buildcontext.go index 032f69fac..3142239a8 100644 --- a/pkg/buildcontext/buildcontext.go +++ b/pkg/buildcontext/buildcontext.go @@ -21,6 +21,7 @@ import ( "strings" "github.com/GoogleContainerTools/kaniko/pkg/constants" + "github.com/GoogleContainerTools/kaniko/pkg/util" ) // BuildContext unifies calls to download and unpack the build context. @@ -35,6 +36,7 @@ func GetBuildContext(srcContext string) (BuildContext, error) { split := strings.SplitAfter(srcContext, "://") prefix := split[0] context := split[1] + switch prefix { case constants.GCSBuildContextPrefix: return &GCS{context: context}, nil @@ -44,6 +46,11 @@ func GetBuildContext(srcContext string) (BuildContext, error) { return &Dir{context: context}, nil case constants.GitBuildContextPrefix: return &Git{context: context}, nil + case constants.HTTPSBuildContextPrefix: + if util.ValidAzureBlobStorageHost(srcContext) { + return &AzureBlob{context: srcContext}, nil + } + return nil, errors.New("url provided for https context is not in a supported format, please use the https url for Azure Blob Storage") } - return nil, errors.New("unknown build context prefix provided, please use one of the following: gs://, dir://, s3://, git://") + return nil, errors.New("unknown build context prefix provided, please use one of the following: gs://, dir://, s3://, git://, https://") } diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go index d0d84e3f3..699b13355 100644 --- a/pkg/constants/constants.go +++ b/pkg/constants/constants.go @@ -58,6 +58,7 @@ const ( S3BuildContextPrefix = "s3://" LocalDirBuildContextPrefix = "dir://" GitBuildContextPrefix = "git://" + HTTPSBuildContextPrefix = "https://" HOME = "HOME" // DefaultHOMEValue is the default value Docker sets for $HOME @@ -78,3 +79,10 @@ const ( // ScratchEnvVars are the default environment variables needed for a scratch image. var ScratchEnvVars = []string{"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"} + +//AzureBlobStorageHostRegEx is ReqEX for Valid azure blob storage host suffix in url for AzureCloud, AzureChinaCloud, AzureGermanCloud and AzureUSGovernment +var AzureBlobStorageHostRegEx = []string{"https://(.+?).blob.core.windows.net/(.+)", + "https://(.+?).blob.core.chinacloudapi.cn/(.+)", + "https://(.+?).blob.core.cloudapi.de/(.+)", + "https://(.+?).blob.core.usgovcloudapi.net/(.+)", +}