Update README.md and some other changes

This commit is contained in:
Karl Cordes 2019-12-18 15:06:53 +11:00
parent b7e915eb95
commit a547a7119e
14 changed files with 265 additions and 17 deletions

View file

@ -40,20 +40,20 @@ ENV COMMIT_SHA=${COMMIT}
EXPOSE 80 EXPOSE 80
# Copy site into place.
ADD . /var/www/cmc-sales
RUN mkdir /var/www/cmc-sales/app/tmp
RUN mkdir /var/www/cmc-sales/app/tmp/logs
RUN chmod -R 755 /var/www/cmc-sales/app/tmp
# Update the default apache site with the config we created. # Update the default apache site with the config we created.
ADD conf/apache-vhost.conf /etc/apache2/sites-available/cmc-sales ADD conf/apache-vhost.conf /etc/apache2/sites-available/cmc-sales
ADD conf/ripmime /bin/ripmime ADD conf/ripmime /bin/ripmime
RUN chmod +x /bin/ripmime RUN chmod +x /bin/ripmime
RUN chmod +x /var/www/cmc-sales/run_vault.sh
RUN a2dissite 000-default RUN a2dissite 000-default
# Copy site into place.
ADD . /var/www/cmc-sales
RUN mkdir /var/www/cmc-sales/app/tmp
RUN mkdir /var/www/cmc-sales/app/tmp/logs
RUN chmod -R 755 /var/www/cmc-sales/app/tmp
RUN chmod +x /var/www/cmc-sales/run_vault.sh
RUN a2ensite cmc-sales RUN a2ensite cmc-sales
# By default, simply start apache. # By default, simply start apache.

View file

@ -1,6 +1,93 @@
# cmc-sales # cmc-sales
Project installation:
sql_mode="" ## Install
/etc/mysql/mysql.conf.d/mysqld.cnf
### Requirements
Debian or Ubuntu OS. These instructions written for Debian 9.9
Assumed pre-work:
Create a new VM with hostname newserver.cmctechnologies.com.au
Configure DNS appropriately. cmctechnologies.com.au zones is currently managed in Google Cloud DNS on Karl's account:
https://console.cloud.google.com/net-services/dns/zones/cmctechnologies?project=cmc-technologies&authuser=1&folder&organizationId
Will need to migrate that to CMC's GSuite account at some point.
1. Install ansible on your workstation
```
apt-get install ansible
```
2. Clone the playbooks
```
git clone git@gitlab.com:minimalist.software/cmc-playbooks.git
```
3. Execute the playbooks
The nginx config expects the site to be available at sales.cmctechnologies.com.au.
You'll need to add the hostname to config/nginx-site, if this isn't sales.cmctechnologies.com.au
```
cd cmc-playbooks
# Add the hostname of your new server to the inventory.txt
ansible-playbook -i inventory.txt setup.yml
```
4. SSH to the new server and configure gitlab-runner
```
ssh newserver.cmctechnologies.com.au
sudo gitlab-runner register
```
5. SSH to the new server as cmc user
```
ssh cmc@newserver.cmctechnologies.com.au
```
6. Add the SSH key to the cmc-sales repo on gitlab as a deploy key
https://gitlab.com/minimalist.software/cmc-sales/-/settings/repository
```
cmc@cmc:~$ cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDFIdoWVp2pGDb46ubW6jkfIpREMa/veD6xZVAtnj3WG1sX7NEUlQYq3RKbZ5CThlw6GKMSYoIsIqk7p6zSoJHGlJSLxoJ0edKflciMUFMTQrdm4T1USXsK+gd0C4DUCyVkYFOs37sy+JtziymnBTm7iOeVI3aMxwfoCOs6mNiD0ettjJT6WtVyy0ZTb6yU4uz7CHj1IGsvwsoKJWPGwJrZ/MfByNl6aJ8R/8zDwbtP06owKD4b3ZPgakM3nYRRoKzHZ/SClz50SXMKC4/nmFY9wLuuMhCWK+9x4/4VPSnxXESOlENMfUoa1IY4osAnZCtaFrWDyenJ+spZrNfgcscD ansible-generated on cmc
```
6. Clone the cmc-sales repo
```
git clone git@gitlab.com:minimalist.software/cmc-sales.git
```
7. As root on new server configure mySQL user cmc
Note: get password from app/config/database.php
(or set a new one and change it)
```
# mysql -u root
CREATE USER 'cmc'@'localhost' IDENTIFIED BY 'password';
CREATE USER 'cmc'@'172.17.0.2' IDENTIFIED BY 'password';
CREATE database cmc;
GRANT ALL PRIVILEGES ON cmc.* TO 'cmc'@'localhost';
GRANT ALL PRIVILEGES ON cmc.* TO 'cmc'@'172.17.0.2';
```
8. Get the latest backup from Google Drive
In the shared google drive:
eg. backups/database/backup_20191217_21001.sql.gz
Copy up to the new server:
```
rsync backup_*.gz root@newserver:~/
```
9. Restore backup to cmc database
```
zcat backup_* | mysql -u cmc -p
```
10. Redeploy from Gitlab
https://gitlab.com/minimalist.software/cmc-sales/pipelines/new
11. You should have a new installation of cmc-sales.

