cleanup build scripts and simplify build/build-container (#301)
This commit is contained in:
parent
e7a6d07c5b
commit
c5f152477d
10
README.md
10
README.md
@ -1,2 +1,12 @@
|
|||||||
# corso
|
# corso
|
||||||
CLI/API based backup of M365 data
|
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
|
||||||
|
```
|
||||||
|
|||||||
@ -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}
|
|
||||||
@ -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
|
|
||||||
```
|
|
||||||
18
build/build-container.sh
Executable file
18
build/build-container.sh
Executable file
@ -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}"
|
||||||
@ -1,27 +1,31 @@
|
|||||||
#! /bin/bash
|
#!/bin/sh
|
||||||
|
|
||||||
# Builds a docker image that contains the deps for the current version of the
|
set -ex
|
||||||
# code. Image expects dev directory to be mounted in the container at runtime.
|
|
||||||
|
|
||||||
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() {
|
# temporary directory for caching go build
|
||||||
docker build \
|
mkdir -p /tmp/.corsobuild/cache
|
||||||
-f Dockerfile \
|
# temporary directory for caching go modules (needed for fast cross-platform build)
|
||||||
-t "$BASE_TAG" \
|
mkdir -p /tmp/.corsobuild/mod
|
||||||
--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
|
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
|
||||||
|
|||||||
@ -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"
|
|
||||||
@ -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
|
|
||||||
@ -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
|
|
||||||
```
|
|
||||||
@ -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
|
|
||||||
Loading…
x
Reference in New Issue
Block a user