diff --git a/.github/workflows/unitTests.yml b/.github/workflows/unitTests.yml index 5a73e7aae..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 @@ -13,4 +16,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 ./... 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 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 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" 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 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