Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/workflows/build_and_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Build the docker images and deploy
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
jobs:
build_and_push_images:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Log into dockerhub
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
- name: Build the Authoritative DNS image
run: |
cd authdns
docker build -t dominikmatic/dddns-authdns:latest .
- name: Build the API server image
run: |
cd apiserver
docker build -t dominikmatic/dddns-apiserver:latest .
- name: Push the authdns Docker image
run: docker push dominikmatic/dddns-authdns:latest
- name: Push the apiserver Docker image
run: docker push dominikmatic/dddns-apiserver:latest
deploy:
needs: build_and_push_images
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: template .env file
run: |
cat <<EOF > ./deployment/files/deploy/.env
DB_USER=${{ secrets.DB_USER }}
DB_PASS=${{ secrets.DB_PASS }}
DB_HOST=${{ secrets.DB_HOST }}
DB_NAME=${{ secrets.DB_NAME }}
AUTH_TOKEN=${{ secrets.AUTH_TOKEN }}
EOF

- name: Run ansible playbook
uses: dawidd6/action-ansible-playbook@v2
with:
# Required, playbook filepath
playbook: deployment/deploy.yml
# Optional, SSH private key
key: ${{secrets.ANSIBLE_PRIVATE_KEY}}
# Optional, literal inventory file contents
inventory: |
[dddns_servers]
3.73.187.39
# Optional, SSH known hosts file content
known_hosts: |
3.73.187.39 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFPYJDOesJo7cyobs6S4mjhhud13BpmG0GnLZ/Q8yf7Y
options: |
-u ansible
4 changes: 4 additions & 0 deletions deployment/ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[defaults]
inventory = inventory
remote_user = ansible
private_key_file = ~/.ssh/ansible
86 changes: 86 additions & 0 deletions deployment/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---

- hosts: dddns_servers
become: true

vars:
deploy_path: /opt/dddns
nginx_conf_dir: "{{ deploy_path }}/nginx"
initdb_conf_dir: "{{ deploy_path }}/initdb"

tasks:
- name: ensure deploy directory exists
file:
path: "{{ deploy_path }}"
state: directory
owner: root
group: root
mode: '0755'

- name: copy .env to deploy directory
copy:
src: files/deploy/.env
dest: "{{ deploy_path }}/.env"
owner: root
group: root
mode: '0644'

- name: copy docker-compose.yml and docker-compose.prod.yml to deploy directory
copy:
src: "files/deploy/{{ item }}"
dest: "{{ deploy_path }}/{{ item }}"
owner: root
group: root
mode: '0644'
loop:
- docker-compose.yml
- docker-compose.prod.yml

- name: ensure nginx config directory exists
file:
path: "{{ nginx_conf_dir }}"
state: directory
owner: root
group: root
mode: '0755'

- name: copy nginx.conf to nginx config directory
copy:
src: files/deploy/nginx.conf
dest: "{{ nginx_conf_dir }}/nginx.conf"
owner: root
group: root
mode: '0644'

- name: ensure initdb directory exists
file:
path: "{{ initdb_conf_dir }}"
state: directory
owner: root
group: root
mode: '0755'

- name: copy init.sql to initdb directory
copy:
src: files/deploy/init.sql
dest: "{{ initdb_conf_dir }}/init.sql"
owner: root
group: root
mode: '0644'

- name: Pull docker images
community.docker.docker_compose_v2:
project_src: "{{ deploy_path }}"
files:
- docker-compose.yml
- docker-compose.prod.yml
pull: always

- name: run docker compose up -d
community.docker.docker_compose_v2:
project_src: "{{ deploy_path }}"
files:
- docker-compose.yml
- docker-compose.prod.yml
state: present
recreate: auto
1 change: 1 addition & 0 deletions deployment/files/deploy/docker-compose.prod.yml
1 change: 1 addition & 0 deletions deployment/files/deploy/docker-compose.yml
1 change: 1 addition & 0 deletions deployment/files/deploy/init.sql
1 change: 1 addition & 0 deletions deployment/files/deploy/nginx.conf
2 changes: 2 additions & 0 deletions deployment/inventory
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[dddns_servers]
3.73.187.39
1 change: 1 addition & 0 deletions dev_up.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sudo docker compose -f docker-compose.yml -f docker-compose.dev.yml up -d --force-recreate
2 changes: 1 addition & 1 deletion docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
services:
nginx:
image: nginx:1.29.0-alpine
container_name: nginx
container_name: dddns-apiserver-nginx
ports:
- "53535:53535"
volumes:
Expand Down
1 change: 0 additions & 1 deletion initdb/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ INSERT INTO dns_records (name, type, value, ttl) VALUES
('dominikmatic.com', 'A', '3.73.187.39', 300),
('www.dominikmatic.com', 'A', '3.73.187.39', 300),
('*.dominikmatic.com', 'A', '3.73.187.39', 300);

2 changes: 1 addition & 1 deletion nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ http {


location / {
proxy_pass http://dddns-apiserver:53530
proxy_pass http://dddns-apiserver:53530;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
Expand Down