Skip to content

Commit

Permalink
feat: add provisioning for testserver
Browse files Browse the repository at this point in the history
  • Loading branch information
jkellerer authored and JonasKellerer committed Jan 27, 2024
1 parent 4932771 commit 4cf6cae
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ansibleOnServer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ jobs:
- name: Run Ansible
run: |
ansible-playbook -i {{ secrets.SERVER_IP_ADDRESS }}, ${{ inputs.ansible_file }}
ansible-playbook --inventory inventory_for_ci.yml --extra-vars "remote_server_user=${{ secrets.SERVER_USER }} remote_server_password=${{ secrets.SERVER_USER_PASSWORD }}" ${{ inputs.ansible_file }}
15 changes: 8 additions & 7 deletions .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: latest

- name: Build and push image
uses: docker/build-push-action@v5
Expand All @@ -44,10 +45,10 @@ jobs:
tags: ${{ steps.dockerMetadata.outputs.tags }}
labels: ${{ steps.dockerMetadata.outputs.labels }}

updateDockerImages:
runs-on: ubuntu-latest
steps:
- name: Update docker images
uses: ./.github/workflows/reusable-workflow.yml@main
with:
ansible_file: 'provision/updateWebsite.yml'
# updateDockerImages:
# runs-on: ubuntu-latest
# steps:
# - name: Update docker images
# uses: ./.github/workflows/ansibleOnServer.yml@main
# with:
# ansible_file: 'provision/updateWebsite.yml'
10 changes: 9 additions & 1 deletion .github/workflows/provisionServer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: ProvisionServer
uses: ./.github/workflows/reusable-workflow.yml@main
uses: ./.github/workflows/ansibleOnServer.yml@main
with:
ansible_file: 'provision/provisionServer.yml'

startContainers:
runs-on: ubuntu-latest
steps:
- name: StartContainers
uses: ./.github/workflows/ansibleOnServer.yml@main
with:
ansible_file: 'provision/startContainers.yml'
2 changes: 1 addition & 1 deletion .github/workflows/startContainersOnServer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: ProvisionServer
uses: ./.github/workflows/reusable-workflow.yml@main
uses: ./.github/workflows/ansibleOnServer.yml@main
with:
ansible_file: 'provision/startContainers.yml'
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ version: "3"

services:
website:
image: ghcr.io/jonaskellerer/variation:latest
container_name: variation_website
build:
context: ./website
Expand Down
10 changes: 10 additions & 0 deletions server/provision/inventory.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
all:
hosts:
varilis.de:
ansible_connection: ssh
ansible_user: "{{ remote_server_user }}"
ansible_become: true
vars:
server_docker_users:
- root
- variation
11 changes: 11 additions & 0 deletions server/provision/inventory_for_ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
all:
hosts:
varilis.de:
ansible_connection: ssh
ansible_user: "{{ remote_server_user }}"
ansible_become: true
ansible_become_password: "{{ remote_server_password }}"
vars:
server_docker_users:
- root
- variation
1 change: 1 addition & 0 deletions server/provision/provisionServer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
roles:
- role: general
- role: docker
- role: copyData
- role: nginx
2 changes: 2 additions & 0 deletions server/provision/requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
roles:
- src: geerlingguy.docker
9 changes: 9 additions & 0 deletions server/provision/roles/copyData/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---

- name: Copy docker-compose.yml
ansible.builtin.copy:
src: ../../../../../docker-compose.yml
dest: /home/{{ remote_server_user }}/docker-compose.yml
owner: "{{ remote_server_user }}"
group: "{{ remote_server_user }}"
mode: 0644
11 changes: 4 additions & 7 deletions server/provision/roles/general/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
---
- name: General setup
become: yes
tasks:
- name: Update all packages to the latest version
apt:
update_cache: yes
upgrade: dist
- name: Update all packages to the latest version
ansible.builtin.apt:
update_cache: yes
upgrade: dist
12 changes: 9 additions & 3 deletions server/provision/roles/startContainers/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
---
- name: Stop containers
ansible.builtin.command: |
docker-compose down
- name: Pulling containers
ansible.builtin.command: |
docker-compose pull
- name: Start containers
ansible.builtin.command: |
docker compose down
docker compose pull
docker compose up -d
docker-compose up -d
14 changes: 13 additions & 1 deletion server/provision/roles/updateWebsite/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,16 @@
ansible.builtin.command: |
docker stop variation_website
docker compose pull
docker compose up -d
docker compose up -d
- name: Stop containers
ansible.builtin.command: |
docker-compose stop variation_website
- name: Pulling containers
ansible.builtin.command: |
docker-compose pull
- name: Start containers
ansible.builtin.command: |
docker-compose up -d

0 comments on commit 4cf6cae

Please sign in to comment.