fix: Combine workflows for Gitea compatibility, use artifact v3
This commit is contained in:
151
.gitea/workflows/deploy.yml
Normal file
151
.gitea/workflows/deploy.yml
Normal file
@@ -0,0 +1,151 @@
|
||||
name: Deploy Cluster
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
TF_VERSION: "1.7.0"
|
||||
TF_VAR_hcloud_token: ${{ secrets.HCLOUD_TOKEN }}
|
||||
TF_VAR_s3_access_key: ${{ secrets.S3_ACCESS_KEY }}
|
||||
TF_VAR_s3_secret_key: ${{ secrets.S3_SECRET_KEY }}
|
||||
|
||||
jobs:
|
||||
terraform:
|
||||
name: Terraform
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Terraform
|
||||
uses: hashicorp/setup-terraform@v3
|
||||
with:
|
||||
terraform_version: ${{ env.TF_VERSION }}
|
||||
|
||||
- name: Terraform Format Check
|
||||
working-directory: terraform
|
||||
run: terraform fmt -check -recursive
|
||||
|
||||
- name: Terraform Init
|
||||
working-directory: terraform
|
||||
run: |
|
||||
terraform init \
|
||||
-backend-config="endpoint=${{ secrets.S3_ENDPOINT }}" \
|
||||
-backend-config="bucket=${{ secrets.S3_BUCKET }}" \
|
||||
-backend-config="region=auto" \
|
||||
-backend-config="access_key=${{ secrets.S3_ACCESS_KEY }}" \
|
||||
-backend-config="secret_key=${{ secrets.S3_SECRET_KEY }}"
|
||||
|
||||
- name: Terraform Validate
|
||||
working-directory: terraform
|
||||
run: terraform validate
|
||||
|
||||
- name: Terraform Plan
|
||||
id: plan
|
||||
working-directory: terraform
|
||||
run: |
|
||||
terraform plan \
|
||||
-var="ssh_public_key=${{ secrets.SSH_PUBLIC_KEY }}" \
|
||||
-var="ssh_private_key=${{ secrets.SSH_PRIVATE_KEY }}" \
|
||||
-out=tfplan \
|
||||
-no-color
|
||||
continue-on-error: true
|
||||
|
||||
- name: Post Plan to PR
|
||||
if: github.event_name == 'pull_request'
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const output = `#### Terraform Plan
|
||||
\`\`\`
|
||||
${{ steps.plan.outputs.stdout }}
|
||||
\`\`\``;
|
||||
github.rest.issues.createComment({
|
||||
issue_number: context.issue.number,
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
body: output
|
||||
});
|
||||
|
||||
- name: Fail if plan failed
|
||||
if: steps.plan.outcome == 'failure'
|
||||
run: exit 1
|
||||
|
||||
- name: Terraform Apply
|
||||
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
|
||||
working-directory: terraform
|
||||
run: |
|
||||
terraform apply \
|
||||
-var="ssh_public_key=${{ secrets.SSH_PUBLIC_KEY }}" \
|
||||
-var="ssh_private_key=${{ secrets.SSH_PRIVATE_KEY }}" \
|
||||
-auto-approve
|
||||
|
||||
- name: Save Terraform Outputs
|
||||
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
|
||||
working-directory: terraform
|
||||
run: terraform output -json > ../outputs/terraform_outputs.json
|
||||
|
||||
- name: Upload Outputs
|
||||
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: terraform-outputs
|
||||
path: outputs/terraform_outputs.json
|
||||
|
||||
ansible:
|
||||
name: Ansible
|
||||
runs-on: ubuntu-latest
|
||||
needs: terraform
|
||||
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Download Terraform Outputs
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: terraform-outputs
|
||||
path: outputs/
|
||||
|
||||
- name: Setup Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.11'
|
||||
|
||||
- name: Install Ansible
|
||||
run: |
|
||||
pip install ansible kubernetes jinja2 pyyaml
|
||||
|
||||
- name: Install Ansible Collections
|
||||
run: ansible-galaxy collection install -r ansible/requirements.yml
|
||||
|
||||
- name: Setup SSH Key
|
||||
run: |
|
||||
mkdir -p ~/.ssh
|
||||
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_ed25519
|
||||
chmod 600 ~/.ssh/id_ed25519
|
||||
|
||||
- name: Generate Ansible Inventory
|
||||
working-directory: ansible
|
||||
run: python3 generate_inventory.py
|
||||
|
||||
- name: Run Ansible Playbook
|
||||
working-directory: ansible
|
||||
run: |
|
||||
ansible-playbook site.yml \
|
||||
-e "hcloud_token=${{ secrets.HCLOUD_TOKEN }}" \
|
||||
-e "cluster_name=k8s-cluster"
|
||||
env:
|
||||
ANSIBLE_HOST_KEY_CHECKING: "False"
|
||||
|
||||
- name: Upload Kubeconfig
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: kubeconfig
|
||||
path: outputs/kubeconfig
|
||||
Reference in New Issue
Block a user