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:
parent
3ee7ff0c0b
commit
0707d00ab5
4
.gitignore
vendored
4
.gitignore
vendored
@ -17,3 +17,7 @@
|
|||||||
# Standard configuration file names
|
# Standard configuration file names
|
||||||
.corso_test.toml
|
.corso_test.toml
|
||||||
.corso.toml
|
.corso.toml
|
||||||
|
|
||||||
|
# Build directories
|
||||||
|
/bin
|
||||||
|
/docker/bin
|
||||||
14
build/Dockerfile
Normal file
14
build/Dockerfile
Normal 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
18
build/README.md
Normal 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
27
build/build.sh
Executable 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
|
||||||
@ -1,14 +1,11 @@
|
|||||||
FROM golang:1.18
|
# syntax=docker/dockerfile:1
|
||||||
|
|
||||||
ARG uid=1000
|
FROM gcr.io/distroless/base-debian10
|
||||||
ARG gid=1000
|
|
||||||
|
|
||||||
# Dockerfile with static deps that won't be changed. Right now there's no deps
|
WORKDIR /
|
||||||
# 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 && \
|
COPY ./bin/corso ./
|
||||||
useradd -m -u "${uid}" -g "${gid}" build
|
|
||||||
|
|
||||||
USER build:${gid}
|
USER nonroot:nonroot
|
||||||
|
|
||||||
|
ENTRYPOINT ["/corso"]
|
||||||
13
docker/README.md
Normal file
13
docker/README.md
Normal 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
|
||||||
|
```
|
||||||
@ -1,27 +1,19 @@
|
|||||||
#! /bin/bash
|
#! /bin/bash
|
||||||
|
|
||||||
# Builds a docker image that contains the deps for the current version of the
|
# Builds a docker image that wraps the corso binary
|
||||||
# code. Image expects dev directory to be mounted in the container at runtime.
|
|
||||||
|
|
||||||
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() {
|
buildImage() {
|
||||||
docker build \
|
docker build . \
|
||||||
-f Dockerfile \
|
-t "$IMAGE_NAME:$VERSION"
|
||||||
-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
|
buildImage
|
||||||
Loading…
x
Reference in New Issue
Block a user