Skip to content

Commit 8ef3518

Browse files
Merge pull request #1 from dominik-matic/finishing-up
Finishing up
2 parents 913da17 + 32fa189 commit 8ef3518

File tree

12 files changed

+155
-3
lines changed

12 files changed

+155
-3
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Build the docker images and deploy
2+
on:
3+
push:
4+
branches: [ "master" ]
5+
pull_request:
6+
branches: [ "master" ]
7+
jobs:
8+
build_and_push_images:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
- name: Log into dockerhub
13+
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
14+
- name: Build the Authoritative DNS image
15+
run: |
16+
cd authdns
17+
docker build -t dominikmatic/dddns-authdns:latest .
18+
- name: Build the API server image
19+
run: |
20+
cd apiserver
21+
docker build -t dominikmatic/dddns-apiserver:latest .
22+
- name: Push the authdns Docker image
23+
run: docker push dominikmatic/dddns-authdns:latest
24+
- name: Push the apiserver Docker image
25+
run: docker push dominikmatic/dddns-apiserver:latest
26+
deploy:
27+
needs: build_and_push_images
28+
runs-on: ubuntu-latest
29+
steps:
30+
- uses: actions/checkout@v3
31+
- name: template .env file
32+
run: |
33+
cat <<EOF > ./deployment/files/deploy/.env
34+
DB_USER=${{ secrets.DB_USER }}
35+
DB_PASS=${{ secrets.DB_PASS }}
36+
DB_HOST=${{ secrets.DB_HOST }}
37+
DB_NAME=${{ secrets.DB_NAME }}
38+
AUTH_TOKEN=${{ secrets.AUTH_TOKEN }}
39+
EOF
40+
41+
- name: Run ansible playbook
42+
uses: dawidd6/action-ansible-playbook@v2
43+
with:
44+
# Required, playbook filepath
45+
playbook: deployment/deploy.yml
46+
# Optional, SSH private key
47+
key: ${{secrets.ANSIBLE_PRIVATE_KEY}}
48+
# Optional, literal inventory file contents
49+
inventory: |
50+
[dddns_servers]
51+
3.73.187.39
52+
# Optional, SSH known hosts file content
53+
known_hosts: |
54+
3.73.187.39 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFPYJDOesJo7cyobs6S4mjhhud13BpmG0GnLZ/Q8yf7Y
55+
options: |
56+
-u ansible

deployment/ansible.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[defaults]
2+
inventory = inventory
3+
remote_user = ansible
4+
private_key_file = ~/.ssh/ansible

deployment/deploy.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
---
2+
3+
- hosts: dddns_servers
4+
become: true
5+
6+
vars:
7+
deploy_path: /opt/dddns
8+
nginx_conf_dir: "{{ deploy_path }}/nginx"
9+
initdb_conf_dir: "{{ deploy_path }}/initdb"
10+
11+
tasks:
12+
- name: ensure deploy directory exists
13+
file:
14+
path: "{{ deploy_path }}"
15+
state: directory
16+
owner: root
17+
group: root
18+
mode: '0755'
19+
20+
- name: copy .env to deploy directory
21+
copy:
22+
src: files/deploy/.env
23+
dest: "{{ deploy_path }}/.env"
24+
owner: root
25+
group: root
26+
mode: '0644'
27+
28+
- name: copy docker-compose.yml and docker-compose.prod.yml to deploy directory
29+
copy:
30+
src: "files/deploy/{{ item }}"
31+
dest: "{{ deploy_path }}/{{ item }}"
32+
owner: root
33+
group: root
34+
mode: '0644'
35+
loop:
36+
- docker-compose.yml
37+
- docker-compose.prod.yml
38+
39+
- name: ensure nginx config directory exists
40+
file:
41+
path: "{{ nginx_conf_dir }}"
42+
state: directory
43+
owner: root
44+
group: root
45+
mode: '0755'
46+
47+
- name: copy nginx.conf to nginx config directory
48+
copy:
49+
src: files/deploy/nginx.conf
50+
dest: "{{ nginx_conf_dir }}/nginx.conf"
51+
owner: root
52+
group: root
53+
mode: '0644'
54+
55+
- name: ensure initdb directory exists
56+
file:
57+
path: "{{ initdb_conf_dir }}"
58+
state: directory
59+
owner: root
60+
group: root
61+
mode: '0755'
62+
63+
- name: copy init.sql to initdb directory
64+
copy:
65+
src: files/deploy/init.sql
66+
dest: "{{ initdb_conf_dir }}/init.sql"
67+
owner: root
68+
group: root
69+
mode: '0644'
70+
71+
- name: Pull docker images
72+
community.docker.docker_compose_v2:
73+
project_src: "{{ deploy_path }}"
74+
files:
75+
- docker-compose.yml
76+
- docker-compose.prod.yml
77+
pull: always
78+
79+
- name: run docker compose up -d
80+
community.docker.docker_compose_v2:
81+
project_src: "{{ deploy_path }}"
82+
files:
83+
- docker-compose.yml
84+
- docker-compose.prod.yml
85+
state: present
86+
recreate: auto
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../docker-compose.prod.yml
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../docker-compose.yml

deployment/files/deploy/init.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../initdb/init.sql

deployment/files/deploy/nginx.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../nginx/nginx.conf

deployment/inventory

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[dddns_servers]
2+
3.73.187.39

dev_up.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sudo docker compose -f docker-compose.yml -f docker-compose.dev.yml up -d --force-recreate

docker-compose.prod.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
services:
22
nginx:
33
image: nginx:1.29.0-alpine
4-
container_name: nginx
4+
container_name: dddns-apiserver-nginx
55
ports:
66
- "53535:53535"
77
volumes:

0 commit comments

Comments
 (0)