View file

@ -4,6 +4,25 @@
if($_SERVER["SERVER_NAME"] == "localhost") {
class DATABASE_CONFIG {
var $default = array(
'driver' => 'mysql',
'persistent' => false,
'host' => '172.17.0.1',
'login' => 'cmc',
'password' => 'cmc',
'database' => 'cmc',
'prefix' => '',
);
}
} else {
class DATABASE_CONFIG { class DATABASE_CONFIG {
var $default = array( var $default = array(
@ -28,3 +47,6 @@
'prefix' => '', 'prefix' => '',
); );
} }
}

View file

@ -309,6 +309,7 @@ ENDINSTRUCTIONS;
$currentuser = $this->GetCurrentUser(); $currentuser = $this->GetCurrentUser();
$this->data['Document']['user_id'] = $currentuser['User']['id']; $this->data['Document']['user_id'] = $currentuser['User']['id'];
$this->data['Document']['revision'] = 0; //No revisions for POs. I have decreed it! $this->data['Document']['revision'] = 0; //No revisions for POs. I have decreed it!
$this->data['Document']['doc_page_count'] = 0;
$this->data['Document']['type'] = 'purchaseOrder'; $this->data['Document']['type'] = 'purchaseOrder';
break; break;
@ -499,6 +500,7 @@ ENDINSTRUCTIONS;
} }
if (!empty($this->data)) { if (!empty($this->data)) {
$docID = $this->data['Document']['id']; $docID = $this->data['Document']['id'];
//this is retarded. I think we delete and re-create each page each time..
$this->Document->DocPage->deleteAll(array('document_id'=>$docID)); $this->Document->DocPage->deleteAll(array('document_id'=>$docID));
$this->Document->DocPage->updateCounterCache(array('document_id'=>$docID)); $this->Document->DocPage->updateCounterCache(array('document_id'=>$docID));
@ -519,7 +521,6 @@ ENDINSTRUCTIONS;
$query = "INSERT INTO `cmc`.`jobs_purchase_orders` (`id`, `job_id`, `purchase_order_id`) VALUES (NULL, '{$job_id}', '{$po_id}');"; $query = "INSERT INTO `cmc`.`jobs_purchase_orders` (`id`, `job_id`, `purchase_order_id`) VALUES (NULL, '{$job_id}', '{$po_id}');";
$this->Document->query($query); $this->Document->query($query);
} }
$result = $this->Document->PurchaseOrder->saveAll($this->data['PurchaseOrder']); $result = $this->Document->PurchaseOrder->saveAll($this->data['PurchaseOrder']);
@ -529,7 +530,7 @@ ENDINSTRUCTIONS;
} }
if ($this->Document->saveAll($this->data)) { if ($this->Document->saveAll($this->data)) {
echo 'SUCCESS'; echo 'SUCCESS'; //this is so stupid
} else { } else {
echo 'FAILURE'; echo 'FAILURE';
} }

View file

@ -8,7 +8,11 @@ class EmailAttachmentsController extends AppController {
function download($id) { function download($id) {
// maybe make this GET a go webservice that's something like
// GET vault.cmctechnologies.com.au/filename
// HTTP basic auth, or some sort of preshared key
// service hits S3 if required. Cached on disk for $sometime
$file = $this->EmailAttachment->findById($id); $file = $this->EmailAttachment->findById($id);
$file_path = Configure::read('email_directory'); $file_path = Configure::read('email_directory');

View file

@ -588,8 +588,6 @@ function getMonthsFY($year) {
),'fields' => array('Job.title'), ),'fields' => array('Job.title'),
'order' => array('Job.title ASC') 'order' => array('Job.title ASC')
)); ));
//print_r($POs); //print_r($POs);

