]> git.puffer.fish Git - matthieu/nova.git/commitdiff
add devcontainer support 3/head
authorMatthieu <matthieu@developershouse.xyz>
Sat, 25 Sep 2021 10:25:26 +0000 (10:25 +0000)
committerMatthieu <matthieu@developershouse.xyz>
Sat, 25 Sep 2021 10:25:26 +0000 (10:25 +0000)
.devcontainer/Dockerfile
.devcontainer/devcontainer.json
.github/workflows/bazel-build.yml
gateway/config/default.toml
gateway/src/shard/connection.rs

index ba27052420e23023e2504df86178c7a86bd8ccb9..2c6a8bd8fd7e2650db09aca17e885bb3c79fcd76 100644 (file)
@@ -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" ]
index 0ff8ae128eb940272a617264c21ac47955bea272..03c3e4cb8cd43b703faa08f53a660f8299c6cf83 100644 (file)
 
     // 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.
index 5f919c8154effca81f26b0abc56a2841f2e1b399..2baaea1dba843163a370c5a1642309fddb23f514 100644 (file)
@@ -68,9 +68,9 @@ jobs:
         with:\r
           name: all-${{ matrix.os }}\r
           path: |\r
-            bazel-bin*/packages_*\r
-            bazel-bin*/packages_zip.zip\r
-            bazel-bin*/packages_tar.tar.gz\r
+            bazel-bin*/package_*\r
+            bazel-bin*/package_zip.zip\r
+            bazel-bin*/package_tar.tar.gz\r
 \r
       - name: Publish docker images\r
         shell: bash\r
index 252ff32644c5b0aaabb0394e485ad5246b9f912a..4bfac9d3e20a4b78e5e26eb3ffaa9486f7afa8e8 100644 (file)
@@ -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
index 0d66286ac2333dcf19507cc081cd9dc6c65c2af4..a0fa98aac719b047483fe7d46a90f3849cf163ba 100644 (file)
@@ -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()));
                                 },
                             }
                         }