From 0d6621d389fa47125a4cb777aa4343ff1a67542d Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Fri, 18 Aug 2023 22:26:42 -0400 Subject: [PATCH] Add docker. --- .dockerignore | 6 ++++++ README.md | 26 +++++++++++++++++++++++++- docker/Dockerfile | 39 +++++++++++++++++++++++++++++++++++++++ docker/Makefile | 27 +++++++++++++++++++++++++++ 4 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 docker/Dockerfile create mode 100644 docker/Makefile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..bca6e0e --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +**/.git +target/ +docker/ +LICENSE +readme/ +README.md diff --git a/README.md b/README.md index d6b2d81..8e9ff2b 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,28 @@ This repository contains a slapdash tool to make visualizing the abstract syntax ![Screenshot showing the interface to the org-mode abstract syntax tree investigation tool.](readme/screenshot.png?raw=true "Org-mode investigation tool interface") ## Running -TODO +Running in docker is the recommended way to run this. It creates a consistent working environment, without impacting (or requiring you to install) emacs, org-mode, or rust. +### Docker +First we need to build the docker container. On the first run, this will pull the emacs and org-mode source code so this build will take a while the first time. After that, subsequent builds should be fast because docker caches the layers. + +```bash +# from the root of this repository: +make --directory=docker +``` + +Next we need to launch the server: +```bash +docker run --rm --publish 127.0.0.1:3000:3000/tcp org-investigation +``` + +This launches a server listening on port 3000, so pop open your browser to http://127.0.0.1:3000/ to access the web interface. +### No docker +You will need a fully functional rust setup with nightly installed (due to the use of exit_status_error). Then from the root of this repo you can launch the server by running: + +```bash +cargo run --release +``` + +It will use your installed version of emacs and org-mode which may differ from what the docker users are using. + +This launches a server listening on port 3000, so pop open your browser to http://127.0.0.1:3000/ to access the web interface. diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..88af123 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,39 @@ +FROM alpine:3.17 AS build +RUN apk add --no-cache build-base musl-dev git autoconf make texinfo gnutls-dev ncurses-dev gawk + + +FROM build AS build-emacs +RUN git clone --depth 1 --branch emacs-29.1 https://git.savannah.gnu.org/git/emacs.git /root/emacs +WORKDIR /root/emacs +RUN mkdir /root/dist +RUN ./autogen.sh +RUN ./configure --prefix /usr --without-x --without-sound +RUN make +RUN make DESTDIR="/root/dist" install + + +FROM build AS build-org-mode +COPY --from=build-emacs /root/dist/ / +RUN mkdir /root/dist +RUN mkdir /root/org-mode && git -C /root/org-mode init --initial-branch=main && git -C /root/org-mode remote add origin https://git.savannah.gnu.org/git/emacs/org-mode.git && git -C /root/org-mode fetch origin cc435cba71a99ee7b12676be3b6e1211a9cb7285 && git -C /root/org-mode checkout FETCH_HEAD +WORKDIR /root/org-mode +RUN make compile +RUN make DESTDIR="/root/dist" install + + +FROM rustlang/rust:nightly-alpine3.17 AS build-org-investigation +RUN apk add --no-cache musl-dev +RUN mkdir /root/org-investigation +WORKDIR /root/org-investigation +COPY . . +RUN CARGO_TARGET_DIR=/target cargo build --release + + +FROM alpine:3.17 AS run +RUN apk add --no-cache ncurses gnutls +COPY --from=build-emacs /root/dist/ / +COPY --from=build-org-mode /root/dist/ / +COPY --from=build-org-investigation /target/release/org_ownership_investigation /usr/bin/ +COPY static /opt/org-investigation/static +WORKDIR /opt/org-investigation +CMD ["/usr/bin/org_ownership_investigation"] diff --git a/docker/Makefile b/docker/Makefile new file mode 100644 index 0000000..26f8349 --- /dev/null +++ b/docker/Makefile @@ -0,0 +1,27 @@ +IMAGE_NAME:=org-investigation +# REMOTE_REPO:=harbor.fizz.buzz/private + +.PHONY: all +all: build push + +.PHONY: build +build: + docker build -t $(IMAGE_NAME) -f Dockerfile ../ + +.PHONY: push +push: +ifdef REMOTE_REPO + docker tag $(IMAGE_NAME) $(REMOTE_REPO)/$(IMAGE_NAME) + docker push $(REMOTE_REPO)/$(IMAGE_NAME) +else + @echo "REMOTE_REPO not defined, not pushing to a remote repo." +endif + +.PHONY: clean +clean: + docker rmi $(IMAGE_NAME) +ifdef REMOTE_REPO + docker rmi $(REMOTE_REPO)/$(IMAGE_NAME) +else + @echo "REMOTE_REPO not defined, not removing from remote repo." +endif