View file

@ -0,0 +1,29 @@
ALTER TABLE documents MODIFY COLUMN user_id int(11) null;
ALTER TABLE documents MODIFY COLUMN doc_page_count int(11) null;
ALTER TABLE documents MODIFY COLUMN pdf_filename varchar(255) null;
ALTER TABLE order_acknowledgements MODIFY COLUMN issue_date date null;
ALTER TABLE order_acknowledgements MODIFY COLUMN job_id int(11) null;
ALTER TABLE order_acknowledgements MODIFY COLUMN estimated_delivery varchar(255) null;
ALTER TABLE order_acknowledgements MODIFY COLUMN document_id int(11) null;
ALTER TABLE order_acknowledgements MODIFY COLUMN enquiry_id int(11) null;
ALTER TABLE order_acknowledgements MODIFY COLUMN currency_id int(11) null;
ALTER TABLE purchase_orders MODIFY COLUMN title varchar(255) null;
ALTER TABLE purchase_orders MODIFY COLUMN document_id int(11) null;
ALTER TABLE jobs MODIFY COLUMN deleted tinyint(1) null;
ALTER TABLE jobs MODIFY COLUMN title varchar(255) null;
ALTER TABLE jobs MODIFY COLUMN state_id int(11) null;
ALTER TABLE jobs MODIFY COLUMN customer_id int(11) null;
ALTER TABLE jobs MODIFY COLUMN enquiry_id int(11) null;
ALTER TABLE jobs MODIFY COLUMN contact_id int(11) null;
ALTER TABLE jobs MODIFY COLUMN date_order_received date null;
ALTER TABLE jobs MODIFY COLUMN customer_order_number varchar(255) null;
ALTER TABLE jobs MODIFY COLUMN all_sent tinyint(1) null;
ALTER TABLE jobs MODIFY COLUMN all_paid tinyint(1) null;
ALTER TABLE jobs MODIFY COLUMN domestic_freight_paid_by enum('CMC','Customer') null;
ALTER TABLE jobs MODIFY COLUMN job_type enum('INDENT','STOCK','COMMISSION','SERVICE') null;
ALTER TABLE jobs MODIFY COLUMN shipment_category int(2) null;
ALTER TABLE jobs MODIFY COLUMN gst tinyint(1) null;
ALTER TABLE jobs MODIFY COLUMN currency_id int(11) null;

View file

@ -0,0 +1,55 @@
ALTER TABLE documents ALTER COLUMN doc_page_count SET DEFAULT 0;
ALTER TABLE documents MODIFY COLUMN cmc_reference varchar(255) null;
ALTER TABLE documents MODIFY COLUMN pdf_flename varchar(255) null;
ALTER TABLE documents MODIFY COLUMN pdf_created_at datetime null;
ALTER TABLE documents MODIFY COLUMN pdf_created_by_user_id int(11) null;
ALTER TABLE documents MODIFY COLUMN email_sent_at datetime null;
ALTER TABLE documents MODIFY COLUMN email_sent_by_user_id int(11) null;
ALTER TABLE documents MODIFY COLUMN revision int(11) null;
ALTER TABLE purchase_orders MODIFY COLUMN issue_date date null;
ALTER TABLE purchase_orders MODIFY COLUMN date_arrived date null;
ALTER TABLE purchase_orders MODIFY COLUMN dispatch_date date null;
ALTER TABLE purchase_orders MODIFY COLUMN principle_id int(11) null;
ALTER TABLE purchase_orders MODIFY COLUMN principle_reference varchar(255) null;
ALTER TABLE purchase_orders MODIFY COLUMN ordered_from text null;
ALTER TABLE purchase_orders MODIFY COLUMN description text null;
ALTER TABLE purchase_orders MODIFY COLUMN dispatch_by varchar(255) null;
ALTER TABLE purchase_orders MODIFY COLUMN deliver_to text null;
ALTER TABLE purchase_orders MODIFY COLUMN shipping_instructions text null;
ALTER TABLE purchase_orders MODIFY COLUMN jobs_text varchar(512) null;
ALTER TABLE jobs MODIFY COLUMN comments TEXT null;
ALTER TABLE jobs MODIFY COLUMN date_scheduled_ex_works date null;
ALTER TABLE jobs MODIFY COLUMN date_order_sent_to_customer date null;
ALTER TABLE jobs MODIFY COLUMN sale_category int(2) null;
ALTER TABLE jobs ALTER COLUMN all_sent SET DEFAULT 0;
ALTER TABLE jobs ALTER COLUMN all_paid SET DEFAULT 0;
ALTER TABLE order_acknowledgements MODIFY COLUMN ship_via varchar(255) null;
ALTER TABLE order_acknowledgements MODIFY COLUMN fob varchar(255) null;
ALTER TABLE order_acknowledgements MODIFY COLUMN estimated_deliery varchar(255) null;
-- write a script to make everythin nullable..
| issue_date | date | NO | | NULL | |
| dispatch_date | date | NO | | NULL | |
| date_arrived | date | NO | | NULL | |
| title | varchar(255) | NO | | NULL | |
| principle_id | int(11) | NO | | NULL | |
| principle_reference | varchar(255) | NO | | NULL | |
| document_id | int(11) | NO | | NULL | |
| currency_id | int(11) | YES | | NULL | |
| ordered_from | text | NO | | NULL | |
| description | text | NO | | NULL | |
| dispatch_by | varchar(255) | NO | | NULL | |
| deliver_to | text | NO | | NULL | |
| shipping_instructions | text | NO | | NULL | |
| jobs_text | varchar(512) | NO | | NULL | |
+-----------------------+--------------+------+-----+---------+----------------+

