Skip to content

Commit 1edbc6b

Browse files
committed
Implement terraform composite action
This will facilitate updating the deployment of the terraform infrastructure among the workflows.
1 parent 17959ff commit 1edbc6b

File tree

4 files changed

+291
-281
lines changed

4 files changed

+291
-281
lines changed
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
name: deploy-terraform-infrastructure
2+
description: |
3+
Deploy the infrastructure of a Mithril network with terraform.
4+
inputs:
5+
dry_run:
6+
description: Dry run will apply the terraform infrastructure, just plan it.
7+
required: true
8+
default: "true"
9+
terraform_backend_bucket:
10+
description: terraform backend bucket used to store terraform state.
11+
required: true
12+
environment_prefix:
13+
description: Mithril network environment prefix.
14+
required: true
15+
environment:
16+
description: Mithril network environment name.
17+
required: true
18+
cardano_network:
19+
description: Cardano network name.
20+
required: true
21+
google_region:
22+
description: Google Cloud region name.
23+
required: true
24+
google_zone:
25+
description: Google Cloud zone name.
26+
required: true
27+
google_machine_type:
28+
description: Google Cloud VM name.
29+
required: true
30+
google_compute_instance_data_disk_size:
31+
description: Google Cloud attached data disk size in GB.
32+
required: true
33+
google_application_credentials:
34+
description: Google Cloud application credentials (service account).
35+
required: true
36+
mithril_api_domain:
37+
description: Mithril network api domain root.
38+
required: true
39+
mithril_image_id:
40+
description: Mithril Docker image id to deploy.
41+
required: true
42+
mithril_protocol_parameters:
43+
description: Mithril protocol parameters.
44+
required: true
45+
mithril_signers:
46+
description: Mithril signers settings.
47+
required: true
48+
mithril_genesis_secret_key:
49+
description: Mithril genesis secret key (only for test networks).
50+
required: false
51+
mithril_genesis_verification_key_url:
52+
description: Mithril genesis verification key location.
53+
required: true
54+
mithril_era_reader_address_url:
55+
description: Mithril era reader address location.
56+
required: true
57+
mithril_era_reader_verification_key_url:
58+
description: Mithril era reader verification key url.
59+
required: true
60+
mithril_era_reader_secret_key:
61+
description: Mithril era reader secret key (onlye for test networks).
62+
required: false
63+
prometheus_auth_username:
64+
description: Prometheus metrics endpoint username.
65+
required: false
66+
prometheus_auth_password:
67+
description: Prometheus metrics endpoint password.
68+
required: false
69+
prometheus_ingest_host:
70+
description: Prometheus ingester endpoint location.
71+
required: false
72+
prometheus_ingest_username:
73+
description: Prometheus ingester endpoint username.
74+
required: false
75+
prometheus_ingest_password:
76+
description: Prometheus ingester endpoint password.
77+
required: false
78+
loki_auth_username:
79+
description: Loki metrics endpoint username.
80+
required: false
81+
loki_auth_password:
82+
description: Loki metrics endpoint password.
83+
required: false
84+
loki_ingest_host:
85+
description: Loki ingester endpoint location.
86+
required: false
87+
loki_ingest_username:
88+
description: Loki ingester endpoint username.
89+
required: false
90+
loki_ingest_password:
91+
description: Loki ingester endpoint password.
92+
required: false
93+
94+
runs:
95+
using: "composite"
96+
steps:
97+
- name: Checkout sources
98+
uses: actions/checkout@v3
99+
100+
- name: Prepare service account credentials
101+
shell: bash
102+
working-directory: mithril-infra
103+
run: |
104+
echo '${{ inputs.google_application_credentials}}' > ./google-application-credentials.json
105+
chmod u+x ./assets/tools/utils/google-credentials-public-key.sh
106+
./assets/tools/utils/google-credentials-public-key.sh ./google-application-credentials.json ./assets/ssh_keys curry
107+
108+
- name: Prepare terraform variables
109+
shell: bash
110+
working-directory: mithril-infra
111+
run: |
112+
cat > ./env.variables.tfvars << EOF
113+
environment_prefix = "${{ inputs.environment_prefix }}"
114+
cardano_network = "${{ inputs.cardano_network }}"
115+
google_region = "${{ inputs.google_region }}"
116+
google_zone = "${{ inputs.google_zone }}"
117+
google_machine_type = "${{ inputs.google_machine_type }}"
118+
google_compute_instance_data_disk_size = "${{ inputs.google_compute_instance_data_disk_size }}"
119+
google_service_credentials_json_file = "./google-application-credentials.json"
120+
mithril_api_domain = "${{ inputs.mithril_api_domain }}"
121+
mithril_image_id = "${{ inputs.mithril_image_id }}"
122+
mithril_genesis_verification_key_url = "${{ inputs.mithril_genesis_verification_key_url }}"
123+
mithril_genesis_secret_key = "${{ inputs.mithril_genesis_secret_key }}"
124+
mithril_protocol_parameters = ${{ fromJSON(inputs.mithril_protocol_parameters) }}
125+
mithril_era_reader_adapter_type = "cardano-chain"
126+
mithril_era_reader_address_url = "${{ inputs.mithril_era_reader_address_url }}"
127+
mithril_era_reader_verification_key_url = "${{ inputs.mithril_era_reader_verification_key_url }}"
128+
mithril_era_reader_secret_key = "${{ inputs.mithril_era_reader_secret_key }}"
129+
mithril_signers = ${{ fromJSON(inputs.mithril_signers) }}
130+
prometheus_auth_username = "${{ inputs.prometheus_auth_username }}"
131+
prometheus_auth_password = "${{ inputs.prometheus_auth_password }}"
132+
prometheus_ingest_host = "${{ inputs.prometheus_ingest_host }}"
133+
prometheus_ingest_username = "${{ inputs.prometheus_ingest_username }}"
134+
prometheus_ingest_password = "${{ inputs.prometheus_ingest_password }}"
135+
loki_auth_username = "${{ inputs.loki_auth_username }}"
136+
loki_auth_password = "${{ inputs.loki_auth_password }}"
137+
loki_ingest_host = "${{ inputs.loki_ingest_host }}"
138+
loki_ingest_username = "${{ inputs.loki_ingest_username }}"
139+
loki_ingest_password = "${{ inputs.loki_ingest_password }}"
140+
EOF
141+
terraform fmt ./env.variables.tfvars
142+
cat ./env.variables.tfvars
143+
144+
- name: Setup Terraform
145+
uses: hashicorp/setup-terraform@v2
146+
with:
147+
terraform_wrapper: false
148+
149+
- name: Init Terraform
150+
shell: bash
151+
working-directory: mithril-infra
152+
run: |
153+
GOOGLE_APPLICATION_CREDENTIALS=./google-application-credentials.json terraform init -backend-config="bucket=${{ inputs.terraform_backend_bucket }}" -backend-config="prefix=terraform/mithril-${{ inputs.environment }}"
154+
155+
- name: Check Terraform
156+
shell: bash
157+
working-directory: mithril-infra
158+
run: terraform fmt -check
159+
160+
- name: Terraform Plan
161+
if: inputs.dry_run == 'true'
162+
shell: bash
163+
working-directory: mithril-infra
164+
run: |
165+
GOOGLE_APPLICATION_CREDENTIALS=./google-application-credentials.json terraform plan --var-file=./env.variables.tfvars
166+
167+
- name: Terraform Apply
168+
shell: bash
169+
working-directory: mithril-infra
170+
if: inputs.dry_run == 'false'
171+
run: |
172+
GOOGLE_APPLICATION_CREDENTIALS=./google-application-credentials.json terraform apply -auto-approve --var-file=./env.variables.tfvars
173+
174+
- name: Cleanup
175+
shell: bash
176+
working-directory: mithril-infra
177+
run: |
178+
rm -f ./env.variables.tfvars
179+
rm -f ./google-application-credentials.json

