Skip to content

Commit 3149e2b

Browse files
committed
Making it compatible with the Digital Ocean Marketplace
- Adding scripts for clean up and checks. - Updating README.md to make it more understandable how to create your own snapshot. - Temporarily removing instructions to update a live image to minimise confusion. - Updating Ansible playbook to enable UFW.
1 parent 9a0411b commit 3149e2b

File tree

10 files changed

+778
-39
lines changed

10 files changed

+778
-39
lines changed

README.md

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
Packer & Ansible template that sets up a Digital Ocean snapshot of a PostgreSQL server with pre-installed and enabled goodies
1+
Packer & Ansible template that sets up a Digital Ocean snapshot of a PostgreSQL server with pre-installed and enabled goodies.
22

3-
## Specifications
4-
- Ubuntu 18.04 (Bionic)
3+
## Supported Images
4+
- Ubuntu 18.04 Bionic (LTS)
55

66
## Default Features
77
✅ Postgres 12
@@ -21,25 +21,34 @@ Packer & Ansible template that sets up a Digital Ocean snapshot of a PostgreSQL
2121
🗹 [Ansible](https://docs.ansible.com/ansible/latest/installation_guide/index.html)
2222

2323
## Walkthrough
24+
25+
1. Install the Ansible role `ANXS.postgresql`.
26+
```
27+
$ ansible-galaxy install ANXS.postgresql -r tasks/install_roles.yml --force
2428
```
25-
$ ansible-galaxy install ANXS.postgresql -r install_roles.yml --force
2629

30+
2. `DO_TOKEN`, `SNAPSHOT_NAME` and `REGION` all need to be defined. A list of valid Digital Ocean regions can be found [here](https://www.digitalocean.com/docs/platform/availability-matrix/).
31+
```
2732
$ export DO_TOKEN=your_digital_ocean_token
2833
$ export SNAPSHOT_NAME=your_snapshot_name
2934
$ export REGION=your_chosen_region
35+
```
3036

31-
# Name is now also mandatory
37+
3. Create the Digital Ocean snapshot
38+
```
3239
$ packer build \
3340
-var "do_token=$DO_TOKEN" \
3441
-var "name=$SNAPSHOT_NAME" \
35-
-var "$REGION" \
42+
-var "region=$REGION" \
3643
packer.json
3744
```
38-
A list of available Digital Ocean regions can be found [here](https://www.digitalocean.com/docs/platform/availability-matrix/).
3945

40-
See [how to use ansible to update an existing instance](ansible/README.md).
46+
Once this is complete, you now have a snapshot available to use for any of your droplets.
4147

4248
## Notes on provisioning
49+
1. The PostgreSQL server can be further customised. Available provisioning variables that can be manipulated are found in `ansible/vars.yml`
50+
2. There are also additional provisioning variables from the role [anxs.postgres](https://github.com/ANXS/postgresql). The exhaustive list can be found [here](https://github.com/ANXS/postgresql/blob/master/defaults/main.yml).
51+
3. To be in line with the standards of images found in the Digital Ocean Marketplace, scripts found in `scripts` are also ran to clean up the snapshot and make it compatible with the Marketplace. They are taken from [here](https://github.com/digitalocean/marketplace-partners/tree/master/scripts). More information on what these scripts achieve can be found [here](https://github.com/digitalocean/marketplace-partners/blob/master/getting-started.md).
4352

44-
1. Variables can be manipulated in `ansible/vars.yml`
45-
2. The playbook uses the role [anxs.postgres](https://github.com/ANXS/postgresql). Other available variables can be found [here](https://github.com/ANXS/postgresql/blob/master/defaults/main.yml)
53+
## Roadmap
54+
🗹 Template for setting up a snapshot on AWS.

ansible/README.md

Lines changed: 0 additions & 22 deletions
This file was deleted.

ansible/inventory.ini

Lines changed: 0 additions & 2 deletions
This file was deleted.

ansible/playbook.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,19 @@
1919
postgresql_user:
2020
name: postgres
2121
password: "{{ postgres_superadmin_password }}"
22+
23+
- name: UFW - Allow SSH connections
24+
ufw:
25+
rule: allow
26+
name: OpenSSH
27+
28+
- name: UFW - Allow connections to postgreSQL (5432)
29+
ufw:
30+
rule: allow
31+
port: '5432'
32+
33+
- name: UFW - Deny all other incoming traffix by default
34+
ufw:
35+
state: enabled
36+
policy: deny
37+
direction: incoming

ansible/tasks/setup-system.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
apt: update_cache=yes upgrade=yes
55
# SEE http://archive.vn/DKJjs#parameter-upgrade
66

7-
- name: Install Python3 and pip
7+
- name: Install essentials
88
apt:
99
pkg:
1010
- python3
1111
- python3-pip
12+
- ufw
1213
update_cache: yes
1314
cache_valid_time: 3600
1415

packer.json

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,19 @@
1313
"ssh_username": "root",
1414
"snapshot_name": "{{user `name`}}"
1515
}],
16-
"provisioners": [{
17-
"type": "ansible",
18-
"playbook_file": "ansible/playbook.yml"
19-
}]
16+
"provisioners": [
17+
{
18+
"type": "ansible",
19+
"playbook_file": "ansible/playbook.yml"
20+
},
21+
{
22+
"type": "shell",
23+
"scripts": [
24+
"scripts/01-test",
25+
"scripts/90-cleanup.sh",
26+
"scripts/91-log_cleanup.sh",
27+
"scripts/99-img_check.sh"
28+
]
29+
}
30+
]
2031
}

scripts/01-test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
#
3+
# Scripts in this directory are run during the build process.
4+
# each script will be uploaded to /tmp on your build droplet,
5+
# given execute permissions and run. The cleanup process will
6+
# remove the scripts from your build system after they have run
7+
# if you use the build_image task.
8+
#
9+
echo "Commencing Digital Ocean Checks"

scripts/90-cleanup.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
apt-get -y update
4+
apt-get -y upgrade
5+
rm -rf /tmp/* /var/tmp/*
6+
history -c
7+
cat /dev/null > /root/.bash_history
8+
unset HISTFILE
9+
apt-get -y autoremove
10+
apt-get -y autoclean
11+
find /var/log -mtime -1 -type f -exec truncate -s 0 {} \;
12+
rm -rf /var/log/*.gz /var/log/*.[0-9] /var/log/*-????????
13+
rm -rf /var/lib/cloud/instances/*
14+
rm -f /root/.ssh/authorized_keys /etc/ssh/*key*
15+
touch /etc/ssh/revoked_keys
16+
chmod 600 /etc/ssh/revoked_keys
17+
18+
# Securely erase the unused portion of the filesystem
19+
GREEN='\033[0;32m'
20+
NC='\033[0m'
21+
printf "\n${GREEN}Writing zeros to the remaining disk space to securely
22+
erase the unused portion of the file system.
23+
Depending on your disk size this may take several minutes.
24+
The secure erase will complete successfully when you see:${NC}
25+
dd: writing to '/zerofile': No space left on device\n
26+
Beginning secure erase now\n"
27+
28+
dd if=/dev/zero of=/zerofile &
29+
PID=$!
30+
while [ -d /proc/$PID ]
31+
do
32+
printf "."
33+
sleep 5
34+
done
35+
sync; rm /zerofile; sync
36+
cat /dev/null > /var/log/lastlog; cat /dev/null > /var/log/wtmp

scripts/91-log_cleanup.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
#Erasing all logs
3+
#
4+
echo "Clearing all log files"
5+
rm -rf /var/log/*

0 commit comments

Comments
 (0)