Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add protected automated deployment to environments #1382

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
53 changes: 53 additions & 0 deletions .github/workflows/deploy-env.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Deploy Environment

on:
push:
workflow_dispatch:
inputs:
environment:
description: 'Environment to deploy to'
type: choice
required: true
default: 'ops-preview-1'
options:
- ALL
- LIVE
michalrus marked this conversation as resolved.
Show resolved Hide resolved
- live-sanchonet@eu-central-1@v2
- DEV
- live-mainnet@eu-central-1@v2
- live-sanchonet@us-east-2@v1
- dev-mainnet@us-east-1
- live-mainnet@us-east-2@v2
- live-sanchonet@us-east-2@v2
- dev-preprod@us-east-1@v2
- live-preprod@eu-central-1@v2
- OPS
- dev-preview@us-east-1
- live-preprod@us-east-2@v2
- ops-preprod-1@us-east-1
- dev-sanchonet@us-east-1@v1
- live-preview@eu-central-1@v2
- ops-preview-1@us-east-1
- dev-sanchonet@us-east-1@v2
- live-preview@us-east-2@v2
- staging-preprod@us-east-1@v2

jobs:
deploy:
environment: ${{ inputs.environment || 'ops-preview-1@us-east-1' }}
runs-on: ubuntu-latest
steps:
- name: 📥 Checkout repository
uses: actions/checkout@v3

- name: 🧰 Setup Nix
uses: cachix/install-nix-action@v21

- name: 🚀 Deploy
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, but don't we have to build the images first? 🤔 Or at least make sure they're built and pushed to ECR?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about it, it should not have push at the top and then it should be fine. We may encounter a race condition once in a while but that's probably not going to be even noticable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I plan to take out push: once the PR is tested and cleared for merging.

Ref: #1382 (comment)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, thanks. I remember I added a check in dapp-store once, to prevent such a race condition, but they use Git commits to tag images.

run: |
echo "${{ secrets.ENVRC }}" > .envrc.local
source .envrc.local
michalrus marked this conversation as resolved.
Show resolved Hide resolved
nix develop -L --command bash -c "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works by accident, but not the way you think (I think ^^).

It should be a single quote here, because on L52 you close this double quote right before yes, and reopen it right after. Single quotes, OTOH, will pass everything to the bash running inside the devshell.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. The purpose of using the double quotes here is to test the CI which initially failed on the single quotes due to setting a single-quoted default value for the environment variable here: ${{ inputs.environment || 'ops-preview-1@us-east-1' }}. Updated now for final reviews.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P.S: Escaping (\) the single quotes did not help.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, but ${{ inputs.environment || 'ops-preview-1@us-east-1' }} is evaluated as a very first step, it's GitHub's YAML templating. So these single quotes have nothing to do with Bash, or?

set -euo pipefail
echo "yes" | nix run .#cardano-services.${{ inputs.environment || 'ops-preview-1@us-east-1' }}.apply
"
2 changes: 1 addition & 1 deletion nix/cardano-services/deployments/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ in
name = "${final.namespace}-cardanojs";
chart = ./Chart.yaml;
context = "eks-devs";
kubeconfig = "$PRJ_ROOT/.kube/${final.region}";
kubeconfig = ./../../local/kubeconfig + "/${final.region}";

utils = {
mkPodEnv = lib.mapAttrsToList (
Expand Down
Loading