.github/workflows/ci.yml

Lines changed: 40 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -438,106 +438,51 @@ jobs:
438438
google_zone: europe-west1-b
439439
google_machine_type: e2-highmem-4
440440
google_compute_instance_data_disk_size: 250
441-
441+
environment: ${{ matrix.environment }}
442442
runs-on: ubuntu-22.04
443-
444443
needs:
445444
- docker-mithril
446-
447-
environment: ${{ matrix.environment }}
448-
449-
env:
450-
GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
451-
GENESIS_SECRET_KEY: ${{ secrets.GENESIS_SECRET_KEY }}
452-
GENESIS_VERIFICATION_KEY_URL: ${{ vars.GENESIS_VERIFICATION_KEY_URL }}
453-
ERA_READER_ADDRESS_URL: ${{ vars.ERA_READER_ADDRESS_URL }}
454-
ERA_READER_VERIFICATION_KEY_URL: ${{ vars.ERA_READER_VERIFICATION_KEY_URL }}
455-
ERA_READER_SECRET_KEY: ${{ secrets.ERA_READER_SECRET_KEY }}
456-
PROMETHEUS_AUTH_USERNAME: ${{ secrets.PROMETHEUS_AUTH_USERNAME }}
457-
PROMETHEUS_AUTH_PASSWORD: ${{ secrets.PROMETHEUS_AUTH_PASSWORD }}
458-
PROMETHEUS_INGEST_HOST: ${{ vars.PROMETHEUS_INGEST_HOST }}
459-
PROMETHEUS_INGEST_USERNAME: ${{ secrets.PROMETHEUS_INGEST_USERNAME }}
460-
PROMETHEUS_INGEST_PASSWORD: ${{ secrets.PROMETHEUS_INGEST_PASSWORD }}
461-
LOKI_AUTH_USERNAME: ${{ secrets.LOKI_AUTH_USERNAME }}
462-
LOKI_AUTH_PASSWORD: ${{ secrets.LOKI_AUTH_PASSWORD }}
463-
LOKI_INGEST_HOST: ${{ vars.LOKI_INGEST_HOST }}
464-
LOKI_INGEST_USERNAME: ${{ secrets.LOKI_INGEST_USERNAME }}
465-
LOKI_INGEST_PASSWORD: ${{ secrets.LOKI_INGEST_PASSWORD }}
466-
467445
defaults:
468446
run:
469447
working-directory: mithril-infra
470-
471448
steps:
449+
- name: Checkout sources
450+
uses: actions/checkout@v3
472451

