Skip to content

Commit

Permalink
fix: provision and start container workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
jkellerer committed Jan 29, 2024
1 parent 4cf6cae commit 50ccf81
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 23 deletions.
29 changes: 26 additions & 3 deletions .github/workflows/ansibleOnServer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,19 @@ on:
description: 'Ansible file to run'
required: true
type: string

secrets:
SERVER_SSH_PRIVATE_KEY:
description: 'SSH private key for server'
required: true
SERVER_IP_ADDRESS:
description: 'IP address of server'
required: true
SERVER_USER:
description: 'User on server'
required: true
SERVER_USER_PASSWORD:
description: 'Password of user on server'
required: true

jobs:
ansibleOnServer:
Expand All @@ -26,13 +38,24 @@ jobs:
python -m pip install --upgrade pip
pip install ansible
- name: Cache pip
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip
restore-keys: |
${{ runner.os }}-pip
- name: Set up SSH key
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SERVER_SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H {{ secrets.SERVER_IP_ADDRESS }} >> ~/.ssh/known_hosts
ssh-keyscan -H ${{ secrets.SERVER_IP_ADDRESS }} >> ~/.ssh/known_hosts
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa

- name: Run Ansible
run: |
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 }}
ansible-playbook --inventory server/provision/inventory_for_ci.yml --extra-vars "remote_server_user=${{ secrets.SERVER_USER }} remote_server_password=${{ secrets.SERVER_USER_PASSWORD }}" ${{ inputs.ansible_file }}
22 changes: 8 additions & 14 deletions .github/workflows/provisionServer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,11 @@ on: workflow_dispatch

jobs:
provisionServer:
runs-on: ubuntu-latest
steps:
- name: ProvisionServer
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'
uses: ./.github/workflows/ansibleOnServer.yml
with:
ansible_file: 'server/provision/provisionServer.yml'
secrets:
SERVER_SSH_PRIVATE_KEY: ${{ secrets.SERVER_SSH_PRIVATE_KEY }}
SERVER_IP_ADDRESS: ${{ secrets.SERVER_IP_ADDRESS }}
SERVER_USER: ${{ secrets.SERVER_USER }}
SERVER_USER_PASSWORD: ${{ secrets.SERVER_USER_PASSWORD }}
14 changes: 8 additions & 6 deletions .github/workflows/startContainersOnServer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ on: workflow_dispatch

jobs:
provisionServer:
runs-on: ubuntu-latest
steps:
- name: ProvisionServer
uses: ./.github/workflows/ansibleOnServer.yml@main
with:
ansible_file: 'provision/startContainers.yml'
uses: ./.github/workflows/ansibleOnServer.yml
with:
ansible_file: 'server/provision/startContainers.yml'
secrets:
SERVER_SSH_PRIVATE_KEY: ${{ secrets.SERVER_SSH_PRIVATE_KEY }}
SERVER_IP_ADDRESS: ${{ secrets.SERVER_IP_ADDRESS }}
SERVER_USER: ${{ secrets.SERVER_USER }}
SERVER_USER_PASSWORD: ${{ secrets.SERVER_USER_PASSWORD }}

0 comments on commit 50ccf81

Please sign in to comment.