From 0af5f2f141f43d143cecfaf5bb33906210a678e4 Mon Sep 17 00:00:00 2001 From: Ashlie Martinez Date: Tue, 3 May 2022 15:31:23 -0700 Subject: [PATCH 1/8] Very basic golang docker with new user. * Expects go get/go mod to be used to handle application dependencies * Expects users to use a volume mount to make code visible to the container * Add a user (with the option of having the same UID/GID as current user) to avoid weird file owners when building things in the container as golang usually runs as root --- docker/Dockerfile | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 docker/Dockerfile diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 000000000..b74c2b405 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,14 @@ +FROM golang:1.18 + +ARG uid=1000 +ARG gid=1000 + +# Dockerfile with static deps that won't be changed. Right now there's no deps +# outside of what the go.mod file has to manage. Makes a user in the container +# with the same UID and GID as the current user so that the mounted directory +# doesn't end up with files with strange permissions. + +RUN groupadd -g "${gid}" build && \ + useradd -m -u "${uid}" -g "${gid}" build + +USER build:build From 6d9d4dc8c7b0ad962ba01fa884336d1985cdbf10 Mon Sep 17 00:00:00 2001 From: Ashlie Martinez Date: Tue, 3 May 2022 15:38:43 -0700 Subject: [PATCH 2/8] Add some information of note for later scripts. Mostly using bash filepath mangling and known values to build up information used to find the proper locations of golang code in a container. --- docker/paths.sh | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 docker/paths.sh diff --git a/docker/paths.sh b/docker/paths.sh new file mode 100644 index 000000000..18029fae7 --- /dev/null +++ b/docker/paths.sh @@ -0,0 +1,9 @@ +#! /bin/bash + +# TODO(ashmrtnz): Needs adjusting based on where source code lands in the repo +# and where the scripts land in the repo. +REPO_ROOT=$(dirname $(pwd)) +REPO_CODE="${REPO_ROOT}/src" +GOLANG_BASE_REPO_PATH="/go/src/github.com/alcionai" +GOLANG_REPO_PATH="${GOLANG_BASE_REPO_PATH}/$(basename $REPO_ROOT)" +DEV_TAG="alcionai/dev" From 9522a33ebe3600d9ff6903208409a659b840f7b8 Mon Sep 17 00:00:00 2001 From: Ashlie Martinez Date: Tue, 3 May 2022 15:39:53 -0700 Subject: [PATCH 3/8] Script file to build a basic dev container image. * New container will have deps known at the time the container was made * If deps change a lot, rebuild/save current container image as deps are outside the directory mount * Deps are not explicitly listed in the container Dockerfile or script as go mod is expected to manage them for us * Automatically creates a container user with UID/GID of the current user to avoid file ownership issues --- docker/build.sh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 docker/build.sh diff --git a/docker/build.sh b/docker/build.sh new file mode 100755 index 000000000..8a3fdbb62 --- /dev/null +++ b/docker/build.sh @@ -0,0 +1,27 @@ +#! /bin/bash + +# Builds a docker image that contains the deps for the current version of the +# code. Image expects dev directory to be mounted in the container at runtime. + +source paths.sh + +BASE_TAG="alcionai/base-dev" + +buildImage() { + docker build \ + -f Dockerfile \ + -t "$BASE_TAG" \ + --build-arg uid=$(id -u) \ + --build-arg gid=$(id -g) \ + . + docker run \ + -v "$REPO_CODE":"$GOLANG_REPO_PATH" \ + --name build-tmp \ + -w "$GOLANG_REPO_PATH" \ + -it \ + "$BASE_TAG" go get + docker commit build-tmp "$DEV_TAG" + docker rm build-tmp +} + +buildImage From 548ffb02ec27d2bdc003c591aa7b7f8ebcf89c41 Mon Sep 17 00:00:00 2001 From: Ashlie Martinez Date: Tue, 3 May 2022 15:44:14 -0700 Subject: [PATCH 4/8] Simple shell script to run dev container. * Mounts the current repo's code in the proper golang path in the container * Container will be destroyed when container is exited * User will start in the repo's code directory in the container --- docker/run_dev.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100755 docker/run_dev.sh diff --git a/docker/run_dev.sh b/docker/run_dev.sh new file mode 100755 index 000000000..5e3a0b32e --- /dev/null +++ b/docker/run_dev.sh @@ -0,0 +1,16 @@ +#! /bin/bash + +# Runs the dev docker image with the current user and mounts the source code +# directory in the container at the proper go path. +# NOTE: The container is ephemeral and destroyed after it is exited (but changes +# in the repo's code directory will be available to the host). + +source paths.sh + +docker run \ + --rm \ + -it \ + -v "$REPO_CODE":"$GOLANG_REPO_PATH" \ + -w "$GOLANG_REPO_PATH" \ + "$DEV_TAG" \ + /bin/bash From 0734a990d25298899fd7d8387cfdfd212706a11d Mon Sep 17 00:00:00 2001 From: Ashlie Martinez Date: Tue, 3 May 2022 16:12:30 -0700 Subject: [PATCH 5/8] Move/update gomode file. Now reflects the fact that this will be cloned from github. Also place in source directory so that all packages in the project don't need to be `src/foo`. --- go.mod | 3 --- src/go.mod | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-) delete mode 100644 go.mod create mode 100644 src/go.mod diff --git a/go.mod b/go.mod deleted file mode 100644 index 0bb7a7299..000000000 --- a/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module alcionai/corso - -go 1.18 diff --git a/src/go.mod b/src/go.mod new file mode 100644 index 000000000..aaebc02c7 --- /dev/null +++ b/src/go.mod @@ -0,0 +1,3 @@ +module github.com/alcionai/corso + +go 1.18 From b78675e821828b5e800b4481bcd6411866f43085 Mon Sep 17 00:00:00 2001 From: Ashlie Martinez Date: Tue, 3 May 2022 16:51:58 -0700 Subject: [PATCH 6/8] Change where workflow points to. --- .github/workflows/unitTests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unitTests.yml b/.github/workflows/unitTests.yml index 5a73e7aae..97c2a3a0a 100644 --- a/.github/workflows/unitTests.yml +++ b/.github/workflows/unitTests.yml @@ -13,4 +13,4 @@ jobs: go-version: 1.18 - run: echo "Running {{ github.repository }} deployment unit tests." - - run: go test ./... \ No newline at end of file + - run: go test ./src/... From 17fde7300ae7e345aded01e4aaa08dd5749adae9 Mon Sep 17 00:00:00 2001 From: Ashlie Martinez Date: Tue, 3 May 2022 16:57:17 -0700 Subject: [PATCH 7/8] Really change workflow directory now? --- .github/workflows/unitTests.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/unitTests.yml b/.github/workflows/unitTests.yml index 97c2a3a0a..219aa74ec 100644 --- a/.github/workflows/unitTests.yml +++ b/.github/workflows/unitTests.yml @@ -12,5 +12,6 @@ jobs: with: go-version: 1.18 + - working-directory: src - run: echo "Running {{ github.repository }} deployment unit tests." - - run: go test ./src/... + - run: go test ./... From 8ff89367d56c447730f3d024def6086fb634bed4 Mon Sep 17 00:00:00 2001 From: Ashlie Martinez Date: Tue, 3 May 2022 17:00:27 -0700 Subject: [PATCH 8/8] Maybe this time... --- .github/workflows/unitTests.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/unitTests.yml b/.github/workflows/unitTests.yml index 219aa74ec..52fde2792 100644 --- a/.github/workflows/unitTests.yml +++ b/.github/workflows/unitTests.yml @@ -3,6 +3,9 @@ on: [push] jobs: Run-All: runs-on: ubuntu-latest + defaults: + run: + working-directory: src steps: - name: Repo Code Checkout uses: actions/checkout@v3 @@ -12,6 +15,5 @@ jobs: with: go-version: 1.18 - - working-directory: src - run: echo "Running {{ github.repository }} deployment unit tests." - run: go test ./...