473-
- name: Checkout sources
474-
uses: actions/checkout@v3
475-
476-
- name: Get Docker image id
477-
run: echo "DOCKER_IMAGE_ID=${{ github.base_ref || github.ref_name }}-$(echo ${{ github.sha }} | cut -c1-7)" >> $GITHUB_ENV
478-
479-
- name: Prepare service account credentials
480-
run: |
481-
echo '${{ env.GOOGLE_APPLICATION_CREDENTIALS}}' > ./google-application-credentials.json
482-
chmod u+x ./assets/tools/utils/google-credentials-public-key.sh
483-
./assets/tools/utils/google-credentials-public-key.sh ./google-application-credentials.json ./assets/ssh_keys curry
484-
485-
- name: Prepare terraform variables
486-
run: |
487-
cat > ./env.variables.tfvars << EOF
488-
environment_prefix = "${{ matrix.environment_prefix }}"
489-
cardano_network = "${{ matrix.cardano_network }}"
490-
google_region = "${{ matrix.google_region }}"
491-
google_zone = "${{ matrix.google_zone }}"
492-
google_machine_type = "${{ matrix.google_machine_type }}"
493-
google_compute_instance_data_disk_size = "${{ matrix.google_compute_instance_data_disk_size }}"
494-
google_service_credentials_json_file = "./google-application-credentials.json"
495-
mithril_api_domain = "${{ matrix.mithril_api_domain }}"
496-
mithril_image_id = "${{ env.DOCKER_IMAGE_ID }}"
497-
mithril_genesis_verification_key_url = "${{ env.GENESIS_VERIFICATION_KEY_URL }}"
498-
mithril_genesis_secret_key = "${{ env.GENESIS_SECRET_KEY }}"
499-
mithril_protocol_parameters = ${{ matrix.mithril_protocol_parameters }}
500-
mithril_era_reader_adapter_type = "cardano-chain"
501-
mithril_era_reader_address_url = "${{ env.ERA_READER_ADDRESS_URL }}"
502-
mithril_era_reader_verification_key_url = "${{ env.ERA_READER_VERIFICATION_KEY_URL }}"
503-
mithril_era_reader_secret_key = "${{ env.ERA_READER_SECRET_KEY }}"
504-
mithril_signers = ${{ matrix.mithril_signers }}
505-
prometheus_auth_username = "${{ env.PROMETHEUS_AUTH_USERNAME }}"
506-
prometheus_auth_password = "${{ env.PROMETHEUS_AUTH_PASSWORD }}"
507-
prometheus_ingest_host = "${{ env.PROMETHEUS_INGEST_HOST }}"
508-
prometheus_ingest_username = "${{ env.PROMETHEUS_INGEST_USERNAME }}"
509-
prometheus_ingest_password = "${{ env.PROMETHEUS_INGEST_PASSWORD }}"
510-
loki_auth_username = "${{ env.LOKI_AUTH_USERNAME }}"
511-
loki_auth_password = "${{ env.LOKI_AUTH_PASSWORD }}"
512-
loki_ingest_host = "${{ env.LOKI_INGEST_HOST }}"
513-
loki_ingest_username = "${{ env.LOKI_INGEST_USERNAME }}"
514-
loki_ingest_password = "${{ env.LOKI_INGEST_PASSWORD }}"
515-
EOF
516-
terraform fmt ./env.variables.tfvars
517-
cat ./env.variables.tfvars
518-
519-
- name: Setup Terraform
520-
uses: hashicorp/setup-terraform@v2
521-
with:
522-
terraform_wrapper: false
523-
524-
- name: Init Terraform
525-
run: |
526-
GOOGLE_APPLICATION_CREDENTIALS=./google-application-credentials.json terraform init -backend-config="bucket=${{ matrix.terraform_backend_bucket }}" -backend-config="prefix=terraform/mithril-${{ matrix.environment }}"
527-
528-
- name: Check Terraform
529-
run: terraform fmt -check
530-
531-
- name: Terraform Plan
532-
run: |
533-
GOOGLE_APPLICATION_CREDENTIALS=./google-application-credentials.json terraform plan --var-file=./env.variables.tfvars
534-
535-
- name: Terraform Apply
536-
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
537-
run: |
538-
GOOGLE_APPLICATION_CREDENTIALS=./google-application-credentials.json terraform apply -auto-approve --var-file=./env.variables.tfvars
539-
540-
- name: Cleanup
541-
run: |
542-
rm -f ./env.variables.tfvars
543-
rm -f ./google-application-credentials.json
452+
- name: Get Docker image id
453+
run: echo "DOCKER_IMAGE_ID=${{ github.base_ref || github.ref_name }}-$(echo ${{ github.sha }} | cut -c1-7)" >> $GITHUB_ENV
454+
455+
- name: ${{ env.DEPLOY == 'true' && 'Apply' || 'Plan' }} terraform infrastructure
456+
uses: ./.github/workflows/actions/deploy-terraform-infrastructure
457+
env:
458+
DEPLOY: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
459+
with:
460+
dry_run: ${{ env.DEPLOY == 'true' && 'false' || 'true' }}
461+
terraform_backend_bucket: ${{ matrix.terraform_backend_bucket }}
462+
environment_prefix: ${{ matrix.environment_prefix }}
463+
environment: ${{ matrix.environment }}
464+
cardano_network: ${{ matrix.cardano_network }}
465+
google_region: ${{ matrix.google_region }}
466+
google_zone: ${{ matrix.google_zone }}
467+
google_machine_type: ${{ matrix.google_machine_type }}
468+
google_compute_instance_data_disk_size: ${{ matrix.google_compute_instance_data_disk_size }}
469+
google_application_credentials: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
470+
mithril_api_domain: ${{ matrix.mithril_api_domain }}
471+
mithril_image_id: ${{ env.DOCKER_IMAGE_ID }}
472+
mithril_protocol_parameters: ${{ toJSON(matrix.mithril_protocol_parameters) }}
473+
mithril_signers: ${{ toJSON(matrix.mithril_signers) }}
474+
mithril_genesis_secret_key: ${{ secrets.GENESIS_SECRET_KEY }}
475+
mithril_genesis_verification_key_url: ${{ vars.GENESIS_VERIFICATION_KEY_URL }}
476+
mithril_era_reader_address_url: ${{ vars.ERA_READER_ADDRESS_URL }}
477+
mithril_era_reader_verification_key_url: ${{ vars.ERA_READER_VERIFICATION_KEY_URL }}
478+
mithril_era_reader_secret_key: ${{ secrets.ERA_READER_SECRET_KEY }}
479+
prometheus_auth_username: ${{ secrets.PROMETHEUS_AUTH_USERNAME }}
480+
prometheus_auth_password: ${{ secrets.PROMETHEUS_AUTH_PASSWORD }}
481+
prometheus_ingest_host: ${{ vars.PROMETHEUS_INGEST_HOST }}
482+
prometheus_ingest_username: ${{ secrets.PROMETHEUS_INGEST_USERNAME }}
483+
prometheus_ingest_password: ${{ secrets.PROMETHEUS_INGEST_PASSWORD }}
484+
loki_auth_username: ${{ secrets.LOKI_AUTH_USERNAME }}
485+
loki_auth_password: ${{ secrets.LOKI_AUTH_PASSWORD }}
486+
loki_ingest_host: ${{ vars.LOKI_INGEST_HOST }}
487+
loki_ingest_username: ${{ secrets.LOKI_INGEST_USERNAME }}
488+
loki_ingest_password: ${{ secrets.LOKI_INGEST_PASSWORD }}

0 commit comments

Comments
 (0)