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

DEVOPS-903: devex-apollo gcp migration #170

Merged
merged 25 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5068620
feat: DEVOPS-903 devex-apollo gcp migration
pavlops Aug 11, 2023
ff0567c
feat: DEVOPS-903 devex-apollo gcp migration
pavlops Aug 11, 2023
660eb7a
feat: DEVOPS-903 devex-apollo gcp migration
pavlops Aug 14, 2023
fca96b6
feat: DEVOPS-903 devex-apollo gcp migration
pavlops Aug 14, 2023
3dbaa4d
feat: DEVOPS-903 devex-apollo gcp migration
pavlops Aug 14, 2023
d3b29ac
feat: DEVOPS-903 devex-apollo gcp migration
pavlops Aug 14, 2023
675fee0
feat: DEVOPS-903 devex-apollo gcp migration
pavlops Aug 14, 2023
2d10ee7
feat: DEVOPS-903 devex-apollo gcp migration
pavlops Aug 14, 2023
768af10
feat: DEVOPS-903 devex-apollo gcp migration
pavlops Aug 14, 2023
6d2079e
feat: DEVOPS-903 devex-apollo gcp migration
pavlops Aug 14, 2023
773a582
feat: DEVOPS-903 devex-apollo gcp migration
pavlops Aug 14, 2023
31c4920
feat: DEVOPS-903 devex-apollo gcp migration
pavlops Aug 16, 2023
0faf019
feat: DEVOPS-903 devex-apollo gcp migration
pavlops Aug 16, 2023
f537cee
devex-apollo local files
Aug 16, 2023
4cc0b0d
devex-apollo local files
Aug 16, 2023
d01f60a
devex-apollo local files
Aug 16, 2023
4439c06
feat: DEVOPS-903 devex-apollo gcp migration
pavlops Aug 16, 2023
8407d97
feat: DEVOPS-903 devex-apollo gcp migration
pavlops Aug 16, 2023
50e4beb
feat: DEVOPS-903 devex-apollo gcp migration
pavlops Aug 16, 2023
9f64ddc
feat: DEVOPS-903 devex-apollo gcp migration
pavlops Aug 16, 2023
c1333c3
feat: DEVOPS-903 devex-apollo gcp migration
pavlops Aug 16, 2023
df311c1
feat: DEVOPS-903 devex-apollo gcp migration
pavlops Aug 16, 2023
c569ec4
feat: DEVOPS-903 devex-apollo gcp migration
pavlops Aug 16, 2023
aebeeeb
feat: DEVOPS-903 devex-apollo gcp migration
pavlops Aug 16, 2023
bbe9863
feat: DEVOPS-903 devex-apollo gcp migration
pavlops Aug 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions .github/workflows/ci-on-merge-main-or-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,28 +118,6 @@ jobs:
python config/workspace-status.py | grep FULL_VERSION_TAG | awk '{print $2}' > VERSION
cat VERSION

- name: Configure AWS Credentials - staging
if: github.ref_name == env.DEFAULT_BRANCH && github.event_name != 'release'
uses: Zilliqa/gh-actions-workflows/actions/configure-aws-credentials@v1
with:
aws-region: us-west-2
role-to-assume: arn:aws:iam::816080630680:role/ecr-read-write
oidc-role: ${{ secrets.OIDC_ROLE }}

- name: Login to the registry - staging
if: github.ref_name == env.DEFAULT_BRANCH && github.event_name != 'release'
uses: docker/login-action@v2
with:
registry: 816080630680.dkr.ecr.us-west-2.amazonaws.com

- name: "Build and push devex-apollo - staging"
if: github.ref_name == env.DEFAULT_BRANCH && github.event_name != 'release' && steps.project-changed.outputs.devex-apollo == 'true'
run: |
VERSION=$(cat VERSION)
docker build -t devex-apollo:local products/devex-apollo
docker tag devex-apollo:local 816080630680.dkr.ecr.us-west-2.amazonaws.com/devex-apollo:$VERSION
docker push 816080630680.dkr.ecr.us-west-2.amazonaws.com/devex-apollo:$VERSION

