Skip to content

Commit

Permalink
Add success alerts, improve logs, and restructure Docker
Browse files Browse the repository at this point in the history
Enhanced user feedback by adding success alerts across multiple modules. Improved logging levels for better debuggability. Restructured Docker-related files for better initialization and configuration, including new entrypoint scripts and environment variable management.
  • Loading branch information
SquirrelDevelopper committed Nov 5, 2024
1 parent b26e609 commit 11a876d
Show file tree
Hide file tree
Showing 18 changed files with 235 additions and 133 deletions.
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ DB_PORT=27017
#REDIS
REDIS_HOST=redis
REDIS_PORT=6379
#SSM CONFIG
#SSM_INSTALL_PATH=/opt/squirrelserversmanager
#SSM_DATA_PATH=/data
3 changes: 3 additions & 0 deletions .env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ DB_PORT=27017
#REDIS
REDIS_HOST=redis
REDIS_PORT=6379
#SSM CONFIG
#SSM_INSTALL_PATH=/opt/squirrelserversmanager
#SSM_DATA_PATH=/data
17 changes: 15 additions & 2 deletions client/src/components/Alert/AlertNotification.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { socket } from '@/socket';
import { notification, Typography } from 'antd';
import React, { useEffect } from 'react';
import { SsmEvents } from 'ssm-shared-lib';
import { SsmEvents, SsmAlert } from 'ssm-shared-lib';

