summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthieu <matthieu@developershouse.xyz>2021-09-25 10:25:26 +0000
committerMatthieu <matthieu@developershouse.xyz>2021-09-25 10:25:26 +0000
commit376f00642c2adba158b148a7933383af53ecdba1 (patch)
treee08ed094a63b14cc79975c1f11492a477970f0d3
parent30ec86caa2e318ea8cf39699fee56f9b8daca591 (diff)
add devcontainer support
-rw-r--r--.devcontainer/Dockerfile37
-rw-r--r--.devcontainer/devcontainer.json10
-rw-r--r--.github/workflows/bazel-build.yml6
-rw-r--r--gateway/config/default.toml2
-rw-r--r--gateway/src/shard/connection.rs23
5 files changed, 51 insertions, 27 deletions
diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile
index ba27052..2c6a8bd 100644
--- a/.devcontainer/Dockerfile
+++ b/.devcontainer/Dockerfile
@@ -1,26 +1,45 @@
FROM mcr.microsoft.com/vscode/devcontainers/base:0-focal
+ARG NONROOT_USER=vscode
-# ** [Optional] Uncomment this section to install additional packages. **
-# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
-# && apt-get -y install --no-install-recommends <your-package-list-here>
-
-RUN apt update -y && apt install apt-transport-https curl gnupg python build-essential ca-certificates lsb-release -y && \
+# Install required programs for the container
+RUN apt update -y && apt install apt-transport-https curl sudo gnupg python build-essential ca-certificates lsb-release -y && \
+ # Add bazel repository gpg keys
curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor -o /etc/apt/trusted.gpg.d/bazel.gpg && \
+ # Add docker repository gpg keys
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg && \
+ # Add docker repository apt source
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list && \
+ # Add bazel repository apt source
echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" | tee /etc/apt/sources.list.d/bazel.list && \
+ # Install bazel tools
+ curl -L https://github.com/bazelbuild/buildtools/releases/download/4.2.0/buildifier -o /usr/bin/buildifier && \
+ curl -L https://github.com/bazelbuild/buildtools/releases/download/4.2.0/buildozer-linux-amd64 -o /usr/bin/buildozer && \
+ chmod +x /usr/bin/buildifier && chmod +x /usr/bin/buildozer && \
+ # Install docker & bazel
apt update -y && apt install bazel docker-ce-cli -y
-ARG NONROOT_USER=vscode
+# Add the user to the sudo group
+RUN adduser $NONROOT_USER sudo
+# Allow to use sudo without password
+RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
+# Startup script, configure docker for the container non-root user
RUN echo "#!/bin/sh\n\
+ . ~/.cargo/env\n\
SOCKET_GID=\$(stat -c '%g' /var/run/docker.sock) \n\
if [ \"${SOCKET_GID}\" != '0' ]; then\n\
- if [ \"\$(cat /etc/group | grep :\${SOCKET_GID}:)\" = '' ]; then groupadd --gid \${SOCKET_GID} docker-host; fi \n\
- if [ \"\$(id ${NONROOT_USER} | grep -E \"groups=.*(=|,)\${SOCKET_GID}\(\")\" = '' ]; then usermod -aG \${SOCKET_GID} ${NONROOT_USER}; fi\n\
+ if [ \"\$(cat /etc/group | grep :\${SOCKET_GID}:)\" = '' ]; then sudo groupadd --gid \${SOCKET_GID} docker-host; fi \n\
+ if [ \"\$(id ${NONROOT_USER} | grep -E \"groups=.*(=|,)\${SOCKET_GID}\(\")\" = '' ]; then sudo usermod -aG \${SOCKET_GID} ${NONROOT_USER}; fi\n\
fi\n\
exec \"\$@\"" > /usr/local/share/docker-init.sh \
&& chmod +x /usr/local/share/docker-init.sh
+USER $NONROOT_USER
+
+# Install go & rust toolchains
+RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain nightly -y && \
+ curl https://raw.githubusercontent.com/canha/golang-tools-install-script/master/goinstall.sh | bash
+
ENTRYPOINT [ "/usr/local/share/docker-init.sh" ]
-CMD [ "sleep", "infinity" ] \ No newline at end of file
+# Required for vscode to start the server inside the container
+CMD [ "sleep", "infinity" ]
diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json
index 0ff8ae1..03c3e4c 100644
--- a/.devcontainer/devcontainer.json
+++ b/.devcontainer/devcontainer.json
@@ -13,7 +13,15 @@
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
- ""
+ "matklad.rust-analyzer",
+ "bazelbuild.vscode-bazel",
+ "vadimcn.vscode-lldb",
+ "ms-azuretools.vscode-docker",
+ "golang.go",
+ "ms-kubernetes-tools.vscode-kubernetes-tools",
+ "zxh404.vscode-proto3",
+ "phgn.vscode-starlark",
+ "redhat.vscode-yaml"
],
// Use 'forwardPorts' to make a list of ports inside the container available locally.
diff --git a/.github/workflows/bazel-build.yml b/.github/workflows/bazel-build.yml
index 5f919c8..2baaea1 100644
--- a/.github/workflows/bazel-build.yml
+++ b/.github/workflows/bazel-build.yml
@@ -68,9 +68,9 @@ jobs:
with:
name: all-${{ matrix.os }}
path: |
- bazel-bin*/packages_*
- bazel-bin*/packages_zip.zip
- bazel-bin*/packages_tar.tar.gz
+ bazel-bin*/package_*
+ bazel-bin*/package_zip.zip
+ bazel-bin*/package_tar.tar.gz
- name: Publish docker images
shell: bash
diff --git a/gateway/config/default.toml b/gateway/config/default.toml
index 252ff32..4bfac9d 100644
--- a/gateway/config/default.toml
+++ b/gateway/config/default.toml
@@ -9,4 +9,4 @@ max_reconnects = 5
reconnect_delay_growth_factor = 1.25
reconnect_delay_minimum = 5000
reconnect_delay_maximum = 60000
-intents = 32767 \ No newline at end of file
+intents = 32767
diff --git a/gateway/src/shard/connection.rs b/gateway/src/shard/connection.rs
index 0d66286..a0fa98a 100644
--- a/gateway/src/shard/connection.rs
+++ b/gateway/src/shard/connection.rs
@@ -17,7 +17,9 @@ impl Shard {
while reconnects < self.config.max_reconnects {
info!("Starting connection for shard");
- self._shard_task().await;
+ if let Err(e) = self._shard_task().await {
+ error!("Gateway status: {:?}", e);
+ }
// when the shard got disconnected, the shard task ends
reconnects += 1;
@@ -40,7 +42,7 @@ impl Shard {
);
}
- async fn _shard_task(&mut self) {
+ async fn _shard_task(&mut self) -> Result<(), GatewayError> {
// create the new connection
let mut connection = Connection::new();
connection.start().await.unwrap();
@@ -58,21 +60,18 @@ impl Shard {
Some(data) => match data {
Ok(message) => self._handle(&message).await,
Err(error) => {
- error!("An error occured while being connected to Discord: {:?}", error);
- return;
+ return Err(GatewayError::from(format!("An error occured while being connected to Discord: {:?}", error).to_string()));
},
},
None => {
- info!("Connection terminated");
- return;
+ return Err(GatewayError::from("Connection terminated".to_string()));
},
}
},
_ = timer.tick() => match self._do_heartbeat().await {
Ok(_) => {},
- Err(e) => {
- info!("error occured: {:?}", e);
- return;
+ Err(error) => {
+ return Err(GatewayError::from(format!("An error occured while being connected to Discord: {:?}", error).to_string()));
},
}
)
@@ -83,13 +82,11 @@ impl Shard {
Some(data) => match data {
Ok(message) => self._handle(&message).await,
Err(error) => {
- error!("An error occured while being connected to Discord: {:?}", error);
- return;
+ return Err(GatewayError::from(format!("An error occured while being connected to Discord: {:?}", error).to_string()));
},
},
None => {
- info!("Connection terminated");
- return;
+ return Err(GatewayError::from("Connection terminated".to_string()));
},
}
}