- name: Configure AWS Credentials - production
if: github.event_name == 'release' && github.event.action == 'created'
uses: Zilliqa/gh-actions-workflows/actions/configure-aws-credentials@v1
Expand Down Expand Up @@ -190,11 +168,6 @@ jobs:
### BEGIN DEPLOYMENT STAGES
- name: "Create application.bzl"
run: |
echo 'APPLICATIONS_STAGING = [' > cd/applications.bzl
if [ "${{ contains(steps.changed-files.outputs.all_changed_and_modified_files, 'products/devex-apollo') }}" = "true" ]; then
echo ' "//products/devex-apollo",' >> cd/applications.bzl
fi
echo ']' >> cd/applications.bzl
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
Expand Down
17 changes: 11 additions & 6 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,28 @@ jobs:
strategy:
fail-fast: false
matrix:
application: [developer-portal, devex, neo-savant]
application: [developer-portal, devex, devex-apollo, neo-savant]
include:
- application: developer-portal
docker_domain: asia-docker.pkg.dev
registry_stg: asia-docker.pkg.dev/prj-d-devops-services-4dgwlsse/zilliqa-private
image_name: zilliqa-devportal
path: products/developer-portal
- application: devex
docker_domain: asia-docker.pkg.dev
registry_stg: asia-docker.pkg.dev/prj-d-devops-services-4dgwlsse/zilliqa-private
image_name: devex
path: products/devex
- application: devex-apollo
docker_domain: asia-docker.pkg.dev
registry_stg: asia-docker.pkg.dev/prj-d-devops-services-4dgwlsse/zilliqa-private
image_name: devex-apollo
path: products/devex-apollo
- application: neo-savant
docker_domain: asia-docker.pkg.dev
registry_stg: asia-docker.pkg.dev/prj-d-devops-services-4dgwlsse/zilliqa-private
image_name: neo-savant
path: products/neo-savant
- application: developer-portal
docker_domain: asia-docker.pkg.dev
registry_stg: asia-docker.pkg.dev/prj-d-devops-services-4dgwlsse/zilliqa-private
image_name: zilliqa-devportal
path: products/developer-portal
env:
DEFAULT_BRANCH: main
steps:
Expand Down
4 changes: 1 addition & 3 deletions cd/applications.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
This module contains the applications which are deployed upon merge into main and release tagging.
"""

APPLICATIONS_STAGING = [
"//products/devex-apollo",
]
APPLICATIONS_STAGING = []

APPLICATIONS_PROD = [
"//products/developer-portal",
Expand Down
3 changes: 3 additions & 0 deletions mlc_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@
},
{
"pattern": "^https://stg-indexer-api.rialto.studio/zilliqa"
},
{
"pattern": "^https://coq.inria.fr"
}
],
"replacementPatterns": [],
Expand Down
32 changes: 6 additions & 26 deletions products/devex-apollo/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,7 @@ load("//config:expand-workspace-status.bzl", "expand_workspace_status")

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

expand_workspace_status(
name = "staging-kustomization",
output = "products/devex-apollo/cd/overlays/staging/kustomization.yaml",
template = "products/devex-apollo/cd/overlays/staging/kustomization.tpl.yaml",
)

pkg_tar(
name = "cd_staging_patch",
srcs = glob(
["products/devex-apollo/cd/overlays/staging/*.yaml"],
exclude = ["products/devex-apollo/cd/overlays/staging/*.tpl.yaml"],
) + [
"products/devex-apollo/cd/overlays/staging/kustomization.yaml",
],
srcs = glob(["cd/base/*.yaml"]),
mode = "0755",
package_dir = "",
strip_prefix = ".",
Expand All @@ -35,17 +15,17 @@ pkg_tar(

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

pkg_tar(
name = "cd_production_patch",
srcs = glob(
["products/devex-apollo/cd/overlays/production/*.yaml"],
exclude = ["products/devex-apollo/cd/overlays/production/*.tpl.yaml"],
["cd/overlays/production/*.yaml"],
exclude = ["cd/overlays/production/*.tpl.yaml"],
) + [
"products/devex-apollo/cd/overlays/production/kustomization.yaml",
"cd/overlays/production/kustomization.yaml",
],
mode = "0755",
package_dir = "",
Expand Down
3 changes: 1 addition & 2 deletions products/devex-apollo/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ COPY ./yarn.lock ./
RUN yarn install && yarn cache clean

COPY . ./
RUN wget -q https://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pem
EXPOSE 5000
EXPOSE 80

CMD ["bash", "run.sh"]
20 changes: 20 additions & 0 deletions products/devex-apollo/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.PHONY: all
all: image/build-and-push

.ONESHELL:
SHELL := /bin/bash
.SHELLFLAGS = -ec

ENVIRONMENT ?= dev
VALID_ENVIRONMENTS := dev stg prd
IMAGE_TAG ?= localhost:5001/devex-apollo:latest

# Check if the ENVIRONMENT variable is in the list of valid environments
ifeq ($(filter $(ENVIRONMENT),$(VALID_ENVIRONMENTS)),)
$(error Invalid value for ENVIRONMENT. Valid values are dev, stg, or prd.)
endif

## Build and push the Docker image
image/build-and-push:
docker build -t "${IMAGE_TAG}" .
docker push "${IMAGE_TAG}"
140 changes: 140 additions & 0 deletions products/devex-apollo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,143 @@ With Devex Apollo,
- Extend [Devex](https://devex.zilliqa.com/?network=https%3A%2F%2Fapi.zilliqa.com) with historical transaction of an account or contracts
- Provide data for construction of smart contract call graph
- Data analytics for DApp

## Deploying applications with z

`z` is the one-stop shop for the Zilliqa provisioning and deployment operations. To deploy applications with z ensure the `z`
binary is installed in your operative system PATH environment variable. For more details about `z` please refer to the [documentation](https://github.com/Zilliqa/devops/blob/main/docs/z2.md).

## Deploying applications to localdev

To deploy the localdev/development environment go to the project folder in the zilliqa-developer repository:

```sh
cd ./products/devex-apollo
```

The `./products/devex-apollo/z.yaml` contains all the relevant configurations for the development environment.
Now set the following environment variables to reference the project's `z.yaml` file:

- `Z_ENV` to the path in which your `z.yaml` resides.
- `ZQ_USER` to your username (the bit before `@` in your email address)

for example:

```sh
export Z_ENV=z.yaml
export ZQ_USER=<user_id>@zilliqa.com
```

Create the local kind cluster (if not created previously):

```sh
z local create
```

Execute the manifests (in this case for ensuring the installation of the ingress-nginx controller, required for localdev/development environments):

```sh
z k-apply
```

Build and push the image:

```sh
make image/build-and-push
```

And deploy the application to your local cluster with:

```sh
z app sync
```

Verify your application is running correct from the `http://localhost` URL and with `kubectl` commands (if required).

## Deploying applications to staging

To deploy the staging 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/non-production/prj-d-staging/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 staging `z.yaml` file. Skip this step if it is an existing application

1. Create a branch:

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

2. In the file `infra/live/gcp/non-production/prj-d-staging/z_ase1.yaml` add the following:

- in `apps` stanza add:

```yaml
clusters:
staging:
apps:
devex:
repo: https://github.com/Zilliqa/zilliqa-developer
path: products/devex-apollo/cd/overlays/staging
track: staging
type: kustomize
```

- in `subdomains` stanza add:

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

3. Push the changes

```sh
git add .
git commit -m "Add Devex Apollo to staging cluster"
git push origin users/<username>/add_devex_apollo_to_staging_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-apollo
```

Verify your application is running correct from the staging URL and with `kubectl` commands (if required).
9 changes: 9 additions & 0 deletions products/devex-apollo/cd/base/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: devex-apollo
data:
BLOCKS_PER_REQUEST: "50"
FAST_SYNC: "false"
NETWORK_URL: "https://dev-api.zilliqa.com/"
NODE_ENV: "dev"
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: devex-apollo
namespace: default
namespace: devex-apollo
labels:
"app.kubernetes.io/name": "devex-apollo"
app.kubernetes.io/name: devex-apollo
spec:
replicas: 1
selector:
matchLabels:
"app.kubernetes.io/name": "devex-apollo"
app.kubernetes.io/name: devex-apollo
strategy:
type: RollingUpdate
template:
metadata:
labels:
"app.kubernetes.io/name": "devex-apollo"
app.kubernetes.io/name: devex-apollo
spec:
containers:
- image: devex-apollo:latest
- image: devex-apollo
name: devex-apollo
ports:
- containerPort: 5000
- containerPort: 80
env:
- name: BLOCKS_PER_REQUEST
valueFrom:
Expand All @@ -35,6 +35,11 @@ spec:
key: DOCUMENTDB_HOST
- name: DOCUMENTDB_PORT
value: "27017"
- name: DOCUMENTDB_DB
valueFrom:
secretKeyRef:
name: devex-apollo
key: DOCUMENTDB_DB
- name: DOCUMENTDB_USER
valueFrom:
secretKeyRef:
Expand Down
Loading
Loading