Skip to content

Commit

Permalink
feat: DEVOPS-958 migrate Developer Portal prod to GCP (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
frankmeds authored Sep 14, 2023
1 parent 99e7aaf commit 3a9d9af
Show file tree
Hide file tree
Showing 16 changed files with 167 additions and 102 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 @@ -60,9 +60,6 @@ jobs:
- name: "Analyse project changes"
id: project-changed
run: |
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-apollo') }}" = "true" ]; then
echo "devex-apollo=true" >> $GITHUB_OUTPUT
fi
Expand Down Expand Up @@ -134,18 +131,10 @@ jobs:
docker tag devex-apollo:local 298213327629.dkr.ecr.us-west-2.amazonaws.com/devex-apollo:$VERSION
docker push 298213327629.dkr.ecr.us-west-2.amazonaws.com/devex-apollo:$VERSION
- name: "Build and push Docker - developer-portal - production"
if: github.event_name == 'release' && github.event.action == 'created' && steps.project-changed.outputs.developer-portal == 'true'
run: |
bazelisk run --test_output=all --keep_going //products/developer-portal:push_image_production
### 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-apollo') }}" = "true" ]; then
echo ' "//products/devex-apollo",' >> cd/applications.bzl
fi
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/cicd-prd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@ jobs:
strategy:
fail-fast: false
matrix:
application: [bluebell-playground, devex, eth-spout, neo-savant]
application:
[bluebell-playground, developer-portal, 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: developer-portal
image_name: developer-portal
path: products/developer-portal
- application: eth-spout
image_name: eth-spout
path: products/eth-spout
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cicd-stg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
application: [developer-portal, devex, devex-apollo, neo-savant]
include:
- application: developer-portal
image_name: zilliqa-devportal
image_name: developer-portal
path: products/developer-portal
- application: devex
image_name: devex
Expand Down
1 change: 0 additions & 1 deletion cd/applications.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ This module contains the applications which are deployed upon merge into main an
APPLICATIONS_STAGING = []

APPLICATIONS_PROD = [
"//products/developer-portal",
"//products/devex-apollo",
]
42 changes: 6 additions & 36 deletions products/developer-portal/BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
load("@io_bazel_rules_docker//container:container.bzl", "container_image", "container_push")
load("@rules_pkg//:pkg.bzl", "pkg_tar")
load("//config:expand-workspace-status.bzl", "expand_workspace_status")
load(":defs.bzl", "mkdocs_html")

# TODO:
Expand Down Expand Up @@ -126,7 +125,7 @@ container_push(
format = "Docker",
image = ":image",
registry = "localhost:5001",
repository = "zilliqa-devportal",
repository = "developer-portal",
tag = "latest",
)

Expand All @@ -135,44 +134,15 @@ container_push(
format = "Docker",
image = ":image",
registry = "asia-docker.pkg.dev/prj-d-devops-services-4dgwlsse/zilliqa-public",
repository = "zilliqa-devportal",
repository = "developer-portal",
tag = "$${IMAGE_TAG#*:}",
)

container_push(
name = "push_image_production",
name = "push_image_prd",
format = "Docker",
image = ":image",
registry = "298213327629.dkr.ecr.us-west-2.amazonaws.com",
repository = "zilliqa-devportal",

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

###
# CD update

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

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

pkg_tar(
name = "cd_production_patch",
srcs = ["products/devportal/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 = "developer-portal",
tag = "$${IMAGE_TAG#*:}",
)
90 changes: 89 additions & 1 deletion products/developer-portal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ z login
dns:
vars:
subdomains:
zilliqa-devportal: {}
developer-portal: {}
```

3. Push the changes
Expand All @@ -139,3 +139,91 @@ z app sync --cache-dir=.cache developer-portal
```

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_developer_portal_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:
developer-portal:
repo: https://github.com/Zilliqa/zilliqa-developer
path: products/developer-portal/cd/overlays/production
track: production
type: kustomize
```
- in `subdomains` stanza add:

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

3. Push the changes

```sh
git add .
git commit -m "Add Developer Portal to production cluster"
git push origin users/<username>/add_developer_portal_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 developer-portal
```

Verify your application is running correct from the production URL and with `kubectl` commands (if required).
14 changes: 7 additions & 7 deletions products/developer-portal/cd/base/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: zilliqa-devportal
namespace: devportal
name: developer-portal
namespace: developer-portal
labels:
"app.kubernetes.io/name": "zilliqa-devportal"
app.kubernetes.io/name: "developer-portal"
spec:
replicas: 1
selector:
matchLabels:
"app.kubernetes.io/name": "zilliqa-devportal"
app.kubernetes.io/name: "developer-portal"
strategy:
type: RollingUpdate
template:
metadata:
labels:
"app.kubernetes.io/name": "zilliqa-devportal"
app.kubernetes.io/name: "developer-portal"
spec:
containers:
- image: zilliqa-devportal
name: zilliqa-devportal
- image: developer-portal
name: developer-portal
ports:
- containerPort: 80
10 changes: 5 additions & 5 deletions products/developer-portal/cd/base/ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: zilliqa-devportal
namespace: devportal
name: developer-portal
namespace: developer-portal
labels:
"app.kubernetes.io/name": "zilliqa-devportal"
app.kubernetes.io/name: "developer-portal"
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
Expand All @@ -16,7 +16,7 @@ spec:
pathType: Prefix
backend:
service:
name: zilliqa-devportal
name: developer-portal
port:
number: 80
- host: dev.zilliqa.com
Expand All @@ -26,6 +26,6 @@ spec:
pathType: Prefix
backend:
service:
name: zilliqa-devportal
name: developer-portal
port:
number: 80
2 changes: 1 addition & 1 deletion products/developer-portal/cd/base/namespace.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: devportal
name: developer-portal
8 changes: 4 additions & 4 deletions products/developer-portal/cd/base/svc.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
apiVersion: v1
kind: Service
metadata:
name: zilliqa-devportal
namespace: devportal
name: developer-portal
namespace: developer-portal
labels:
"app.kubernetes.io/name": "zilliqa-devportal"
app.kubernetes.io/name: "developer-portal"
spec:
type: ClusterIP
ports:
Expand All @@ -13,4 +13,4 @@ spec:
protocol: TCP
name: http
selector:
"app.kubernetes.io/name": "zilliqa-devportal"
app.kubernetes.io/name: "developer-portal"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: networking.gke.io/v1
kind: ManagedCertificate
metadata:
name: developer-portal
spec:
domains:
- dev.zilliqa.com
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: networking.gke.io/v1beta1
kind: FrontendConfig
metadata:
name: developer-portal
spec:
redirectToHttps:
enabled: true
responseCodeName: RESPONSE_CODE

This file was deleted.

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: developer-portal
patch: |-
- op: replace
path: "/spec/rules/0/host"
value: dev.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: dev-zilliqa-com
networking.gke.io/managed-certificates: developer-portal
networking.gke.io/v1beta1.FrontendConfig: developer-portal
namespace: developer-portal-prd
Loading

0 comments on commit 3a9d9af

Please sign in to comment.