View file

@ -137,6 +137,7 @@ if ($currentuser['User']['access_level'] == 'manager' || $currentuser['User']['a
</li> </li>
<li><?php echo $html->link('Help', '/pages/about'); ?> <li><?php echo $html->link('Help', '/pages/about'); ?>
<ul> <ul>
<li><a href="/pages/bug">Raise a bug</a></li>
<li><a href="https://gitlab.com/minimalist.software/cmc-sales/issues">Issue tracker</a></li> <li><a href="https://gitlab.com/minimalist.software/cmc-sales/issues">Issue tracker</a></li>
<li class="last"><?php echo $html->link('About', '/pages/about'); ?></li> <li class="last"><?php echo $html->link('About', '/pages/about'); ?></li>
</ul> </ul>

View file

@ -1,5 +1,4 @@
<h3>About this Software</h3> <h3>About this Software</h3>
<p>Developed by Karl Cordes</p> <p>Developed by Karl Cordes</p>
<br> <br>
<pre>Copyright (c) 2009 Karl Cordes <pre>Copyright (c) 2009 Karl Cordes

35
app/views/pages/bug.ctp Normal file
View file

@ -0,0 +1,35 @@
<h2>Raise a bug report</h2>
<p>If you've found a bug. Please email the following template to:
<a href="mailto:karl@minimalist.software">karl@minimalist.software</a>
<div class="bugtemplate">
# Summary of the problem
# What should happen
# What does happen
# Steps to reproduce
</div>
<h3>Example of a bug report</h3>
<div class="bugtemplate">
# Summary of the problem
Unable to add new contact to Customer
# What should happen
I click add contact and the new contact form appears
# What does happen
Click add contact and no form appears
# Steps to reproduce
eg.
1. Go to https://sales.cmctechnologies.com.au/customers/view/2075
2. Click "add contact"
3. No form appears
</div>

View file

@ -1692,3 +1692,9 @@ ul.document-buttons li {
clear: both; clear: both;
} }
.bugtemplate {
font-family: monospace;
white-space: pre;
font-size: 140%;
margin-bottom: 1em;
}

4
backup.sh Normal file
View file

@ -0,0 +1,4 @@
#!/bin/bash
FILENAME=backups/backup_$(date +'%Y%m%d-%H%M%S').sql.gz
mysqldump cmc | gzip > $FILENAME
rclone copy $FILENAME gdrivebackups:database/

7
run_docker_local.sh Executable file
View file

@ -0,0 +1,7 @@
ID=$(docker ps -q)
docker kill $ID
sleep 1
docker run -d -p 127.0.0.1:8888:80 \
--mount type=bind,source=/home/k/projects/cmc-sales/app/webroot/pdf,target=/var/www/cmc-sales/app/webroot/pdf \
--mount type=bind,source=/home/k/projects/cmc-sales/app/webroot/attachments_files,target=/var/www/cmc-sales/app/webroot/attachments_files \
cmc:latest