diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..da31d1b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,21 @@ +# CMake ignores +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps + +# Project specific +cmake/* +!cmake/.gitkeep +node_modules +.idea + +# protoc output +gooseai/*/*pb* diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..cdd4a8c --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,24 @@ +name: Build Docker Image + +on: + push: {} + +jobs: + build-with-docker: + name: Build with Docker + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v3 + - uses: docker/setup-buildx-action@v2 + - uses: docker/build-push-action@v3 + with: + push: false + context: . + cache-from: type=gha + cache-to: type=gha,mode=max + outputs: | + type=local,dest=${{ runner.temp }}/docker-build + - uses: actions/upload-artifact@v3 + with: + name: gooseai + path: ${{ runner.temp }}/docker-build/gooseai \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c863923 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,35 @@ +ARG NODE_IMAGE_TAG=16-bullseye +FROM node:${NODE_IMAGE_TAG} as builder +ARG GOLANG_VERSION=1.18.6 +ARG GOLANG_PACKAGE=https://go.dev/dl/go${GOLANG_VERSION}.linux-amd64.tar.gz +ARG GRPC_VERSION=v1.48.2 +ARG PROTOC_GEN_GO_VERSION=v1.28.1 +ARG PROTOC_GEN_GO_GRPC_VERSION=v1.1.0 + +# Install python and build tools from apt +RUN apt-get update && apt-get install -y cmake git build-essential python3-venv wget && rm -rf /var/lib/apt/lists/* + +# Install golang from binary package +RUN rm -rf /go && wget ${GOLANG_PACKAGE} -qO- | tar -C / -xz +ENV GOPATH=/go +ENV PATH $GOPATH/bin:$PATH +RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH" +RUN mkdir -p /build + +# Build GRPC; note this issue before updating: https://github.com/protocolbuffers/protobuf-javascript/issues/127 +WORKDIR /build +RUN git clone --recurse-submodules -b ${GRPC_VERSION} --depth 1 --shallow-submodules https://github.com/grpc/grpc +WORKDIR /build/grpc +RUN mkdir -p cmake/build; cd cmake/build; cmake -DgRPC_INSTALL=ON -DgRPC_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=/usr/local ../.. && make -j 8 && make install + +# Build api-interfaces +RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@${PROTOC_GEN_GO_VERSION} +RUN go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@${PROTOC_GEN_GO_GRPC_VERSION} + +COPY . /build/api-interfaces/ +WORKDIR /build/api-interfaces +RUN cmake . && cmake --build . + +# Copy output to a bare container +FROM debian:bullseye-slim +COPY --from=builder /build/api-interfaces/gooseai /gooseai \ No newline at end of file