-
Notifications
You must be signed in to change notification settings - Fork 62
DRAFT control-service: AWS Code commit integration #3304
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
Open
SurajViitk
wants to merge
8
commits into
vmware:main
Choose a base branch
from
SurajViitk:vsuraj/git-sts-cc-intg
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3ed9812
Temp to test credentials for aws code commit
15d4c95
Code commit integration
eb1d5df
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 22d3f77
Code commit message builder integration
a0d13f4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] e074075
review comment
8bef395
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 505fb09
bean fix
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
This file contains hidden or 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 hidden or 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 hidden or 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
33 changes: 33 additions & 0 deletions
33
projects/control-service/projects/job-builder-code-commit/Dockerfile
This file contains hidden or 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,33 @@ | ||
| # Used to trigger a build for a data job image. | ||
|
|
||
| FROM gcr.io/kaniko-project/executor | ||
|
|
||
| FROM alpine | ||
|
|
||
| COPY --from=0 /kaniko /kaniko | ||
|
|
||
|
|
||
| ENV PATH $PATH:/kaniko | ||
| ENV SSL_CERT_DIR=/kaniko/ssl/certs | ||
| ENV DOCKER_CONFIG /kaniko/.docker/ | ||
|
|
||
| WORKDIR /workspace | ||
|
|
||
| COPY Dockerfile.python.vdk /workspace/Dockerfile | ||
| COPY build_image.sh /build_image.sh | ||
| RUN chmod +x /build_image.sh | ||
|
|
||
|
|
||
| # Setup Python and Git | ||
| ## Update & Install dependencies | ||
| RUN apk add --no-cache --update \ | ||
| git \ | ||
| bash | ||
|
|
||
| RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/v3.10/main python3=3.7.10-r0 py3-pip \ | ||
| && pip3 install awscli \ | ||
| && pip3 install git-remote-codecommit \ | ||
| && apk --purge -v del py3-pip \ | ||
| && rm -rf /var/cache/apk/* | ||
|
|
||
| ENTRYPOINT ["/build_image.sh"] |
30 changes: 30 additions & 0 deletions
30
projects/control-service/projects/job-builder-code-commit/Dockerfile.python.vdk
This file contains hidden or 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,30 @@ | ||
| # https://docs.docker.com/develop/develop-images/dockerfile_best-practices | ||
|
|
||
| ARG base_image=python:3.9-slim | ||
|
|
||
| FROM $base_image | ||
|
|
||
| ARG UID=1000 | ||
| ARG GID=1000 | ||
|
|
||
| # Set the working directory | ||
| WORKDIR /job | ||
|
|
||
| # Create necessary users and set home directory to /job | ||
| RUN groupadd -r -g $GID group && useradd -u $UID -g $GID -r user && chown -R $UID:$GID /job | ||
| ENV HOME=/job | ||
|
|
||
| # Copy the actual job that has to be executed | ||
| ARG job_name | ||
| COPY --chown=$UID:$GID $job_name $job_name/ | ||
|
|
||
| # TODO: this would trigger for any change in job even if requirements.txt does not change | ||
| # but there's no COPY_IF_EXISTS command in docker to try copy it. | ||
| ARG requirements_file=requirements.txt | ||
| RUN if [ -f "$job_name/$requirements_file" ]; then pip3 install --no-cache-dir --disable-pip-version-check -q -r "$job_name/$requirements_file" || ( echo ">requirements_failed<" && exit 1 ) ; fi | ||
|
|
||
| ARG job_githash | ||
| ENV JOB_NAME $job_name | ||
| ENV VDK_JOB_GITHASH $job_githash | ||
|
|
||
| USER $UID |
1 change: 1 addition & 0 deletions
1
projects/control-service/projects/job-builder-code-commit/README.md
This file contains hidden or 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 @@ | ||
| This package provides a way to configure and build your own Data Job images. |
84 changes: 84 additions & 0 deletions
84
projects/control-service/projects/job-builder-code-commit/build_image.sh
This file contains hidden or 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,84 @@ | ||
| #!/bin/sh | ||
| # Copyright 2023-2024 Broadcom | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| # Copyright 2021-2023 VMware, Inc. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # TODO: replace those as env variables | ||
|
|
||
| aws_access_key_id=$1 | ||
| aws_secret_access_key=$2 | ||
| aws_region=$3 | ||
| docker_registry=$4 | ||
| git_repository=$7 | ||
| registry_type=$8 | ||
| registry_username=$9 | ||
| registry_password=${10} | ||
| aws_session_token=${11} | ||
|
|
||
| # Within this property docker config should be included to connect to the registry used to pull the image from. | ||
| # it should be prefixed with a comma | ||
| # example: ,"ghcr.io/versatile-data-kit-dev/dp/versatiledatakit":{"auth":"dmVyc2F0aWxlLWRhdGEta2l0LWRldjo8bXlUb2tlbj4="}} | ||
| extra_auth=${extra_auth:-""} | ||
| # Echo selected data to be logged | ||
| echo "AWS_REGION=$aws_region" | ||
| echo "DOCKER_REGISTRY=$docker_registry" | ||
| echo "GIT_REPOSITORY=$git_repository" | ||
| echo "REGISTRY_TYPE=$registry_type" | ||
| # We default to generic repo. | ||
| # We have special support for ECR because | ||
| # even though Kaniko supports building and pushing images to ECR | ||
| # it doesn't create repository nor do they think they should support it - | ||
| # https://github.com/GoogleContainerTools/kaniko/pull/1537 | ||
| # And ECR requires for each image to create separate repository | ||
| # And ECR will not create new image repository on docker push | ||
| # So we need to do it manually. | ||
| if [ "$registry_type" = "ecr" ] || [ "$registry_type" = "ECR" ] ; then | ||
| # Setup credentials to connect to AWS - same creds will be used by kaniko as well. | ||
| aws configure set aws_access_key_id $aws_access_key_id | ||
| aws configure set aws_secret_access_key $aws_secret_access_key | ||
|
|
||
| # Check if aws_session_token is set and not empty. | ||
| if [ -n "$aws_session_token" ] ; then | ||
| aws configure set aws_session_token "$aws_session_token" | ||
| fi | ||
| # https://stackoverflow.com/questions/1199613/extract-filename-and-path-from-url-in-bash-script | ||
| repository_prefix=${docker_registry#*/} | ||
| # Create docker repository if it does not exist | ||
| aws ecr describe-repositories --region $aws_region --repository-names $repository_prefix/${DATA_JOB_NAME} || | ||
| aws ecr create-repository --region $aws_region --repository-name $repository_prefix/${DATA_JOB_NAME} | ||
| echo '{ "credsStore": "ecr-login" }' > /kaniko/.docker/config.json | ||
| elif [ "$registry_type" = "generic" ] || [ "$registry_type" = "GENERIC" ]; then | ||
| export auth=$(echo -n $registry_username:$registry_password | base64 -w 0) | ||
| cat > /kaniko/.docker/config.json <<- EOM | ||
| { | ||
| "auths": { | ||
| "$IMAGE_REGISTRY_PATH": { | ||
| "username":"$registry_username", | ||
| "password":"$registry_password", | ||
| "auth": "$auth" | ||
| } | ||
| $extra_auth | ||
| } | ||
| } | ||
| EOM | ||
| #cat /kaniko/.docker/config.json | ||
| fi | ||
| # Clone repo into /data-jobs dir to get job's source | ||
| git clone $git_repository ./data-jobs | ||
| cd ./data-jobs | ||
| git reset --hard $GIT_COMMIT || ( echo ">data-job-not-found<" && exit 1 ) | ||
| if [ ! -d ${DATA_JOB_NAME} ]; then | ||
| echo ">data-job-not-found<" | ||
| exit 1 | ||
| fi | ||
| cd .. | ||
| # kaniko supports building directly from git repository but as we are using codecommit | ||
| # and using aws session credentials, we need to build it beforehand | ||
| /kaniko/executor \ | ||
| --dockerfile=/workspace/Dockerfile \ | ||
| --destination="${IMAGE_REGISTRY_PATH}/${DATA_JOB_NAME}:${GIT_COMMIT}" \ | ||
| --build-arg=job_githash="$JOB_GITHASH" \ | ||
| --build-arg=base_image="$BASE_IMAGE" \ | ||
| --build-arg=job_name="$JOB_NAME" \ | ||
| --context=./data-jobs $EXTRA_ARGUMENTS |
23 changes: 23 additions & 0 deletions
23
projects/control-service/projects/job-builder-code-commit/publish-vdk-job-builder.sh
This file contains hidden or 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 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Copyright 2023-2024 Broadcom | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | ||
| VERSION_TAG=$(cat "$SCRIPT_DIR/version.txt") | ||
| VDK_DOCKER_REGISTRY_URL=${VDK_DOCKER_REGISTRY_URL:-"registry.hub.docker.com/versatiledatakit"} | ||
|
|
||
| function build_and_push_image() { | ||
| name="$1" | ||
| docker_file="$2" | ||
| arguments="$3" | ||
|
|
||
| image_repo="$VDK_DOCKER_REGISTRY_URL/$name" | ||
| image_tag="$image_repo:$VERSION_TAG" | ||
|
|
||
| docker build -t $image_tag -t $image_repo:latest -f "$SCRIPT_DIR/$docker_file" $arguments "$SCRIPT_DIR" | ||
| docker_push_vdk.sh $image_tag | ||
| docker_push_vdk.sh $image_repo:latest | ||
| } | ||
|
|
||
| build_and_push_image "job-builder" Dockerfile |
1 change: 1 addition & 0 deletions
1
projects/control-service/projects/job-builder-code-commit/version.txt
This file contains hidden or 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 @@ | ||
| 1.0.0 |
This file contains hidden or 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 hidden or 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 hidden or 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
27 changes: 27 additions & 0 deletions
27
..._service/src/main/java/com/vmware/taurus/service/upload/CodeCommitCredentialProvider.java
This file contains hidden or 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,27 @@ | ||
| /* | ||
| * Copyright 2023-2024 Broadcom | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package com.vmware.taurus.service.upload; | ||
|
|
||
| import com.vmware.taurus.service.credentials.AWSCredentialsService; | ||
| import org.eclipse.jgit.transport.CredentialsProvider; | ||
| import org.springframework.cloud.config.server.support.AwsCodeCommitCredentialProvider; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Component | ||
| public class CodeCommitCredentialProvider implements VCSCredentialsProvider { | ||
| private final AWSCredentialsService awsCredentialsService; | ||
|
|
||
| public CodeCommitCredentialProvider(AWSCredentialsService awsCredentialsService) { | ||
| this.awsCredentialsService = awsCredentialsService; | ||
| } | ||
|
|
||
| @Override | ||
| public CredentialsProvider getProvider() { | ||
| AwsCodeCommitCredentialProvider codeCommitCredentialProvider = new AwsCodeCommitCredentialProvider(); | ||
| codeCommitCredentialProvider.setAwsCredentialProvider(awsCredentialsService.getCredentialsProvider()); | ||
| return codeCommitCredentialProvider; | ||
| } | ||
| } |
35 changes: 35 additions & 0 deletions
35
...trol_service/src/main/java/com/vmware/taurus/service/upload/CredentialProviderConfig.java
This file contains hidden or 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,35 @@ | ||
| /* | ||
| * Copyright 2023-2024 Broadcom | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package com.vmware.taurus.service.upload; | ||
|
|
||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
|
|
||
| @Configuration | ||
| public class CredentialProviderConfig { | ||
|
|
||
|
|
||
| private final VCSCredentialsProvider credentialsProvider; | ||
|
|
||
| @Autowired | ||
| public CredentialProviderConfig( | ||
| @Value("${datajobs.git.assumeIAMRole}") boolean assumeCodeCommitIAMRole, | ||
| GitCredentialsProvider gitCredentialsProvider, | ||
| CodeCommitCredentialProvider codeCommitProvider) { | ||
| if (assumeCodeCommitIAMRole) { | ||
| this.credentialsProvider = codeCommitProvider; | ||
| } else { | ||
| this.credentialsProvider = gitCredentialsProvider; | ||
| } | ||
| } | ||
|
|
||
| @Bean(name="credentialsProvider") | ||
| public VCSCredentialsProvider credentialsProvider() { | ||
| return credentialsProvider; | ||
| } | ||
| } |
This file contains hidden or 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
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.
why can't you just re use thw git url above ?
then you don't need the if stateent below ?
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.
This is URL expected from Git Remote Code-commit tool, it is following format "codecommit::us-east-1://vdkdata-jobs" and only for this url format, git can fetch from AWS Code Commit repositories
Source - https://github.com/aws/git-remote-codecommit
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.
yes but can't you just set this through {datajobs.git.url} property?
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.
I tested that but code push through jgit didnt work in that case, so I included both the git and grc url, this is a optional property required only if datajobs.git.assumeIAMRole is true, maybe I can add a comment before this field in properties file to clarify this further