Compare commits
10 Commits
c2cf7bc905
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 45f2c61c17 | |||
| dd30ade94b | |||
| 587287fb82 | |||
| 78788f05e3 | |||
| 87d81bb447 | |||
| 52427c453e | |||
| 6e5d4e39e7 | |||
| ea1bc210c6 | |||
| acee9670d0 | |||
| 54ed8d999f |
40
.github/workflows/pipeline.yml
vendored
40
.github/workflows/pipeline.yml
vendored
@@ -80,13 +80,35 @@ jobs:
|
||||
echo "$SSH_PRIVATE_KEY" > private.key
|
||||
sudo chmod 400 private.key
|
||||
|
||||
- name: Setup Nomad
|
||||
uses: hashicorp/setup-nomad@main
|
||||
with:
|
||||
nomad_version: '1.10.5'
|
||||
|
||||
- name: Deploy Job to Nomad
|
||||
run: |
|
||||
nomad job run -var="version=${{ github.sha }}" infra/nomad/code-snippets.nomad.hcl
|
||||
- name: Write Ansible Inventory To File
|
||||
env:
|
||||
NOMAD_ADDR: ${{ secrets.NOMAD_ADDR }}
|
||||
APP_HOST: ${{ secrets.APP_HOST }}
|
||||
run: |
|
||||
echo "[app]" > hosts.ini
|
||||
echo "$APP_HOST" >> hosts.ini
|
||||
|
||||
- name: Install Ansible
|
||||
run: |
|
||||
sudo apt-add-repository ppa:ansible/ansible -y
|
||||
sudo apt-get update -y
|
||||
sudo apt-get install ansible -y
|
||||
|
||||
- name: Run Ansible Playbook to Configure Servers
|
||||
run: |
|
||||
export ANSIBLE_HOST_KEY_CHECKING=False # Disable host key checking
|
||||
ansible-playbook infra/ansible/deploy-playbook.yml --private-key private.key --inventory hosts.ini
|
||||
env:
|
||||
APP_HOST: ${{ secrets.APP_HOST }}
|
||||
REGISTRY_USERNAME: ${{ secrets.DOCKER_USERNAME }}
|
||||
REGISTRY_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
|
||||
|
||||
# - name: Setup Nomad
|
||||
# uses: hashicorp/setup-nomad@main
|
||||
# with:
|
||||
# nomad_version: '1.10.5'
|
||||
|
||||
# - name: Deploy Job to Nomad
|
||||
# run: |
|
||||
# nomad job run -var="version=${{ github.sha }}" infra/nomad/code-snippets.nomad.hcl
|
||||
# env:
|
||||
# NOMAD_ADDR: ${{ vars.NOMAD_ADDR }}
|
||||
|
||||
@@ -76,6 +76,10 @@ export default defineConfig({
|
||||
{ text: 'Local DB (PostgreSQL)', link: '/docker/local-db-pg' },
|
||||
]
|
||||
},
|
||||
{
|
||||
text: 'Docker Swarm',
|
||||
link: '/docker-swarm/',
|
||||
},
|
||||
{
|
||||
text: 'EF Core',
|
||||
link: '/ef-core/',
|
||||
|
||||
27
docs/docker-swarm/index.md
Normal file
27
docs/docker-swarm/index.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# Docker Swarm Snippets and Musings
|
||||
|
||||
## Updating Services
|
||||
|
||||
View services:
|
||||
|
||||
```bash
|
||||
docker service ls
|
||||
```
|
||||
|
||||
To scale a service up or down:
|
||||
|
||||
```bash
|
||||
docker service scale <service_name>=<number_of_replicas>
|
||||
```
|
||||
|
||||
Sometimes services get stuck or need to be forcefully updated:
|
||||
|
||||
```bash
|
||||
docker service update --force <service_name>
|
||||
```
|
||||
|
||||
::: tip
|
||||
|
||||
Sometimes if you need to force containers to restart use the update force (e.g. after restarting a node).
|
||||
|
||||
:::
|
||||
@@ -26,6 +26,10 @@ hero:
|
||||
text: Docker
|
||||
link: /docker/
|
||||
|
||||
- theme: alt
|
||||
text: Docker Swarm
|
||||
link: /docker-swarm/
|
||||
|
||||
- theme: alt
|
||||
text: EF Core
|
||||
link: /ef-core/
|
||||
|
||||
@@ -2,20 +2,38 @@
|
||||
|
||||
Handy commands for dumping and restoring Postgres databases.
|
||||
|
||||
:::info
|
||||
::: info
|
||||
Most of these commands are run using Docker as then we don't need to have Postgres installed locally.
|
||||
|
||||
If a different version of Postgres is needed, just change the version number in the Docker image tag.
|
||||
:::
|
||||
|
||||
## Setup
|
||||
|
||||
Create a pgpass file in the current directory with the following content:
|
||||
|
||||
```
|
||||
<server>:<port>:<database>:<username>:<password>
|
||||
```
|
||||
|
||||
::: tip
|
||||
Use `*` as a wildcard for any of the fields except for the password.
|
||||
:::
|
||||
|
||||
## Dumping a Database
|
||||
|
||||
```bash
|
||||
docker run --network host --rm -v .:/tmp -e PGPASSWORD=mysecretpassword postgres:16 pg_dump -h localhost -U myuser -d mydb -f /tmp/dump.sql
|
||||
docker run --network host --rm -v .:/tmp -v ./pgpass:/root/.pgpass -e PGPASSFILE=/root/.pgpass postgres:16 bash -c "chmod 600 /root/.pgpass && pg_dump -h <server> -p <port> -U <username> <database> -f /tmp/$(date +%Y%m%d_%H%M%S)_<database>_dump.sql -c --if-exists"
|
||||
```
|
||||
|
||||
## Restoring a Database
|
||||
## Dumping a Cluster
|
||||
|
||||
```bash
|
||||
docker run --network host --rm -v .:/tmp -e PGPASSWORD=mysecretpassword postgres:16 psql -h localhost -U myuser -d mydb -f /tmp/dump.sql
|
||||
docker run --network host --rm -v .:/tmp -v ./pgpass:/root/.pgpass -e PGPASSFILE=/root/.pgpass postgres:16 bash -c "chmod 600 /root/.pgpass && pg_dumpall -h <server> -p <port> -U <username> -f /tmp/$(date +%Y%m%d_%H%M%S)_<server>_cluster_dump.sql -c --if-exists"
|
||||
```
|
||||
|
||||
## Restoring from a SQL Dump
|
||||
|
||||
```bash
|
||||
docker run --network host --rm -v .:/tmp -v ./pgpass:/root/.pgpass -e PGPASSFILE=/root/.pgpass postgres:16 bash -c "chmod 600 /root/.pgpass && psql -h <server> -p <port> -U <username> <database> -f /tmp/dump.sql -X"
|
||||
```
|
||||
@@ -1,12 +1,12 @@
|
||||
variable "version" {
|
||||
type = string
|
||||
default = "latest"
|
||||
}
|
||||
|
||||
job "code-snippets" {
|
||||
datacenters = ["dc1"]
|
||||
type = "service"
|
||||
|
||||
variable "version" {
|
||||
type = string
|
||||
default = "latest"
|
||||
}
|
||||
|
||||
group "code-snippets" {
|
||||
count = 1
|
||||
|
||||
|
||||
Reference in New Issue
Block a user