diff --git a/README.md b/README.md index 7ce8c2cd3..97c725642 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,12 @@ # corso CLI/API based backup of M365 data + +# Getting Started + +```sh +# Build +./build/build.sh # this will create a binary in bin/ + +# Docker Image +./build/build-container.sh # this will build an image +``` diff --git a/build/Dockerfile b/build/Dockerfile deleted file mode 100644 index 562c6521a..000000000 --- a/build/Dockerfile +++ /dev/null @@ -1,14 +0,0 @@ -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 if [ ! $(getent group ${gid}) ]; then groupadd -g "${gid}" build; fi && \ - useradd -m -u "${uid}" -g "${gid}" build - -USER build:${gid} diff --git a/build/README.md b/build/README.md deleted file mode 100644 index 505d8bd1e..000000000 --- a/build/README.md +++ /dev/null @@ -1,18 +0,0 @@ -# Corso build image - -The Corso build image is a docker image that -can be used to dev/test/build Corso - -## Creating the build image - -Run `build.sh` to create `docker.io/alcionai/base-dev` -``` -$ ./build.sh -``` - -## Launching the build image - -Run `run_dev.sh` to launch into the build image. It will mount the corso src directory at `/` -``` -$ ./run_dev.sh -``` \ No newline at end of file diff --git a/build/build-container.sh b/build/build-container.sh new file mode 100755 index 000000000..1b073119b --- /dev/null +++ b/build/build-container.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +set -ex + +SCRIPT_ROOT=$(dirname $(readlink -f $0)) +PROJECT_ROOT=$(dirname ${SCRIPT_ROOT}) + +IMAGE_TAG=$(git describe --tags --always --dirty) +IMAGE_NAME=alcionai/corso:${IMAGE_TAG} + +${SCRIPT_ROOT}/build.sh + +echo "building container" +docker build -t ${IMAGE_NAME} \ + -f ${PROJECT_ROOT}/Dockerfile \ + ${PROJECT_ROOT} + +echo "container built successfully ${IMAGE_NAME}" diff --git a/build/build.sh b/build/build.sh index 8a3fdbb62..0b4b96239 100755 --- a/build/build.sh +++ b/build/build.sh @@ -1,27 +1,31 @@ -#! /bin/bash +#!/bin/sh -# 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. +set -ex -source paths.sh +SCRIPT_ROOT=$(dirname $(readlink -f $0)) +PROJECT_ROOT=$(dirname ${SCRIPT_ROOT}) +SRC_DIR=${PROJECT_ROOT} +CORSO_BUILD_ARGS='' -BASE_TAG="alcionai/base-dev" +CORSO_BUILD_CONTAINER_DIR=/go/src/github.com/alcionai/corso +CORSO_BUILD_CONTAINER_SRC_DIR=${CORSO_BUILD_CONTAINER_DIR}/src -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 -} +# temporary directory for caching go build +mkdir -p /tmp/.corsobuild/cache +# temporary directory for caching go modules (needed for fast cross-platform build) +mkdir -p /tmp/.corsobuild/mod -buildImage +echo "building corso" +docker run --rm --mount type=bind,src=${SRC_DIR},dst=${CORSO_BUILD_CONTAINER_DIR} \ + --mount type=bind,src=/tmp/.corsobuild/cache,dst=/tmp/.corsobuild/cache \ + --mount type=bind,src=/tmp/.corsobuild/mod,dst=/go/pkg/mod \ + --workdir ${CORSO_BUILD_CONTAINER_SRC_DIR} \ + --env GOCACHE=/tmp/.corsobuild/cache \ + --entrypoint /usr/local/go/bin/go \ + golang:1.18 \ + build ${CORSO_BUILD_ARGS} + +mkdir -p ${PROJECT_ROOT}/bin + +echo "creating binary image in bin/corso" +mv ${PROJECT_ROOT}/src/corso ${PROJECT_ROOT}/bin/corso diff --git a/build/paths.sh b/build/paths.sh deleted file mode 100644 index 18029fae7..000000000 --- a/build/paths.sh +++ /dev/null @@ -1,9 +0,0 @@ -#! /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/build/run_dev.sh b/build/run_dev.sh deleted file mode 100755 index 5e3a0b32e..000000000 --- a/build/run_dev.sh +++ /dev/null @@ -1,16 +0,0 @@ -#! /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/docker/README.md b/docker/README.md deleted file mode 100644 index 499f75924..000000000 --- a/docker/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# Corso Dockerfile - -## Instructions - -The docker image build currently expects the `corso` binary to be available in the same directory. - -- Build the `corso` binary in the build image. See instructions in the `build` directory. - -- Copy the `corso` binary to `$REPO/docker/bin` and run `build.sh` - -``` -$ ./build.sh -``` \ No newline at end of file diff --git a/docker/build.sh b/docker/build.sh deleted file mode 100755 index 2735ea044..000000000 --- a/docker/build.sh +++ /dev/null @@ -1,19 +0,0 @@ -#! /bin/bash - -# Builds a docker image that wraps the corso binary - -IMAGE_NAME="alcionai/corso" -VERSION=$(git describe --tags --always --dirty) -CORSO_BINARY="./bin/corso" - -if [ ! -f "$CORSO_BINARY" ]; then - echo "$CORSO_BINARY does not exist. Build corso and ensure the binary is available at $CORSO_BINARY" - exit 1 -fi - -buildImage() { - docker build . \ - -t "$IMAGE_NAME:$VERSION" -} - -buildImage \ No newline at end of file