Compare commits
1 Commits
cicd
...
3ba88407c9
| Author | SHA1 | Date | |
|---|---|---|---|
| 3ba88407c9 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,4 +1,5 @@
|
|||||||
# ---> Ansible
|
# ---> Ansible
|
||||||
*.retry
|
*.retry
|
||||||
/env-file/*.env
|
/env-file/*.env
|
||||||
|
/containers/*.container
|
||||||
/vars/*.yml
|
/vars/*.yml
|
||||||
|
|||||||
65
README.md
65
README.md
@@ -1,68 +1,3 @@
|
|||||||
# cosmos-plan-crm-ansible-deploy
|
# cosmos-plan-crm-ansible-deploy
|
||||||
|
|
||||||
Ansible Playbook for deployment
|
Ansible Playbook for deployment
|
||||||
|
|
||||||
## Installation
|
|
||||||
1. Make sure podman, Playbook Ansible and containers.podman is installed
|
|
||||||
```bash
|
|
||||||
dnf install podman
|
|
||||||
dnf install ansible
|
|
||||||
ansible-galaxy collection install containers.podman
|
|
||||||
```
|
|
||||||
2. Install AWS CLI as a user(Not as a root)
|
|
||||||
```bash
|
|
||||||
unzip awscliv2.zip
|
|
||||||
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
|
|
||||||
./aws/install -i ~/.local/aws-cli -b ~/.local/bin
|
|
||||||
```
|
|
||||||
|
|
||||||
## Setup Environment
|
|
||||||
Using quadlets to run container as service in systemd(rootless)
|
|
||||||
1. Allows the user's systemd services to continue running even after they have logged out of all sessions. Trigger command from root
|
|
||||||
```bash
|
|
||||||
loginctl enable-linger {username}
|
|
||||||
```
|
|
||||||
2. Check subid and subgid(root).
|
|
||||||
```bash
|
|
||||||
cat /etc/subuid
|
|
||||||
cat /etc/subgid
|
|
||||||
```
|
|
||||||
3. Add if not exists
|
|
||||||
```bash
|
|
||||||
nano /etc/subuid
|
|
||||||
```
|
|
||||||
4. Then
|
|
||||||
```makefile
|
|
||||||
user:100000:65536
|
|
||||||
```
|
|
||||||
5. Check if $HOME/.config/containers/systemd exits. Else, create folder
|
|
||||||
```bash
|
|
||||||
$HOME/.config/containers/systemd
|
|
||||||
```
|
|
||||||
## Setup Ansible Playbook
|
|
||||||
1. Navigate to cosmos-plan-crm-ansible-deploy folder
|
|
||||||
2. Create containers folder
|
|
||||||
3. Create crm-server.container & crm-client.container inside containers folder
|
|
||||||
4. Create env-file folder
|
|
||||||
5. Copy .env from crm-server/src/Web.Api/.env to env-file folder
|
|
||||||
4. Create vars folder
|
|
||||||
5. Create aws.yml in vars folder by command
|
|
||||||
```bash
|
|
||||||
ansible-vault create aws.yml --ask-vault-pass
|
|
||||||
```
|
|
||||||
6. Save as below
|
|
||||||
```makefile
|
|
||||||
aws_access_key:
|
|
||||||
aws_secret_key:
|
|
||||||
aws_region:
|
|
||||||
aws_account_id:
|
|
||||||
```
|
|
||||||
|
|
||||||
## Run Ansible Playbook
|
|
||||||
1. Navigate to cosmos-plan-crm-ansible-deploy folder
|
|
||||||
2. Run command in terminal
|
|
||||||
```bash
|
|
||||||
ansible-playbook playbook.yml --ask-vault-pass
|
|
||||||
```
|
|
||||||
3. Key in password and let process finish
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
[Unit]
|
|
||||||
Description=crm-client server
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
ContainerName=crm-client
|
|
||||||
Restart=always
|
|
||||||
|
|
||||||
[Container]
|
|
||||||
Image=746819106135.dkr.ecr.ap-southeast-1.amazonaws.com/prod/crm-client:latest
|
|
||||||
PublishPort=3000:80
|
|
||||||
AutoUpdate=registry
|
|
||||||
Environment=VITE_API_ENDPOINT=https://api.cosmos-tropical.com
|
|
||||||
Environment=VITE_API_TIMEOUT=3600
|
|
||||||
Environment=VITE_APPLICATION_DEFAULT_OPEN_SIDEBAR=false
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=default.target
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
[Unit]
|
|
||||||
Description=crm-server server
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
ContainerName=crm-server
|
|
||||||
Restart=always
|
|
||||||
|
|
||||||
[Container]
|
|
||||||
Pod=crm-server.pod
|
|
||||||
Image=746819106135.dkr.ecr.ap-southeast-1.amazonaws.com/prod/crm-server:latest
|
|
||||||
Volume=/home/cosmosplan/crm-data:/app/data
|
|
||||||
Volume=/home/cosmosplan/crm-logs:/app/logs
|
|
||||||
Volume=/home/cosmosplan/cosmos-plan-crm-ansible-deploy/env-file/appsettings.json:/app/appsettings.json
|
|
||||||
AutoUpdate=registry
|
|
||||||
EnvironmentFile=/home/cosmosplan/cosmos-plan-crm-ansible-deploy/env-file/.env
|
|
||||||
Environment=TZ=Asia/Kuala_Lumpur
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=default.target
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
[Unit]
|
|
||||||
Description=datalust-seq container
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
ContainerName=datalust-seq
|
|
||||||
Restart=always
|
|
||||||
|
|
||||||
[Container]
|
|
||||||
Pod=crm-server.pod
|
|
||||||
Image=docker.io/datalust/seq:2024.3
|
|
||||||
AutoUpdate=registry
|
|
||||||
Environment=ACCEPT_EULA=Y
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=default.target
|
|
||||||
@@ -1,124 +0,0 @@
|
|||||||
{
|
|
||||||
"ApplicationSetting": {
|
|
||||||
"SlowRunningThresholdMilliseconds": 3000,
|
|
||||||
"UploadTempPath": "data/upload/temp",
|
|
||||||
"UploadTemplatePath": "data/upload/templates",
|
|
||||||
"UploadMailMagazinePath": "data/upload/resources",
|
|
||||||
"ClientAppUrl": "https://example.com",
|
|
||||||
"UnsubscribePath": "unsubscribe"
|
|
||||||
},
|
|
||||||
"AuthSetting": {
|
|
||||||
"DefaultPassword": "AAAAAAAA",
|
|
||||||
"JwtPublicKey": "-----BEGIN PUBLIC KEY-----\nJwtPublicKey\n-----END PUBLIC KEY-----",
|
|
||||||
"JwtPrivateKey": "-----BEGIN PRIVATE KEY -----\nJwtPrivateKey\n-----END PRIVATE KEY-----",
|
|
||||||
"JwtIssuer": "https://identity.sothink.vn",
|
|
||||||
"JwtAudience": "cosmos-plan-crm,cosmos-plan-crm-api",
|
|
||||||
"JwtExpirationInMinutes": 3,
|
|
||||||
"JwtKeyId": "cosmos-plan-crm-api",
|
|
||||||
"RefreshTokenExpirationInMinutes": 60,
|
|
||||||
"RefreshTokenMaxUsage": 5,
|
|
||||||
"RefreshTokenCookieName": "RefreshTokenCookieName"
|
|
||||||
},
|
|
||||||
"AWS": {
|
|
||||||
"AccessKeyId": "",
|
|
||||||
"SecretAccessKey": "",
|
|
||||||
"Region": "",
|
|
||||||
"SESMailFrom": "noreply@example.com",
|
|
||||||
"SESMailServiceFrom": "noreply@example.com"
|
|
||||||
},
|
|
||||||
"DataProtection": {
|
|
||||||
"EncryptionKey": ""
|
|
||||||
},
|
|
||||||
"EventBus": {
|
|
||||||
"SesTopicName": "",
|
|
||||||
"TopicNamePrefix": ""
|
|
||||||
},
|
|
||||||
"CachingSetting": {
|
|
||||||
"Mode": "Memory",
|
|
||||||
"ModeDescription": "Support modes: [\"Memory\", \"Distributed\", \"Hybrid\"]",
|
|
||||||
"DefaultTtlInSeconds": 60,
|
|
||||||
"CachingDataTtlInSeconds": 300,
|
|
||||||
"DistributedConnectionString": "",
|
|
||||||
"DistributedDatabaseName": 0
|
|
||||||
},
|
|
||||||
"DatabaseSetting": {
|
|
||||||
"ConnectionString": "Host=${IP};Port=${PORT};Database=${DB_NAME};Username=${DB_USER};Password=${DATA_PASSWORD};Include Error Detail=true",
|
|
||||||
"BackgroundJobConnectionString": "Host=${IP};Port=${PORT};Database=${DB_NAME};Username=${DB_USER};Password=${DATA_PASSWORD};Include Error Detail=true",
|
|
||||||
"Schema": "${SCHEMA}",
|
|
||||||
"UseMigrations": false,
|
|
||||||
"UseSeedData": true
|
|
||||||
},
|
|
||||||
"OutboxMessageOptions": {
|
|
||||||
"IntervalInSeconds": 3,
|
|
||||||
"BatchSize": 10,
|
|
||||||
"RetryCount": 3
|
|
||||||
},
|
|
||||||
"Serilog": {
|
|
||||||
"Using": [
|
|
||||||
"Serilog.Sinks.Console",
|
|
||||||
"Serilog.Sinks.File",
|
|
||||||
"Serilog.Enrichers.ClientInfo"
|
|
||||||
],
|
|
||||||
"MinimumLevel": {
|
|
||||||
"Default": "Warning",
|
|
||||||
"Override": {
|
|
||||||
"MassTransit": "Information",
|
|
||||||
"Microsoft": "Information",
|
|
||||||
"Microsoft.EntityFrameworkCore": "Warning",
|
|
||||||
"Microsoft.EntityFrameworkCore.Database.Command": "Warning"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"WriteTo": [
|
|
||||||
{
|
|
||||||
"Name": "Console",
|
|
||||||
"Args": {
|
|
||||||
"formatter": "Serilog.Formatting.Compact.RenderedCompactJsonFormatter, Serilog.Formatting.Compact"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Name": "File",
|
|
||||||
"Args": {
|
|
||||||
"path": "logs/log-.json",
|
|
||||||
"rollingInterval": "Day",
|
|
||||||
"retainedFileCountLimit": 30,
|
|
||||||
"formatter": "Serilog.Formatting.Compact.RenderedCompactJsonFormatter, Serilog.Formatting.Compact"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Name": "Seq",
|
|
||||||
"Args": {
|
|
||||||
"ServerUrl": "http://localhost:5341"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"Properties": {
|
|
||||||
"Application": "Cosmos Plan CRM API",
|
|
||||||
"Environment": "Production"
|
|
||||||
},
|
|
||||||
"Enrich": [
|
|
||||||
"FromLogContext",
|
|
||||||
"WithMachineName",
|
|
||||||
"WithThreadId",
|
|
||||||
"WithClientIp",
|
|
||||||
"WithCorrelationId",
|
|
||||||
{
|
|
||||||
"Name": "WithRequestHeader",
|
|
||||||
"Args": {
|
|
||||||
"headerName": "User-Agent"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"Smtp": {
|
|
||||||
"Host": "",
|
|
||||||
"Port": 0,
|
|
||||||
"From": "",
|
|
||||||
"Username": "",
|
|
||||||
"Password": "",
|
|
||||||
"UseSsl": false
|
|
||||||
},
|
|
||||||
"Network": {
|
|
||||||
"KnownProxies": "103.205.208.186"
|
|
||||||
,"ForwardLimit": 2
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
[Pod]
|
|
||||||
PublishPort=5000:8080
|
|
||||||
PublishPort=5431:8081
|
|
||||||
PublishPort=8081:80
|
|
||||||
@@ -5,32 +5,25 @@
|
|||||||
- name: Pull image from ECR for crm-client
|
- name: Pull image from ECR for crm-client
|
||||||
shell: >
|
shell: >
|
||||||
podman pull {{ aws_account_id }}.dkr.ecr.{{ aws_region }}.amazonaws.com/prod/crm-client:latest
|
podman pull {{ aws_account_id }}.dkr.ecr.{{ aws_region }}.amazonaws.com/prod/crm-client:latest
|
||||||
register: pulled_image_crm_client_result
|
|
||||||
|
|
||||||
- name: Pull image from ECR for crm-server
|
- name: Pull image from ECR for crm-server
|
||||||
shell: >
|
containers.podman.podman_image:
|
||||||
podman pull {{ aws_account_id }}.dkr.ecr.{{ aws_region }}.amazonaws.com/prod/crm-server:latest
|
name: "{{ aws_account_id }}.dkr.ecr.{{ aws_region }}.amazonaws.com/prod/crm-server"
|
||||||
|
state: present
|
||||||
register: pulled_image_crm_server_result
|
register: pulled_image_crm_server_result
|
||||||
|
|
||||||
- name: Copy crm-server.container file if image was pulled
|
- name: Copy crm-server.container file if image was pulled
|
||||||
ansible.builtin.copy:
|
ansible.builtin.copy:
|
||||||
src: containers/crm-server.container
|
src: containers/crm-server.container
|
||||||
dest: "{{ ansible_env.HOME }}/.config/containers/systemd/crm-server.container"
|
dest: "{{ ansible_env.HOME }}/.config/containers/systemd/crm-server.container"
|
||||||
|
when: pulled_image_crm_server_result.changed
|
||||||
- name: Copy seq.container
|
register: copy_crm_server_container_file_result
|
||||||
ansible.builtin.copy:
|
|
||||||
src: containers/seq.container
|
|
||||||
dest: "{{ ansible_env.HOME }}/.config/containers/systemd/seq.container"
|
|
||||||
|
|
||||||
- name: Copy crm-server.pod
|
|
||||||
ansible.builtin.copy:
|
|
||||||
src: pods/crm-server.pod
|
|
||||||
dest: "{{ ansible_env.HOME }}/.config/containers/systemd/crm-server.pod"
|
|
||||||
|
|
||||||
- name: Restart crm-server systemd service if container file was copied
|
- name: Restart crm-server systemd service if container file was copied
|
||||||
ansible.builtin.systemd:
|
ansible.builtin.systemd:
|
||||||
name: crm-server-pod
|
name: crm-server
|
||||||
state: restarted
|
state: restarted
|
||||||
scope: user
|
scope: user
|
||||||
daemon_reload: yes
|
daemon_reload: yes
|
||||||
|
when: copy_crm_server_container_file_result.changed
|
||||||
|
|
||||||
Reference in New Issue
Block a user