45 lines
1.7 KiB
YAML
45 lines
1.7 KiB
YAML
name: Setup K8S Environment
|
|
description: Prepare the environment for A13labs CI/CD pipelines
|
|
inputs:
|
|
k8s-target:
|
|
description: "The target host to deploy the K8S applications"
|
|
default: "microk8s"
|
|
|
|
runs:
|
|
using: "composite"
|
|
steps:
|
|
- name: Copy Kube Config from remote host
|
|
shell: bash
|
|
env:
|
|
VAULT_MASTER_PASSWORD: ${{ secrets.VAULT_MASTER_PASSWORD }}
|
|
ANSIBLE_USER: ${{ secrets.ANSIBLE_USER }}
|
|
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
|
|
run: |
|
|
mkdir -p ~/.kube
|
|
ansible -i ansible/inventory/hosts -u $ANSIBLE_USER -m fetch -a "src=/home/$ANSIBLE_USER/.kube/config dest=~/.kube/config flat=yes" {{ inputs.k8s-target }}
|
|
|
|
- name: Terraform Init
|
|
shell: bash
|
|
env:
|
|
VAULT_MASTER_PASSWORD: ${{ secrets.VAULT_MASTER_PASSWORD }}
|
|
run: |
|
|
cd terraform/k8sapps
|
|
sectool exec terraform init
|
|
|
|
- name: Terraform Apply
|
|
shell: bash
|
|
env:
|
|
VAULT_MASTER_PASSWORD: ${{ secrets.VAULT_MASTER_PASSWORD }}
|
|
ANSIBLE_USER: ${{ secrets.ANSIBLE_USER }}
|
|
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
|
|
run: |
|
|
# Get Hostname and IP address of the target
|
|
ANSIBLE_HOST=$(ansible -i ansible/inventory/hosts -u $ANSIBLE_USER -m shell -a "hostname" {{ inputs.k8s-target }} | grep -oP '(\w+\.){2}\w+' | head -1)
|
|
IP_ADDR=$(ansible -i ansible/inventory/hosts -u $ANSIBLE_USER -m shell -a "curl -s ifconfig.me" {{ inputs.k8s-target }} | grep -oP '(\d+\.){3}\d+')
|
|
|
|
# Forward the k8s API server port to localhost
|
|
ssh -f -N -L 16443:localhost:16443 $ANSIBLE_USER@$ANSIBLE_HOST
|
|
|
|
# Override the kube config file to use localhost
|
|
sed -i "s/server: https:\/\/$IP_ADDR:16443/server: https:\/\/localhost:16443/g" ~/.kube/config
|