Skip to content

Commit

Permalink
feat: DEVOPS-957 move Devex to GCP (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
frankmeds authored Sep 14, 2023
1 parent 9f62d7d commit 99e7aaf
Show file tree
Hide file tree
Showing 12 changed files with 149 additions and 72 deletions.
11 changes: 0 additions & 11 deletions .github/workflows/ci-on-merge-main-or-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ jobs:
if [ "${{ contains(steps.changed-files.outputs.all_changed_and_modified_files, 'products/developer-portal') }}" = "true" || "${{ contains(steps.changed-files.outputs.all_changed_and_modified_files, 'docs') }}" = "true" ]; then
echo "developer-portal=true" >> $GITHUB_OUTPUT
fi
if [ "${{ contains(steps.changed-files.outputs.all_changed_and_modified_files, 'products/devex') }}" = "true" ]; then
echo "devex=true" >> $GITHUB_OUTPUT
fi
if [ "${{ contains(steps.changed-files.outputs.all_changed_and_modified_files, 'products/devex-apollo') }}" = "true" ]; then
echo "devex-apollo=true" >> $GITHUB_OUTPUT
fi
Expand Down Expand Up @@ -142,21 +139,13 @@ jobs:
run: |
bazelisk run --test_output=all --keep_going //products/developer-portal:push_image_production
- name: "Build and push Docker - devex - production"
if: github.event_name == 'release' && github.event.action == 'created' && steps.project-changed.outputs.devex == 'true'
run: |
bazelisk run --test_output=all --keep_going //products/devex:push_image_prd
### BEGIN DEPLOYMENT STAGES
- name: "Create application.bzl"
run: |
echo 'APPLICATIONS_PROD = [' > cd/applications.bzl
if [ "${{ contains(steps.changed-files.outputs.all_changed_and_modified_files, 'products/developer-portal') }}" = "true" || "${{ contains(steps.changed-files.outputs.all_changed_and_modified_files, 'docs') }}" = "true" ]; then
echo ' "//products/developer-portal",' >> cd/applications.bzl
fi
if [ "${{ contains(steps.changed-files.outputs.all_changed_and_modified_files, 'products/devex') }}" = "true" ]; then
echo ' "//products/devex",' >> cd/applications.bzl
fi
if [ "${{ contains(steps.changed-files.outputs.all_changed_and_modified_files, 'products/devex-apollo') }}" = "true" ]; then
echo ' "//products/devex-apollo",' >> cd/applications.bzl
fi
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/cicd-prd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ jobs:
strategy:
fail-fast: false
matrix:
application: [bluebell-playground, eth-spout, neo-savant]
application: [bluebell-playground, devex, eth-spout, neo-savant]
include:
- application: bluebell-playground
image_name: bluebell-playground
path: products/bluebell
- application: devex
image_name: devex
path: products/devex
- application: eth-spout
image_name: eth-spout
path: products/eth-spout
Expand Down
1 change: 0 additions & 1 deletion cd/applications.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ APPLICATIONS_STAGING = []

APPLICATIONS_PROD = [
"//products/developer-portal",
"//products/devex",
"//products/devex-apollo",
]
36 changes: 3 additions & 33 deletions products/devex/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_to_bin")
load("@io_bazel_rules_docker//container:container.bzl", "container_image", "container_push")
load("@npm//:react-app-rewired/package_json.bzl", cra_bin = "bin")
load("@rules_pkg//:pkg.bzl", "pkg_tar")
load("//config:expand-workspace-status.bzl", "expand_workspace_status")

# Filename conventions described at
# https://create-react-app.dev/docs/running-tests#filename-conventions
Expand Down Expand Up @@ -186,38 +185,9 @@ container_push(
name = "push_image_prd",
format = "Docker",
image = ":image",
registry = "298213327629.dkr.ecr.us-west-2.amazonaws.com",
repository = "developer-explorer",

# Tagging from workspace status - requires --stamp as build args
tag = "{FULL_VERSION_TAG}",
)

###
# CD update

pkg_tar(
name = "cd_base",
srcs = glob(["cd/base/*.yaml"]),
mode = "0755",
package_dir = "",
strip_prefix = ".",
visibility = ["//visibility:public"],
)

expand_workspace_status(
name = "production-kustomization",
output = "cd/overlays/production/kustomization.yaml",
template = "cd/overlays/production/kustomization.tpl.yaml",
)

pkg_tar(
name = "cd_production_patch",
srcs = ["cd/overlays/production/kustomization.yaml"],
mode = "0755",
package_dir = "",
strip_prefix = ".",
visibility = ["//visibility:public"],
registry = "asia-docker.pkg.dev/prj-p-devops-services-tvwmrf63/zilliqa-public",
repository = "devex",
tag = "$${IMAGE_TAG#*:}",
)

cra_bin.react_app_rewired_binary(
Expand Down
88 changes: 88 additions & 0 deletions products/devex/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,91 @@ z app sync --cache-dir=.cache devex
```

Verify your application is running correct from the staging URL and with `kubectl` commands (if required).

## Deploying applications to production

To deploy the production environment we need to clone the devops repository and execute `z` from there:

```sh
git clone https://github.com/Zilliqa/devops.git
cd devops
source setenv
```

### Set the following environment variables

- `Z_ENV` to the path in which your `z.yaml` resides.
- `ZQ_USER` to your username (the bit before `@` in your email address)
- `GITHUB_PAT` (if you are deploying staging or production apps) to a classic PAT with all the repo permissions ticked.

for example:

```sh
export Z_ENV=`pwd`/infra/live/gcp/production/prj-p-prod-apps/z_ase1.yaml
export ZQ_USER=<user_id>@zilliqa.com
export GITHUB_PAT=<GITHUB_PAT>
```

### Login to Google Cloud

```sh
z login
```

### Add the application to the production `z.yaml` file. Skip this step if it is an existing application

1. Create a branch:

```sh
git checkout -b users/<username>/add_devex_to_production_cluster
```

2. In the file `infra/live/gcp/production/prj-p-prod-apps/z_ase1.yaml` add the following:

- in `apps` stanza add:

```yaml
clusters:
production:
apps:
devex:
repo: https://github.com/Zilliqa/zilliqa-developer
path: products/devex/cd/overlays/production
track: production
type: kustomize
```
- in `subdomains` stanza add:

```yaml
infrastructure:
dns:
vars:
subdomains:
devex: {}
```

3. Push the changes

```sh
git add .
git commit -m "Add Devex to production cluster"
git push origin users/<username>/add_devex_to_production_cluster
```

4. Open a Pull Request to the main branch

5. Apply the changes

```sh
z plan
z apply
```

### Deploy the application

```sh
z app sync --cache-dir=.cache devex
```

Verify your application is running correct from the production URL and with `kubectl` commands (if required).
2 changes: 1 addition & 1 deletion products/devex/cd/base/ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ spec:
name: devex
port:
number: 80
- host: dev-devex.zilliqa.com
- host: devex.zilliqa.com
http:
paths:
- path: /
Expand Down
7 changes: 7 additions & 0 deletions products/devex/cd/overlays/production/certificate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: networking.gke.io/v1
kind: ManagedCertificate
metadata:
name: devex
spec:
domains:
- devex.zilliqa.com
8 changes: 8 additions & 0 deletions products/devex/cd/overlays/production/frontend-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: networking.gke.io/v1beta1
kind: FrontendConfig
metadata:
name: devex
spec:
redirectToHttps:
enabled: true
responseCodeName: RESPONSE_CODE
24 changes: 0 additions & 24 deletions products/devex/cd/overlays/production/kustomization.tpl.yaml

This file was deleted.

27 changes: 27 additions & 0 deletions products/devex/cd/overlays/production/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- ../../base
- certificate.yaml
- frontend-config.yaml

patches:
- target:
kind: Ingress
name: devex
patch: |-
- op: replace
path: "/spec/rules/0/host"
value: devex.zilliqa.com
- op: remove
path: "/spec/rules/1"
- op: replace
path: /metadata/annotations
value:
kubernetes.io/ingress.class: gce
kubernetes.io/ingress.global-static-ip-name: devex-zilliqa-com
networking.gke.io/managed-certificates: devex
networking.gke.io/v1beta1.FrontendConfig: devex
namespace: devex-prd
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: networking.gke.io/v1beta1
kind: FrontendConfig
metadata:
name: neo-savant-ide
spec:
redirectToHttps:
enabled: true
responseCodeName: RESPONSE_CODE
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ kind: Kustomization
resources:
- ../../base
- certificate.yaml
- frontend-config.yaml

patches:
- target:
Expand All @@ -18,8 +19,9 @@ patches:
- op: replace
path: /metadata/annotations
value:
kubernetes.io/ingress.class: gce
kubernetes.io/ingress.global-static-ip-name: ide-zilliqa-com
networking.gke.io/managed-certificates: neo-savant-ide
kubernetes.io/ingress.class: gce
networking.gke.io/v1beta1.FrontendConfig: neo-savant-ide
namespace: neo-savant-ide-prd

0 comments on commit 99e7aaf

Please sign in to comment.