From b3e3302ecf20032e56510fa704c2a109bfc6f607 Mon Sep 17 00:00:00 2001 From: Shubham Agrawal Date: Fri, 5 Feb 2021 20:02:25 +0530 Subject: [PATCH 1/3] Added AWS codecommit support using access & secret keys --- docker/Dockerfile.linux.amd64 | 26 ++++++++++++++++++++++++++ posix/clone | 12 ++++++++++++ 2 files changed, 38 insertions(+) diff --git a/docker/Dockerfile.linux.amd64 b/docker/Dockerfile.linux.amd64 index af4bfde..d90fa68 100644 --- a/docker/Dockerfile.linux.amd64 +++ b/docker/Dockerfile.linux.amd64 @@ -1,5 +1,31 @@ FROM alpine:3.12 RUN apk add --no-cache ca-certificates git git-lfs openssh curl perl +ENV GLIBC_VER=2.31-r0 +RUN apk --no-cache add \ + binutils \ + curl \ + && curl -sL https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub -o /etc/apk/keys/sgerrand.rsa.pub \ + && curl -sLO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VER}/glibc-${GLIBC_VER}.apk \ + && curl -sLO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VER}/glibc-bin-${GLIBC_VER}.apk \ + && apk add --no-cache \ + glibc-${GLIBC_VER}.apk \ + glibc-bin-${GLIBC_VER}.apk \ + && curl -sL https://awscli.amazonaws.com/awscli-exe-linux-x86_64-2.1.24.zip -o awscliv2.zip \ + && unzip awscliv2.zip \ + && aws/install \ + && rm -rf \ + awscliv2.zip \ + aws \ + /usr/local/aws-cli/v2/*/dist/aws_completer \ + /usr/local/aws-cli/v2/*/dist/awscli/data/ac.index \ + /usr/local/aws-cli/v2/*/dist/awscli/examples \ + && apk --no-cache del \ + binutils \ + curl \ + && rm glibc-${GLIBC_VER}.apk \ + && rm glibc-bin-${GLIBC_VER}.apk \ + && rm -rf /var/cache/apk/* + ADD posix/* /usr/local/bin/ ENTRYPOINT ["/usr/local/bin/clone"] diff --git a/posix/clone b/posix/clone index c197f73..3dc7c27 100755 --- a/posix/clone +++ b/posix/clone @@ -29,6 +29,18 @@ if [[ ! -z "${DRONE_SSH_KEY}" ]]; then ssh-keyscan -H ${DRONE_NETRC_MACHINE} > /etc/ssh/ssh_known_hosts 2> /dev/null fi +# AWS codecommit support using AWS access key & secret key +# Refer: https://docs.aws.amazon.com/codecommit/latest/userguide/setting-up-https-unixes.html + +if [[ ! -z "$DRONE_AWS_ACCESS_KEY" ]]; then + aws configure set aws_access_key_id $DRONE_AWS_ACCESS_KEY + aws configure set aws_secret_access_key $DRONE_AWS_SECRET_KEY + aws configure set default.region $DRONE_AWS_REGION + + git config --global credential.helper '!aws codecommit credential-helper $@' + git config --global credential.UseHttpPath true +fi + # configure git global behavior and parameters via the # following environment variables: From 21eadbab5b9b20031e82f76aa1902affe709f9cc Mon Sep 17 00:00:00 2001 From: Shubham Agrawal Date: Fri, 5 Feb 2021 20:35:55 +0530 Subject: [PATCH 2/3] Fixed test --- posix/posix_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/posix/posix_test.go b/posix/posix_test.go index 337419c..ccf96b9 100644 --- a/posix/posix_test.go +++ b/posix/posix_test.go @@ -166,7 +166,7 @@ func TestPullRequest(t *testing.T) { cmd.Dir = local cmd.Env = []string{ fmt.Sprintf("DRONE_COMMIT_REF=%s", "refs/pull/14596/head"), - fmt.Sprintf("DRONE_COMMIT_BRANCH=%s", "master"), + fmt.Sprintf("DRONE_COMMIT_BRANCH=%s", "main"), fmt.Sprintf("DRONE_COMMIT_SHA=%s", "26923a8f37933ccc23943de0d4ebd53908268582"), fmt.Sprintf("DRONE_WORKSPACE=%s", local), fmt.Sprintf("DRONE_REMOTE_URL=%s", remote), @@ -195,7 +195,7 @@ func TestPullRequest(t *testing.T) { t.Errorf("Want commit %s, got %s", want, got) } - if want, got := "master", branch; got != want { + if want, got := "main", branch; got != want { t.Errorf("Want branch %s, got %s", want, got) } @@ -230,14 +230,14 @@ var tests = []struct { }{ { commit: "9cd29dca0a98f76df94d66493ee54788a18190a0", - branch: "master", + branch: "main", tag: "v1.0.0", file: "hello.txt", text: "hi world\n", }, { commit: "bbdf5d4028a6066431f59fcd8d83afff610a55ae", - branch: "master", + branch: "main", tag: "v1.1.0", file: "hello.txt", text: "hello world\n", From e82207b5918c45f5f43babe73f46da1a7025810d Mon Sep 17 00:00:00 2001 From: Shubham Agrawal Date: Fri, 5 Feb 2021 20:39:03 +0530 Subject: [PATCH 3/3] Fix UT --- posix/posix_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/posix/posix_test.go b/posix/posix_test.go index ccf96b9..a70f214 100644 --- a/posix/posix_test.go +++ b/posix/posix_test.go @@ -230,14 +230,14 @@ var tests = []struct { }{ { commit: "9cd29dca0a98f76df94d66493ee54788a18190a0", - branch: "main", + branch: "master", tag: "v1.0.0", file: "hello.txt", text: "hi world\n", }, { commit: "bbdf5d4028a6066431f59fcd8d83afff610a55ae", - branch: "main", + branch: "master", tag: "v1.1.0", file: "hello.txt", text: "hello world\n",