bunkerized-nginx/.github/workflows/staging-create-infra.yml

63 lines
2.3 KiB
YAML
Raw Normal View History

2023-03-01 17:46:40 +01:00
name: Create staging infra (REUSABLE)
on:
2023-03-01 17:46:40 +01:00
workflow_call:
inputs:
TYPE:
required: true
type: string
secrets:
CICD_SECRETS:
required: true
2023-08-31 08:17:56 +02:00
SECRET_KEY:
required: true
K8S_IP:
required: true
2023-03-01 17:46:40 +01:00
jobs:
create:
runs-on: ubuntu-latest
steps:
# Prepare
- name: Generate SSH keypair
run: ssh-keygen -b 2048 -t rsa -f ~/.ssh/id_rsa -q -N "" && ssh-keygen -f ~/.ssh/id_rsa -y > ~/.ssh/id_rsa.pub && echo -e "Host *\n StrictHostKeyChecking no" > ~/.ssh/ssh_config
if: inputs.TYPE != 'k8s'
- name: Checkout source code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
2023-03-01 17:46:40 +01:00
- name: Install terraform
uses: hashicorp/setup-terraform@a1502cd9e758c50496cc9ac5308c4843bcd56d36 # v3.0.0
2023-03-01 17:46:40 +01:00
- name: Install kubectl
uses: azure/setup-kubectl@901a10e89ea615cf61f57ac05cecdf23e7de06d8 # v3.2
2023-03-01 17:46:40 +01:00
if: inputs.TYPE == 'k8s'
with:
2023-10-20 16:34:12 +02:00
version: "v1.28.2"
2023-03-01 17:46:40 +01:00
- name: Set up Python 3.11
uses: actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236 # v4.7.1
2023-03-01 17:46:40 +01:00
if: inputs.TYPE != 'k8s'
with:
2023-03-09 10:04:59 +01:00
python-version: "3.11"
2023-03-01 17:46:40 +01:00
- name: Install ansible
run: pip install --no-cache-dir --require-hashes -r misc/requirements-ansible.txt
2023-03-01 17:46:40 +01:00
if: inputs.TYPE != 'k8s'
- name: Install ansible libs
run: ansible-galaxy install --timeout 120 monolithprojects.github_actions_runner,1.18.1 && ansible-galaxy collection install --timeout 120 community.general
2023-03-01 17:46:40 +01:00
if: inputs.TYPE != 'k8s'
# Create infra
- run: ./tests/create.sh ${{ inputs.TYPE }}
env:
CICD_SECRETS: ${{ secrets.CICD_SECRETS }}
2023-08-31 08:17:56 +02:00
K8S_IP: ${{ secrets.K8S_IP }}
2023-08-25 17:51:32 +02:00
- run: |
2023-08-30 15:19:02 +02:00
tar -cf terraform.tar /tmp/${{ inputs.TYPE }}
2023-08-25 17:51:32 +02:00
echo "$SECRET_KEY" > /tmp/.secret_key
openssl enc -in terraform.tar -aes-256-cbc -pbkdf2 -iter 100000 -md sha256 -pass file:/tmp/.secret_key -out terraform.tar.enc
2023-08-25 17:51:32 +02:00
rm -f /tmp/.secret_key
2023-03-01 17:46:40 +01:00
if: always()
2023-08-25 17:51:32 +02:00
env:
SECRET_KEY: ${{ secrets.SECRET_KEY }}
- uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
2023-03-01 17:46:40 +01:00
if: always()
with:
name: tf-${{ inputs.TYPE }}
2023-08-25 17:51:32 +02:00
path: terraform.tar.enc