const AlertNotification: React.FC = () => {
const [api, contextHolder] = notification.useNotification();
const openNotificationWithIcon = (payload: any) => {
if (payload?.severity === 'error') {
if (payload?.severity === SsmAlert.AlertType.ERROR) {
api.error({
message: 'Alert',
description: (
Expand All @@ -19,6 +19,19 @@ const AlertNotification: React.FC = () => {
duration: 0,
});
}
if (payload?.severity === SsmAlert.AlertType.SUCCESS) {
api.success({
message: 'Success',
description: (
<Typography.Text style={{ fontSize: 13 }}>
{payload?.message
?.split('\n')
.map((line: string, index: number) => <p key={index}>{line}</p>)}
</Typography.Text>
),
duration: 0,
});
}
};
useEffect(() => {
socket.connect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ const ContainerStacksGitRepositoryModal: React.FC<
await props.asyncFetch();
} else {
await putContainerStacksGitRepository(values);
message.loading({
content: 'Repository cloning & processing in process...',
duration: 6,
});
props.setModalOpened(false);
await props.asyncFetch();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ const PlaybooksGitRepositoryModal: React.FC<
await props.asyncFetch();
} else {
await putPlaybooksGitRepository(values);
message.loading({
content: 'Repository cloning & processing in process...',
duration: 6,
});
props.setModalOpened(false);
await props.asyncFetch();
}
Expand Down
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ services:
environment:
NODE_ENV: production
volumes:
- ./.data.prod:/data
- ./.data.prod/playbooks:/playbooks
- ./.data.prod/config:/ansible-config
client:
image: "ghcr.io/squirrelcorporation/squirrelserversmanager-client:latest"
restart: unless-stopped
Expand Down
5 changes: 5 additions & 0 deletions server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ LABEL org.opencontainers.image.source=https://github.com/SquirrelCorporation/Squ
LABEL org.opencontainers.image.description="SSM Server"
LABEL org.opencontainers.image.licenses="GNU AFFERO GENERAL PUBLIC LICENSE"

COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

WORKDIR /opt/squirrelserversmanager/server
RUN apk update && apk add ansible nmap sudo openssh sshpass py3-pip expect gcompat libcurl curl
RUN apk add docker docker-cli-compose
Expand All @@ -25,10 +28,12 @@ ENV NODE_ENV=production
RUN npm ci --verbose --no-audit
COPY . .
RUN npm run build
ENTRYPOINT ["/entrypoint.sh"]
CMD ["node", "./dist/src/index.js"]

FROM base AS dev
ENV NODE_ENV=development
COPY ./nodemon.json .
RUN npm install -g nodemon && npm ci --verbose --no-audit
ENTRYPOINT ["/entrypoint.sh"]
CMD ["npm", "run", "dev"]
8 changes: 8 additions & 0 deletions server/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

# Create symlinks
ln -sf /data/playbooks /playbooks
ln -sf /data /ansible-config

# Execute the CMD
exec "$@"
Original file line number Diff line number Diff line change
@@ -1,121 +1,128 @@
- name: Update apt package cache
ansible.builtin.apt:
update_cache: yes
when: ansible_os_family == "Debian"

- name: Install required packages for Docker (Debian-based)
ansible.builtin.apt:
name:
- apt-transport-https
- ca-certificates
- curl
- gnupg-agent
- software-properties-common
state: present
when: ansible_os_family == "Debian"

- name: Add Docker's official GPG key (Debian-based)
ansible.builtin.shell: |
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
when: ansible_os_family == "Debian"

- name: Set up the Docker repository (Debian-based)
ansible.builtin.shell: |
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \
$(. /etc/os-release && echo \"$VERSION_CODENAME\") stable" |\
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
when: ansible_os_family == "Debian"

- name: Update apt package cache after adding Docker repo
ansible.builtin.apt:
update_cache: yes
when: ansible_os_family == "Debian"

- name: Install required packages for Docker (RHEL-based)
ansible.builtin.yum:
name:
- yum-utils
- device-mapper-persistent-data
- lvm2
state: present
when: ansible_os_family == "RedHat"

- name: Add Docker's official repository (RHEL-based)
ansible.builtin.command: |
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
when: ansible_os_family == "RedHat"

- name: Ensure old versions of Docker are not installed (Debian-based)
ansible.builtin.apt:
name: "{{ item }}"
state: absent
loop:
- docker
- docker-engine
- docker.io
- containerd
- runc
when: ansible_os_family == "Debian"

- name: Ensure old versions of Docker are not installed (RHEL-based)
ansible.builtin.yum:
name: "{{ item }}"
state: absent
loop:
- docker
- docker-common
- docker-selinux
- docker-engine
when: ansible_os_family == "RedHat"

- name: Install Docker CE (Debian-based)
ansible.builtin.apt:
name:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-buildx-plugin
- docker-compose-plugin
state: present
update_cache: yes
when: ansible_os_family == "Debian"

- name: Install Docker CE (RHEL-based)
ansible.builtin.yum:
name:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-buildx-plugin
- docker-compose-plugin
state: present
when: ansible_os_family == "RedHat"

- name: Start and enable Docker service
ansible.builtin.service:
name: docker
state: started
enabled: yes

- name: Add user to Docker group
ansible.builtin.user:
name: "{{ ansible_user_id }}"
groups: docker
append: yes

- name: Check if user is part of docker group
command: groups {{ ansible_user_id }}
register: user_groups
changed_when: false

- name: Display message if user is not yet in the Docker group
debug:
msg: "User '{{ ansible_user_id }}' needs to log out and log back in to apply the group change"
when: "'docker' not in user_groups.stdout"

- name: Activate the changes to groups
command: newgrp docker
when: "'docker' not in user_groups.stdout"
---
- name: Install Docker
hosts: all
become: true
gather_facts: false

tasks:
- name: Update apt package cache
ansible.builtin.apt:
update_cache: yes
when: ansible_os_family == "Debian"

- name: Install required packages for Docker (Debian-based)
ansible.builtin.apt:
name:
- apt-transport-https
- ca-certificates
- curl
- gnupg-agent
- software-properties-common
state: present
when: ansible_os_family == "Debian"

- name: Add Docker's official GPG key (Debian-based)
ansible.builtin.shell: |
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
when: ansible_os_family == "Debian"

- name: Set up the Docker repository (Debian-based)
ansible.builtin.shell: |
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \
$(. /etc/os-release && echo \"$VERSION_CODENAME\") stable" |\
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
when: ansible_os_family == "Debian"

- name: Update apt package cache after adding Docker repo
ansible.builtin.apt:
update_cache: yes
when: ansible_os_family == "Debian"

- name: Install required packages for Docker (RHEL-based)
ansible.builtin.yum:
name:
- yum-utils
- device-mapper-persistent-data
- lvm2
state: present
when: ansible_os_family == "RedHat"

- name: Add Docker's official repository (RHEL-based)
ansible.builtin.command: |
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
when: ansible_os_family == "RedHat"

- name: Ensure old versions of Docker are not installed (Debian-based)
ansible.builtin.apt:
name: "{{ item }}"
state: absent
loop:
- docker
- docker-engine
- docker.io
- containerd
- runc
when: ansible_os_family == "Debian"

- name: Ensure old versions of Docker are not installed (RHEL-based)
ansible.builtin.yum:
name: "{{ item }}"
state: absent
loop:
- docker
- docker-common
- docker-selinux
- docker-engine
when: ansible_os_family == "RedHat"

- name: Install Docker CE (Debian-based)
ansible.builtin.apt:
name:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-buildx-plugin
- docker-compose-plugin
state: present
update_cache: yes
when: ansible_os_family == "Debian"

- name: Install Docker CE (RHEL-based)
ansible.builtin.yum:
name:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-buildx-plugin
- docker-compose-plugin
state: present
when: ansible_os_family == "RedHat"

- name: Start and enable Docker service
ansible.builtin.service:
name: docker
state: started
enabled: yes

- name: Add user to Docker group
ansible.builtin.user:
name: "{{ ansible_user_id }}"
groups: docker
append: yes

- name: Check if user is part of docker group
command: groups {{ ansible_user_id }}
register: user_groups
changed_when: false

- name: Display message if user is not yet in the Docker group
debug:
msg: "User '{{ ansible_user_id }}' needs to log out and log back in to apply the group change"
when: "'docker' not in user_groups.stdout"

- name: Activate the changes to groups
command: newgrp docker
when: "'docker' not in user_groups.stdout"
Loading

0 comments on commit 11a876d

Please sign in to comment.