Skip to content

Commit

Permalink
feat: add devcontainer support for judgels development
Browse files Browse the repository at this point in the history
This patch add initial configs for devcontainer, development inside
container using vscode.
https://code.visualstudio.com/docs/devcontainers/containers

To use it, simply open judgels as follow:

$ git clone https://github.com/ia-toki/judgels.git
$ cd judgels
$ code .

Different container runtimes might need additional step. For example,
with colima on macOS, the source code directory need to be mounted on
start such as follow:

$ colima start --cpu 6 --memory 16 --mount $JUDGELS_HOME:$JUDGELS_HOME:w

Where $JUDGELS_HOME is an environment variable to judgels source code
path in host filesystem.

Testing:
- Successfully compile the code with devcontainer on macOS
  • Loading branch information
rizaon committed Oct 21, 2023
1 parent 314fe62 commit 8f7ac4b
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM ubuntu:20.04

ARG USER_UID=1000
ARG USER_GID=$USER_UID

RUN apt-get update \
&& apt-get install -y sudo git \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends tzdata \
&& addgroup --gid "${USER_GID}" tokidev \
&& adduser --uid "${USER_UID}" --gid "${USER_GID}" --disabled-password --gecos '' tokidev \
&& echo 'tokidev ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers

EXPOSE 9101
EXPOSE 3000
17 changes: 17 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "Impala Dev",
"dockerFile": "Dockerfile",
"runArgs": [
"--privileged",
],
"remoteUser": "tokidev",
"containerUser": "tokidev",
"postCreateCommand": "echo 'yes' | bin/bootstrap_system.sh",
"customizations": {
"vscode": {
"extensions": [
"vscjava.vscode-java-pack"
]
}
}
}
61 changes: 61 additions & 0 deletions bin/bootstrap_system.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env bash

# This script is intended to install the minimum requirement to start
# developing judgels in ubuntu20.04

set -eu -o pipefail

: ${JUDGELS_HOME:=$(cd "$(dirname $0)"/..; pwd)}
export JUDGELS_HOME

if [[ -t 1 ]] # if on an interactive terminal
then
echo "This script will clobber some system settings. Are you sure you want to"
echo -n "continue? "
while true
do
read -p "[yes/no] " ANSWER
ANSWER=$(echo "$ANSWER" | tr /a-z/ /A-Z/)
if [[ $ANSWER = YES ]]
then
break
elif [[ $ANSWER = NO ]]
then
echo "OK, Bye!"
exit 1
fi
done
fi

set -x

# install tools via apt-get
UBUNTU_JAVA_VERSION="11"
sudo apt-get --yes install git ssh wget curl unzip vim-common \
openjdk-${UBUNTU_JAVA_VERSION}-jdk openjdk-${UBUNTU_JAVA_VERSION}-source \
openjdk-${UBUNTU_JAVA_VERSION}-dbg npm mysql-client

# setup mysql server as a separate docker container, such as:
# docker run --name mysql -e MYSQL_ROOT_PASSWORD=judgels-root \
# -e MYSQL_DATABASE=judgels -d mysql:8

# install yarn
sudo npm install --global yarn

java --version
npm --version
yarn --version

# assemble judgels-server-app
cd $JUDGELS_HOME/judgels-backends/judgels-server-app
cp var/conf/judgels-server.yml.example var/conf/judgels-server.yml
../gradlew assemble

# build judgels-client
cd $JUDGELS_HOME/judgels-client
cp public/var/conf/judgels-client.js.example public/var/conf/judgels-client.js
yarn install

# TODO: to start judgels-server-app and judgels-client,
# follow the remaining instruction at:
# https://github.com/ia-toki/judgels/wiki/Dev's-Guide:-Running-from-source
3 changes: 3 additions & 0 deletions bin/create-mysql-user.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CREATE USER 'judgels'@'%' IDENTIFIED WITH mysql_native_password BY 'judgels';
GRANT ALL PRIVILEGES ON * . * TO 'judgels'@'%';
FLUSH PRIVILEGES;
1 change: 1 addition & 0 deletions judgels-backends/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ generated_tests/

data/

.devcontainer/*
.idea/
.ideaDataSources/
*.iml
Expand Down

0 comments on commit 8f7ac4b

Please sign in to comment.