Add a Dockerfile for corso (#247)

Adds a Dockerfile under the docker to package the corso binary.

This currently requires the user to build the corso binary (for linux/amd64) in the build image
prior to building the docker image. Follow up PRs will introduce a Makefile.

Also moves the build image to the build folder and adds a couple of README.md files with
instructions.

Fixes #218
This commit is contained in:
Vaibhav Kamra 2022-06-28 12:15:30 -07:00 committed by GitHub
parent 3ee7ff0c0b
commit 0707d00ab5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 95 additions and 30 deletions

6
.gitignore vendored
View File

@ -16,4 +16,8 @@
# Standard configuration file names
.corso_test.toml
.corso.toml
.corso.toml
# Build directories
/bin
/docker/bin

14
build/Dockerfile Normal file
View File

@ -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 if [ ! $(getent group ${gid}) ]; then groupadd -g "${gid}" build; fi && \
useradd -m -u "${uid}" -g "${gid}" build
USER build:${gid}

18
build/README.md Normal file
View File

@ -0,0 +1,18 @@
# 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
```

27
build/build.sh Executable file
View File

@ -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

View File

@ -1,14 +1,11 @@
FROM golang:1.18
# syntax=docker/dockerfile:1
ARG uid=1000
ARG gid=1000
FROM gcr.io/distroless/base-debian10
# 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.
WORKDIR /
RUN if [ ! $(getent group ${gid}) ]; then groupadd -g "${gid}" build; fi && \
useradd -m -u "${uid}" -g "${gid}" build
COPY ./bin/corso ./
USER nonroot:nonroot
USER build:${gid}
ENTRYPOINT ["/corso"]

13
docker/README.md Normal file
View File

@ -0,0 +1,13 @@
# 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
```

View File

@ -1,27 +1,19 @@
#! /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.
# Builds a docker image that wraps the corso binary
source paths.sh
IMAGE_NAME="alcionai/corso"
VERSION=$(git describe --tags --always --dirty)
CORSO_BINARY="./bin/corso"
BASE_TAG="alcionai/base-dev"
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 \
-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
docker build . \
-t "$IMAGE_NAME:$VERSION"
}
buildImage
buildImage