-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Add support to download context file from Azure Blob Storage #816
Merged
tejal29
merged 14 commits into
GoogleContainerTools:master
from
yangtaokm:azure-blobstorage-https
Oct 25, 2019
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f8e37a2
Set up CI with Azure Pipelines
yangtaokm 062efe1
Merge remote-tracking branch 'upstream/master'
e9af4cf
remove azure-pipelines.yml
e533d45
Merge remote-tracking branch 'upstream/master'
yangtaokm 880b69e
Merge remote-tracking branch 'upstream/master'
yangtaokm cca8814
Merge remote-tracking branch 'upstream/master'
355ed05
Initial commit for Azure Blob Storage SupportX
yangtaokm 3e6a24b
Initial commit for Azure Blob Storage SupportX
yangtaokm 45d58cf
Merge branch 'azure-blostorage-https' of https://github.com/yangtaokm…
yangtaokm 78e9974
Add more test case for azureblob_util.go
yangtaokm a86ffc8
Apply suggestions from code review
yangtaokm 616eb83
Refactory and Code and Merge remote-tracking branch 'upstream/master'…
yangtaokm 45c43a2
refactory the code and add CreateTargetTarfile in fs_util.go
yangtaokm aa881d5
fix gofmt
yangtaokm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: kaniko | ||
spec: | ||
containers: | ||
- name: kaniko | ||
image: gcr.io/kaniko-project/executor:latest | ||
args: ["--dockerfile=<path to Dockerfile within the build context>", | ||
"--context=https://myaccount.blob.core.windows.net/container/path/to/context.tar.gz", | ||
"--destination=<registry for image push>"] | ||
... | ||
env: | ||
- name: AZURE_STORAGE_ACCESS_KEY | ||
valueFrom: | ||
secretKeyRef: | ||
name: azure-storage-access-key | ||
key: azure-storage-access-key | ||
... | ||
volumes: | ||
- name: azure-storage-access-key | ||
secret: | ||
secretName: azure-storage-access-key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
Copyright 2018 Google LLC | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package buildcontext | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"net/url" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/Azure/azure-storage-blob-go/azblob" | ||
"github.com/GoogleContainerTools/kaniko/pkg/constants" | ||
"github.com/GoogleContainerTools/kaniko/pkg/util" | ||
) | ||
|
||
// AzureBlob struct for Azure Blob Storage processing | ||
type AzureBlob struct { | ||
context string | ||
} | ||
|
||
// Download context file from given azure blob storage url and unpack it to BuildContextDir | ||
func (b *AzureBlob) UnpackTarFromBuildContext() (string, error) { | ||
|
||
// Get Azure_STORAGE_ACCESS_KEY from environment variables | ||
accountKey := os.Getenv("AZURE_STORAGE_ACCESS_KEY") | ||
if len(accountKey) == 0 { | ||
return "", errors.New("AZURE_STORAGE_ACCESS_KEY environment variable is not set") | ||
} | ||
|
||
// Get storage accoutname for Azure Blob Storage | ||
u, _ := url.Parse(b.context) | ||
parts := azblob.NewBlobURLParts(*u) | ||
accountName := strings.Split(parts.Host, ".")[0] | ||
|
||
// Generate credentail with accountname and accountkey | ||
credential, err := azblob.NewSharedKeyCredential(accountName, accountKey) | ||
if err != nil { | ||
return parts.Host, err | ||
} | ||
|
||
// Create directory and target file for downloading the context file | ||
directory := constants.BuildContextDir | ||
tarPath := filepath.Join(directory, constants.ContextTar) | ||
file, err := util.CreateTargetTarfile(tarPath) | ||
if err != nil { | ||
return tarPath, err | ||
} | ||
|
||
// Downloading contextfile from Azure Blob Storage | ||
p := azblob.NewPipeline(credential, azblob.PipelineOptions{}) | ||
blobURL := azblob.NewBlobURL(*u, p) | ||
ctx := context.Background() | ||
|
||
if err := azblob.DownloadBlobToFile(ctx, blobURL, 0, 0, file, azblob.DownloadFromBlobOptions{}); err != nil { | ||
return parts.Host, err | ||
} | ||
|
||
if err := util.UnpackCompressedTar(tarPath, directory); err != nil { | ||
return tarPath, err | ||
} | ||
// Remove the tar so it doesn't interfere with subsequent commands | ||
return directory, os.Remove(tarPath) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
Copyright 2018 Google LLC | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package util | ||
|
||
import ( | ||
"regexp" | ||
|
||
"github.com/GoogleContainerTools/kaniko/pkg/constants" | ||
) | ||
|
||
// Validate if the host url provided is with correct suffix for AzureCloud, AzureChinaCloud, AzureGermanCloud and AzureUSGovernment | ||
// RegEX for supported suffix defined in constants.AzureBlobStorageHostRegEx | ||
func ValidAzureBlobStorageHost(context string) bool { | ||
for _, re := range constants.AzureBlobStorageHostRegEx { | ||
validBlobURL := regexp.MustCompile(re) | ||
if validBlobURL.MatchString(context) { | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
examples
should point to a working yaml. Ideally users can just copy and replace the variables. Can you please remove the...