Set up and push Docker containers for demonstration purposes

These containers take the place of a desktop install
This commit is contained in:
Michael Hohn
2024-09-04 15:52:18 -07:00
committed by =Michael Hohn
parent 681fcdab8c
commit 1e2df515e3
12 changed files with 403 additions and 33 deletions

View File

@@ -0,0 +1,65 @@
FROM codercom/code-server:4.92.2-debian
# ======================
# Pre-install a custom JDK for this platform and redirect CodeQL to it
USER root
ENV DEBIAN_FRONTEND=noninteractive
# Install packages
RUN apt-get update && apt-get install --no-install-recommends --assume-yes \
ca-certificates \
curl \
default-jdk \
git \
libcurl4-openssl-dev \
libssl-dev \
python3 \
python3-dev \
unzip
# Build argument for CodeQL version, defaulting to the latest release
ARG CODEQL_VERSION=latest
# If the version is 'latest', get the latest release version from GitHub, unzip
# the bundle into /opt, and delete the archive
RUN if [ "$CODEQL_VERSION" = "latest" ]; then \
CODEQL_VERSION=$(curl -s https://api.github.com/repos/github/codeql-cli-binaries/releases/latest | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/'); \
fi && \
echo "Using CodeQL version $CODEQL_VERSION" && \
curl -L "https://github.com/github/codeql-cli-binaries/releases/download/$CODEQL_VERSION/codeql-linux64.zip" -o /tmp/codeql.zip && \
unzip /tmp/codeql.zip -d /opt && \
rm /tmp/codeql.zip && \
chmod -R +x /opt/codeql
# ======================
# Install code-server
USER coder
# Set environment variables
ENV PASSWORD mrva
# Install VS Code extensions as user root -- globally
RUN code-server --install-extension ms-python.python \
&& code-server --install-extension esbenp.prettier-vscode \
&& code-server --install-extension GitHub.vscode-codeql
# Expose the port that Code Server runs on
EXPOSE 9080
# Point CodeQL to the java binary for this platform
ENV CODEQL_JAVA_HOME=/usr
# Add
# codeQl.cli.executablePath
# to user settings.
# This is in addition to the environment variable CODEQL_JAVA_HOME which has no
# effect on the plugin
COPY ./settings.json /home/coder/.local/share/code-server/User/
# Start Code Server
ENTRYPOINT ["dumb-init", "code-server", "--bind-addr", "0.0.0.0:9080", "."]
# Run as the coder user
USER coder

View File

@@ -0,0 +1,26 @@
all: code-server-initialized
CSI_TARGET := code-server-initialized:0.1.24
csi: code-server-initialized
code-server-initialized:
docker build -t ${CSI_TARGET} .
touch $@
csi-serve: csi
docker run -d -p 9080:9080 ${CSI_TARGET}
clean:
-docker rmi -f ${CSI_TARGET}
-rm code-server-initialized
# Targets below are used after some manual setup of the container. See README.org
# for details
csi-push: csi
docker tag ${CSI_TARGET} ghcr.io/hohn/${CSI_TARGET}
docker push ghcr.io/hohn/${CSI_TARGET}
touch $@
csi-test:
docker pull ghcr.io/hohn/${CSI_TARGET}
docker run --rm -it --name test-code-server-codeql ghcr.io/hohn/${CSI_TARGET} sh

View File

@@ -0,0 +1,60 @@
* MRVA VS Code server container
On the host:
- Build the container via
#+BEGIN_SRC sh
make csi
#+END_SRC
- Run the container via
#+BEGIN_SRC sh
make csi-serve
#+END_SRC
- Connect to it at http://localhost:9080/?folder=/home/coder, password is =mrva=.
Inside the container:
- Setup inside the container
#+BEGIN_SRC shell
export PATH=/opt/codeql:$PATH
codeql pack init qldemo
cd qldemo
codeql pack add codeql/python-all@1.0.6
#+END_SRC
- Open a new file =qldemo/simple.ql= and add this this query to it. The plugin
will download the CodeQL binaries (but never use them -- the configuration
redirects)
#+BEGIN_SRC java
import python
select 42
#+END_SRC
- Create database.
#+BEGIN_SRC sh
cd ~/qldemo
cat > short.py <<EOF
print('hello world')
EOF
export PATH=/opt/codeql:$PATH
codeql database create --language=python -s . -v short-db
#+END_SRC
- Set the database as default and run the query.
- Capture the state of this container and create a new image from it
#+BEGIN_SRC sh
docker ps
docker commit 0c15aeeaa914 code-server-initialized:0.1.24
docker kill 0c15aeeaa914
docker run -d -p 9080:9080 code-server-initialized:0.1.24
#+END_SRC
- Push this container
[[file:~/work-gh/mrva/mrvacommander/client/containers/vscode/Makefile::image-push: image]]
#+BEGIN_SRC sh
docker images |head
make csi-push
#+END_SRC

View File

@@ -0,0 +1,4 @@
{
"codeQL.runningQueries.numberOfThreads": 2,
"codeQl.cli.executablePath": "/opt/codeql"
}