Skip to content

Commit

Permalink
Add workflow to deploy to prod (#12)
Browse files Browse the repository at this point in the history
* Adding workflow compiler to Github action (#5)
  • Loading branch information
0xLucca authored Nov 14, 2023
1 parent 48a5703 commit 355ab45
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 38 deletions.
70 changes: 70 additions & 0 deletions .github/workflows/build_compiler_be.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: "Build, push to ECR and deploy to EC2 instance"

on:
push:
branches:
- main
workflow_dispatch:

jobs:
build_and_push_to_ECR:
name: Build & push polkadot-wizard image to ECR.
runs-on: ubuntu-latest
env:
# Secrets
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
SSH_KEY: ${{ secrets.SSH_KEY }}

# Env variables
ACCOUNT_ID: 711012187398
REPOSITORY: 'polkadot-contract-wizard-compiler-be'
DEPLOYMENT_SERVER_IP: '3.139.60.27'

CONTAINER_BASE: "pkw"
DB_EXTERNAL_PORT: 27027
BACKEND_EXTERNAL_PORT: 8000
WEB_EXTERNAL_PORT: 3000
WEB_ENVIRONMENT: "production"
BRANCH: "develop"

steps:
- name: Check out Git repository
uses: actions/checkout@v3
with:
submodules: 'true'

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Build compiler-be docker-image
id: build-compiler-be-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
run: |
docker build -t ${{ env.REPOSITORY }}:$GITHUB_REF_NAME .
- name: Set tag and push compiler-be image to Amazon ECR
id: push-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
run: |
docker tag ${{ env.REPOSITORY }}:$GITHUB_REF_NAME $ECR_REGISTRY/${{ env.REPOSITORY }}:$GITHUB_REF_NAME
docker push $ECR_REGISTRY/${{ env.REPOSITORY }}:$GITHUB_REF_NAME
- name: Update Docker Compose Deployment
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
run: |
export IMAGE_URL=$ECR_REGISTRY/${{ env.REPOSITORY }}:$GITHUB_REF_NAME
echo "$SSH_KEY" | tr -d '\r' > key.pem && chmod 400 key.pem
ssh -o "StrictHostKeyChecking no" -i "key.pem" ubuntu@$DEPLOYMENT_SERVER_IP "export IMAGE_URL=$IMAGE_URL; sed -i '/COMPILER_BE_IMAGE/d' /home/ubuntu/polkadot-contract-wizard/.docker/dev.docker.env; echo COMPILER_BE_IMAGE=$IMAGE_URL >> /home/ubuntu/polkadot-contract-wizard/.docker/dev.docker.env; cd polkadot-contract-wizard/; docker-compose --env-file .docker/dev.docker.env down; sleep 5; docker-compose --env-file .docker/dev.docker.env up -d"
35 changes: 0 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,41 +271,6 @@ Response body example:
}
```

#### Get the deployment by Id
Returns the deployment by the Id provided when created.

``` http
GET /deployment?{id}
```

| Parameter | Type | Description |
| :-------- | :------- | :-------------------------------- |
| `id` | `string` | **Required**. The Id of the deployment. |

Request example:

```http
GET /deployments?id=652ee5587fbadc38e3b17bab
```

Response body example:

```json
{
"data": [
{
"id": "652ee5587fbadc38e3b17bab",
"contract_name": "Test Token",
"contract_address": "5Dsykc2KUHcziwcTgZkHxyDDTotBJbGNh3BakfZ5PdDGMzfn",
"network": "Rococo",
"code_id": "5a4ce58af5294a73b22b5c6bf1b1a8886972598925ddee77c3a591ced4bae78b",
"user_address": "ZA9WeQNb3QKmqvNi1szndDMchQ66npnDFXpjWuKayXQpriW"
}
],
"error": null
}
```

#### Get all contract deployments for a given user
Returns all the smart contract deployments for a given user, optionally filtered by network and contract address.

Expand Down
1 change: 0 additions & 1 deletion src/repository/mongodb_repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::env;
use crate::models::api_models::{GetDeploymentsMessage, UpdateDeployMessage};
use crate::models::db_models::{Contract, Deployment};
use crate::utils::common::string_to_object_id;

use mongodb::results::UpdateResult;
use mongodb::{
bson::doc,
Expand Down
1 change: 0 additions & 1 deletion src/tests/main_get_deployments_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ mod get_deployments_test {
let response = client.get(url).dispatch();

assert_eq!(response.status(), Status::Ok);

let original_json = r#"{"data":[{"_id":{"$oid":"OID_PLACEHOLDER"},"contract_name":null,"contract_address":"5CfkL1QXpnMoto87UYNER6B9dktRADjn1Vyrvzvc4ZziraFs","network":"some_network","code_id":"some_impossible_id","user_address":"5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY","tx_hash":null,"date":"2021-03-03T15:00:00.000Z","contract_type":"custom","external_abi":null,"hidden":false}],"error":null}"#;
let final_json = original_json.replace("OID_PLACEHOLDER", &deployment_id);
assert_eq!(response.into_string().unwrap(), final_json);
Expand Down
1 change: 0 additions & 1 deletion src/tests/main_post_contract_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ mod post_contract_test {
VALID_INK_SC
);
let response = client.post(uri!("/contract")).body(body).dispatch();

assert_eq!(response.status(), Status::Ok);

let json: ServerResponse<Contract> = response.into_json().unwrap();
Expand Down

0 comments on commit 355ab45

Please sign in to comment.