From 9725b8de69c255a3eb5b99681a1bcbbb7ec144d5 Mon Sep 17 00:00:00 2001 From: Andrea Luzzardi Date: Fri, 12 Mar 2021 16:14:00 -0800 Subject: [PATCH 1/5] test: add secrets for testing Signed-off-by: Andrea Luzzardi --- .gitattributes | 3 +++ tests/test-lib.sh | 8 ++++++++ tests/test.secret | Bin 0 -> 163 bytes tests/test.sh | 42 ++++++++++++++++++++++++++++-------------- 4 files changed, 39 insertions(+), 14 deletions(-) create mode 100644 .gitattributes create mode 100644 tests/test.secret diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..00b39fdf --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +*.secret filter=git-crypt diff=git-crypt +*.key filter=git-crypt diff=git-crypt +*.secret.* filter=git-crypt diff=git-crypt diff --git a/tests/test-lib.sh b/tests/test-lib.sh index 34f5780e..242ee92f 100644 --- a/tests/test-lib.sh +++ b/tests/test-lib.sh @@ -130,3 +130,11 @@ test::one(){ disable(){ logger::warning "Test \"$2\" has been disabled." } + +secret(){ + if [ -z "${DAGGER_SECRETS_LOADED+x}" ] || [ "$DAGGER_SECRETS_LOADED" != "1" ]; then + logger::warning "Skip \"$2\": secrets not available" + else + "$@" + fi +} diff --git a/tests/test.secret b/tests/test.secret new file mode 100644 index 0000000000000000000000000000000000000000..82cd5d6c9a7127c5e086dbca95e4785e6d496380 GIT binary patch literal 163 zcmV;U09^k7M@dveQdv+`04r)@kO(t==*nOiRD)IVOS?@U__WGO$Vz${+1c9>>+Qv0 zagOiq))m^2Y%iw;D^#kY_e2oQ<+KY_Fk=lW5NzIlkpTZwsXZX1D5_ZCtPPpA))ifu zpiF?2G7SL%vcWD)k?tVdBRAD_%pp933oG*%)d8Prq#M0AoBY+idvfrNRi-HJd&u3| R_}OY~0W?5vu06{Kt?0)HO(y^V literal 0 HcmV?d00001 diff --git a/tests/test.sh b/tests/test.sh index f9843843..e38e2425 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -6,6 +6,11 @@ readonly d=$(cd "$(dirname "${BASH_SOURCE[0]:-$PWD}")" 2>/dev/null 1>&2 && pwd) # shellcheck source=/dev/null . "$d/test-lib.sh" +# shellcheck source=/dev/null +if grep -q "DAGGER_SECRETS" "$d/test.secret"; then + source "$d/test.secret" +fi + # Point this to your dagger binary readonly DAGGER_BINARY="${DAGGER_BINARY:-$d/../cmd/dagger/dagger}" # The default arguments are a no-op, but having "anything" is a little cheat necessary for "${DAGGER_BINARY_ARGS[@]}" to not be empty down there @@ -86,6 +91,14 @@ test::fetchcontainer(){ "$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/fetch-container/nonexistent/image-with-valid-digest } +test::pushcontainer(){ + local dagger="$1" + + # Fetch container + secret test::one "FetchContainer: valid containers" --exit=0 \ + "$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/fetch-container/exist +} + test::fetchgit(){ local dagger="$1" @@ -244,22 +257,23 @@ test::dockerbuild() { test::all(){ local dagger="$1" - test::load "$dagger" - test::mount "$dagger" +# test::load "$dagger" +# test::mount "$dagger" - test::copy "$dagger" - test::local "$dagger" - test::compute "$dagger" - test::fetchcontainer "$dagger" - test::fetchgit "$dagger" - test::exec "$dagger" - test::export "$dagger" - test::input "$dagger" - test::subdir "$dagger" - test::dockerbuild "$dagger" +# test::copy "$dagger" +# test::local "$dagger" +# test::compute "$dagger" +# test::fetchcontainer "$dagger" + test::pushcontainer "$dagger" +# test::fetchgit "$dagger" +# test::exec "$dagger" +# test::export "$dagger" +# test::input "$dagger" +# test::subdir "$dagger" +# test::dockerbuild "$dagger" - test::stdlib "$dagger" - test::examples "$dagger" +# test::stdlib "$dagger" +# test::examples "$dagger" } case "${1:-all}" in From 9887166c7180479027b168e4e00ab6cbdf9991ed Mon Sep 17 00:00:00 2001 From: Andrea Luzzardi Date: Fri, 12 Mar 2021 16:42:07 -0800 Subject: [PATCH 2/5] test: add push-container Signed-off-by: Andrea Luzzardi --- tests/push-container/main.cue | 56 +++++++++++++++++++++++++++++++++++ tests/test.sh | 34 ++++++++++----------- 2 files changed, 72 insertions(+), 18 deletions(-) create mode 100644 tests/push-container/main.cue diff --git a/tests/push-container/main.cue b/tests/push-container/main.cue new file mode 100644 index 00000000..cb54bdf4 --- /dev/null +++ b/tests/push-container/main.cue @@ -0,0 +1,56 @@ +package main + +import ( + "dagger.io/dagger" + "dagger.io/alpine" +) + +TestPushContainer: { + // Generate a random number + random: { + string + #compute: [ + dagger.#Load & {from: alpine.#Image}, + dagger.#Exec & { + args: ["sh", "-c", "echo -n $RANDOM > /rand"] + }, + dagger.#Export & { + source: "/rand" + }, + ] + } + + // Push an image with a random tag + push: { + ref: "daggerio/ci-test:\(random)" + #compute: [ + dagger.#WriteFile & { + content: random + dest: "/rand" + }, + dagger.#PushContainer & { + "ref": ref + }, + ] + } + + // Pull the image back + pull: #compute: [ + dagger.#FetchContainer & { + ref: push.ref + }, + ] + + // Check the content + check: #compute: [ + dagger.#Load & {from: alpine.#Image}, + dagger.#Exec & { + args: [ + "sh", "-c", #""" + test "$(cat /src/rand)" = "\#(random)" + """#, + ] + mount: "/src": from: pull + }, + ] +} diff --git a/tests/test.sh b/tests/test.sh index e38e2425..21c7935c 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -94,9 +94,8 @@ test::fetchcontainer(){ test::pushcontainer(){ local dagger="$1" - # Fetch container - secret test::one "FetchContainer: valid containers" --exit=0 \ - "$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/fetch-container/exist + secret test::one "PushContainer: simple" --exit=0 \ + "$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/push-container } test::fetchgit(){ @@ -214,7 +213,6 @@ test::local(){ disable "" "There are no local tests right now (the feature is possibly not functioning at all: see https://github.com/blocklayerhq/dagger/issues/41)" } - test::mount(){ test::one "Mount: tmpfs" --exit=0 \ "$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/mounts/valid/tmpfs @@ -257,23 +255,23 @@ test::dockerbuild() { test::all(){ local dagger="$1" -# test::load "$dagger" -# test::mount "$dagger" + test::load "$dagger" + test::mount "$dagger" -# test::copy "$dagger" -# test::local "$dagger" -# test::compute "$dagger" -# test::fetchcontainer "$dagger" + test::copy "$dagger" + test::local "$dagger" + test::compute "$dagger" + test::fetchcontainer "$dagger" test::pushcontainer "$dagger" -# test::fetchgit "$dagger" -# test::exec "$dagger" -# test::export "$dagger" -# test::input "$dagger" -# test::subdir "$dagger" -# test::dockerbuild "$dagger" + test::fetchgit "$dagger" + test::exec "$dagger" + test::export "$dagger" + test::input "$dagger" + test::subdir "$dagger" + test::dockerbuild "$dagger" -# test::stdlib "$dagger" -# test::examples "$dagger" + test::stdlib "$dagger" + test::examples "$dagger" } case "${1:-all}" in From e7ecc8763152ed6f89dbf4a6f313c276549eb0b7 Mon Sep 17 00:00:00 2001 From: Andrea Luzzardi Date: Fri, 12 Mar 2021 16:42:17 -0800 Subject: [PATCH 3/5] ci: login to dockerhub Signed-off-by: Andrea Luzzardi --- .github/workflows/ci.yml | 17 ++++++++++++++--- tests/test.secret | Bin 163 -> 180 bytes 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 351e2572..5617824e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,15 +11,26 @@ jobs: name: Build runs-on: ubuntu-latest steps: + - name: Check out + uses: actions/checkout@v2 + + - name: Unlock secrets + uses: sliteteam/github-action-git-crypt-unlock@1.2.0 + env: + GIT_CRYPT_KEY: ${{ secrets.GIT_CRYPT_KEY }} + + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Set up Go uses: actions/setup-go@v1 with: go-version: 1.16 id: go - - name: Check out - uses: actions/checkout@v2 - - name: Install Dependencies run: | sudo apt-get update diff --git a/tests/test.secret b/tests/test.secret index 82cd5d6c9a7127c5e086dbca95e4785e6d496380..17fca195f17246dd8f381df91f654732acec338b 100644 GIT binary patch literal 180 zcmV;l089S>M@dveQdv+`0GxRSOxqk5CacMR0T!thl(xM8)xHoI;3{)s15PM_aXu>y z-PVWw{k^E}KEw$XiZ6eWD`ZHvLrptVfaP8Rj#?)qp+OHt%paz*CBoD-5fIDCA)#hk z40KSpz6c=uRZ34@j>irNKio3gW(y7io4f3enhieHvHeHfGN0K_U#E>+Qv0 zagOiq))m^2Y%iw;D^#kY_e2oQ<+KY_Fk=lW5NzIlkpTZwsXZX1D5_ZCtPPpA))ifu zpiF?2G7SL%vcWD)k?tVdBRAD_%pp933oG*%)d8Prq#M0AoBY+idvfrNRi-HJd&u3| R_}OY~0W?5vu06{Kt?0)HO(y^V From 19b9ec2721cfd3e75a85948ac424a60847ea6e8d Mon Sep 17 00:00:00 2001 From: Andrea Luzzardi Date: Fri, 12 Mar 2021 17:20:05 -0800 Subject: [PATCH 4/5] ci: remove build, already done by integration tests Signed-off-by: Andrea Luzzardi --- .github/workflows/ci.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5617824e..ae29bf9d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,9 +43,6 @@ jobs: curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sudo sh -s -- -b /usr/local/bin v1.23.8 curl -L https://github.com/cuelang/cue/releases/download/${CUE_VERSION}/${CUE_TARBALL} | sudo tar zxf - -C /usr/local/bin - - name: Build - run: | - make - name: Lint run: | From 5ccf617245c7e81b19f2b956fdae07e810be131c Mon Sep 17 00:00:00 2001 From: Andrea Luzzardi Date: Fri, 12 Mar 2021 17:24:52 -0800 Subject: [PATCH 5/5] ci: install git-crypt Signed-off-by: Andrea Luzzardi --- .github/workflows/ci.yml | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ae29bf9d..8b6209f9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,10 +14,26 @@ jobs: - name: Check out uses: actions/checkout@v2 + - name: Install Dependencies + run: | + sudo apt-get update + sudo apt-get install -y --no-install-recommends shellcheck git-crypt + + export CUE_VERSION="$(grep cue ./go.mod | cut -d' ' -f2)" + export CUE_TARBALL="cue_${CUE_VERSION}_linux_amd64.tar.gz" + + echo "Installing cue version $CUE_VERSION" + curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sudo sh -s -- -b /usr/local/bin v1.23.8 + + curl -L https://github.com/cuelang/cue/releases/download/${CUE_VERSION}/${CUE_TARBALL} | sudo tar zxf - -C /usr/local/bin + - name: Unlock secrets - uses: sliteteam/github-action-git-crypt-unlock@1.2.0 env: GIT_CRYPT_KEY: ${{ secrets.GIT_CRYPT_KEY }} + run: | + echo "$GIT_CRYPT_KEY" | base64 -d > /tmp/git-crypt-key + git-crypt unlock /tmp/git-crypt-key + rm -f /tmp/git-crypt-key - name: Login to Docker Hub uses: docker/login-action@v1 @@ -31,19 +47,6 @@ jobs: go-version: 1.16 id: go - - name: Install Dependencies - run: | - sudo apt-get update - sudo apt-get install -y --no-install-recommends shellcheck - - export CUE_VERSION="$(grep cue ./go.mod | cut -d' ' -f2)" - export CUE_TARBALL="cue_${CUE_VERSION}_linux_amd64.tar.gz" - - echo "Installing cue version $CUE_VERSION" - curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sudo sh -s -- -b /usr/local/bin v1.23.8 - - curl -L https://github.com/cuelang/cue/releases/download/${CUE_VERSION}/${CUE_TARBALL} | sudo tar zxf - -C /usr/local/bin - - name: Lint run: | make lint