# Discourse Plugin: Discourse Container Names with GON

**URL:** <https://community.unix.com/t/discourse-plugin-discourse-container-names-with-gon/380701>\
**Category:** Discourse Plugins\
**Created:** [November 11, 2020, 10:06am UTC](https://community.unix.com/t/discourse-plugin-discourse-container-names-with-gon/380701 "2020-11-11T10:06:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Neo](https://community.unix.com/user_avatar/community.unix.com/neo/32/22838_2.png) [@Neo](https://community.unix.com/u/Neo)\
**Post date:** [November 11, 2020, 10:06am UTC](https://community.unix.com/t/discourse-plugin-discourse-container-names-with-gon/380701/1 "2020-11-11T10:06:47Z")

</div>

### Discourse Plugin Summary

Shows the names of Docker containers to Discourse system admins using GON gem on the Backups page.

GITHUB: [GitHub - unixneo/discourse-container-names-with-gon: This Discourse plugin uses either (A) two environmental variables specified in the Discourse container yml file or (B) the Discourse system ENV["DATA\_NAME"] environmental variable to show the names of the containers in the admin area. In addition, this plugin displays partial disk space information using the df command inside the container.](https://github.com/unixneo/discourse-container-names-with-gon)

### Installation

- If you want to overwrite your container names in your container yaml files; defining these two constants, as follows:

```plaintext
env:
  DISCOURSE_CONTAINER_MAIN: 'socket-only'
  DISCOURSE_CONTAINER_DATA: 'data'

```

- Install the plugin in your Discourse container yaml file using the standard Discourse plugin install directions:

```plaintext
    - exec:
        cd: $home/plugins
        cmd:
          - git clone https://github.com/unixneo/discourse-container-names-with-gon.git

```

Add Javascript to theme in `</head>` section:

```plaintext
<script type='text/discourse-plugin' version='0.8.19'>
api.onPageChange(url => {
    if($('#container-names').length === 0){
	  var containers = '<div id="container-names" style="margin:10px;"> Containers: '+gon.global.container_main+', '+gon.global.container_data+'</div>';
      $(".admin-content").prepend( containers );
    }
});
</script>

```

If you have installed GON correctly, you will see the container names in your admin panel, for example:

 ![Screen Shot 2020-11-12 at 1.18.40 PM](https://community.unix.com/uploads/default/original/2X/0/09c94651ef198c6619fa6432774e732c29452f26.jpeg)

### See Also:

> **[GitHub - unixneo/discourse-container-names-with-gon: This Discourse plugin uses either (A) two...](https://github.com/unixneo/discourse-container-names-with-gon)**
>
> This Discourse plugin uses either (A) two environmental variables specified in the Discourse container yml file or (B) the Discourse system ENV\["DATA\_NAME"\] environmental variable to show the names of the containers in the admin area. In addition, this plugin displays partial disk space information using the df command inside the container.

> **[GitHub - gazay/gon: Your Rails variables in your JS](https://github.com/gazay/gon)**
>
> Your Rails variables in your JS

> **[Install plugins on a self-hosted site](https://meta.discourse.org/t/install-plugins-on-a-self-hosted-site/19157)**
>
> ⚠ This guide assumes that you have a self-hosted standard installation. We only support the standard method of install here, so these instructions assume you have a standard install. ⚠ This guide only applies to self-hosted Discourse instances....

---

<div class="post-metadata">

**Author:** ![Neo](https://community.unix.com/user_avatar/community.unix.com/neo/32/22838_2.png) [@Neo](https://community.unix.com/u/Neo)\
**Post date:** [November 12, 2020, 6:16am UTC](https://community.unix.com/t/discourse-plugin-discourse-container-names-with-gon/380701/2 "2020-11-12T06:16:30Z")

</div>

### UPDATE

Moved all logic to theme.

```plaintext
<script type='text/discourse-plugin' version='0.8.19'>
api.onPageChange(url => {
    if($('#container-names').length === 0){
	  var containers = '<div id="container-names" style="margin:10px;"> Containers: '+gon.global.container_main+', '+gon.global.container_data+'</div>';
      $(".admin-content").prepend( containers );
    }
});
</script>

```

Removed EmberJS code from plugin.

Update: Replaced jQuery with vanilla JS:

```javascript
<script type='text/discourse-plugin' version='0.8.19'>
api.onPageChange(url => {
    if (!document.getElementById('container-names') && document.getElementsByClassName("admin-content").length > 0)
    {
        var my_div = document.createElement('div');
        my_div.setAttribute("id", "container-names");
        my_div.style.margin = "10px";
        my_div.innerHTML = 'Containers: '+gon.global.container_main+', '+gon.global.container_data+'<br> Disk Space (df) on '+gon.global.diskspace;
        var element = document.getElementsByClassName("admin-content");
        element[0].prepend(my_div);
    }
});
</script>

```

---

<div class="post-metadata">

**Author:** ![Neo](https://community.unix.com/user_avatar/community.unix.com/neo/32/22838_2.png) [@Neo](https://community.unix.com/u/Neo)\
**Post date:** [November 22, 2020, 8:17am UTC](https://community.unix.com/t/discourse-plugin-discourse-container-names-with-gon/380701/3 "2020-11-22T08:17:05Z")

</div>

Update:

Modified this plugin to:

- Add some info about disk usage
- Pull container info from a Discourse system ENV variable when available.

Added the logic to the Admin controller, so the info will update when the admin page is refreshed.

 ![Screen Shot 2020-11-22 at 3.06.24 PM](https://community.unix.com/uploads/default/original/2X/2/2b473ab5b43b988bbe042e41cbb9475b86a9e42b.jpeg)

TODO:

- Move the logic so it is not duplicated in both the initializer and the AdminController class; or just remove the logic from the initializer.

NOTE:

These ENV variables are not required:

```
env:
  DISCOURSE_CONTAINER_MAIN: 'socket-only'
  DISCOURSE_CONTAINER_DATA: 'data'

```

The plugin will get the names from the Discourse application environmental variable, it it exists:

```
ENV["DATA_NAME"]

```

However, if you do set the the ENV variables in the container build file, these variables will take priority over `ENV["DATA_NAME"]`.

In other words, for most people, it is not necessary to set any additional ENV VARS in the container `yml files`. However, if you do decide to set them, your settings container with not be overridden.

---

<div class="post-metadata">

**Author:** ![Neo](https://community.unix.com/user_avatar/community.unix.com/neo/32/22838_2.png) [@Neo](https://community.unix.com/u/Neo)\
**Post date:** [November 23, 2020, 3:28am UTC](https://community.unix.com/t/discourse-plugin-discourse-container-names-with-gon/380701/4 "2020-11-23T03:28:08Z")

</div>

See also:

> **[Discourse Container Names with GON - For Sys Admins and Developers](https://meta.discourse.org/t/discourse-container-names-with-gon-for-sys-admins-and-developers/170973)**
>
> WHAT DOES THIS PLUGIN DO? This simple Discourse Container Names with GON plugin consumes the ENV\["DATA\_NAME"\] environmental, or user set environments, to display the container names on Discourse admin pages. In addition, it displays the disk...

---

<div class="post-metadata">

**Author:** ![Neo](https://community.unix.com/user_avatar/community.unix.com/neo/32/22838_2.png) [@Neo](https://community.unix.com/u/Neo)\
**Post date:** [April 10, 2021, 2:15pm UTC](https://community.unix.com/t/discourse-plugin-discourse-container-names-with-gon/380701/5 "2021-04-10T14:15:29Z")

</div>

Updated this plugin to use plain vanilla JS in the theme (component) and removed the jQuery (used in the prior version of the plugin):

```javascript
<script type='text/discourse-plugin' version='0.8.19'>
api.onPageChange(url => {
    if (!document.getElementById('container-names') && document.getElementsByClassName("admin-content").length > 0)
    {
        var my_div = document.createElement('div');
        my_div.setAttribute("id", "container-names");
        my_div.style.margin = "10px";
        my_div.innerHTML = 'Containers: '+gon.global.container_main+', '+gon.global.container_data+'<br> Disk Space (df) on '+gon.global.diskspace;
        var element = document.getElementsByClassName("admin-content");
        element[0].prepend(my_div);
    }
});
</script>

```
