(prod) Manual build & deploy #14
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: (prod) Manual build & deploy | |
on: | |
workflow_dispatch: | |
inputs: | |
version: | |
description: 'Version tag' | |
required: true | |
type: string | |
permissions: | |
id-token: write | |
contents: read | |
env: | |
NODE_VERSION: '20.x' | |
REGISTRY: "599564732950.dkr.ecr.us-east-2.amazonaws.com" | |
REPOSITORY: "starknet-remix-plugin" | |
CLUSTER: "starknet-remix-plugin-ecs-cluster" | |
SERVICE_NAME: "rocket-development-svc" | |
PROD_BUCKET_NAME: 'starknet-remix-plugin-prod-web' | |
PROD_CLUSTER: "starknet-remix-plugin-production-ecs-cluster" | |
PROD_SERVICE_NAME: "rocket-production-svc" | |
API_SERVICE_URL: "https://cairo-remix-api.nethermind.io" | |
STARKNET_DEVNET_URL: "https://starknet-remix-devnet.nethermind.io" | |
jobs: | |
BuildAPI: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Clone repository | |
uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 | |
- name: Apply release tag | |
uses: rickstaa/action-create-tag@v1 | |
with: | |
tag: ${{ inputs.version }} | |
tag_exists_error: false | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-region: us-east-2 | |
role-to-assume: arn:aws:iam::599564732950:role/Aws-GH-Action-Assume-Role-Starknet | |
role-session-name: GHStarknet | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v1 | |
with: | |
mask-password: 'true' | |
# - name: Update local Rust toolchain | |
# run: | | |
# curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain stable -y | |
# rustup update | |
# rustup component add clippy | |
# rustup install nightly | |
# - name: Toolchain info | |
# run: | | |
# cargo --version --verbose | |
# rustc --version | |
# cargo clippy --version | |
# - name: Build | |
# run: | | |
# cd api | |
# cargo build | |
# ls ./target/debug/ -al | |
- name: Build, tag, and push docker image to Amazon ECR | |
env: | |
REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
REPOSITORY: ${{ env.REPOSITORY }} | |
IMAGE_TAG: ${{ inputs.version }} | |
run: | | |
docker build -t $REGISTRY/$REPOSITORY:apiserver-$IMAGE_TAG -f ./DockerfileRocket . | |
docker push $REGISTRY/$REPOSITORY:apiserver-$IMAGE_TAG | |
outputs: | |
image-version: ${{ inputs.version }} | |
BuildReact: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Clone repository | |
uses: actions/checkout@v2 | |
- name: Inject version | |
env: | |
VERSION: ${{inputs.version}} | |
run: | | |
export STRIPPED_VERSION=${VERSION/v/} | |
sed -i "s/\"version\"\:[ ]\"[0-9].[0-9]*.[0-9]*\"/\"version\": \"$STRIPPED_VERSION\"/g" ./plugin/package.json | |
- name: Setup Node ${{ env.NODE_VERSION }} Environment | |
uses: actions/setup-node@v1 | |
with: | |
node-version: ${{ env.NODE_VERSION }} | |
- name: Install dependencies | |
run: npm install -g pnpm | |
- name: pnpm install | |
working-directory: ./plugin | |
run: pnpm install | |
- name: pnpm build | |
working-directory: ./plugin | |
run: pnpm run build | |
- name: 'Upload Artifact' | |
uses: actions/upload-artifact@v3 | |
with: | |
name: react-github-actions-build | |
path: ./plugin/build/**/* | |
DeployAPI_Prod: | |
runs-on: ubuntu-latest | |
needs: [BuildReact, BuildAPI] | |
steps: | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-region: us-east-2 | |
role-to-assume: arn:aws:iam::228016254426:role/Aws-GH-Action-Assume-Role-Starknet-Production | |
role-session-name: GHStarknet | |
- name: Download task definition | |
run: | | |
aws ecs describe-task-definition --task-definition starknet-remix-production-rocket --query taskDefinition > task-definition.json | |
- name: Fill in the new image ID in the Amazon ECS task definition | |
id: task-def | |
uses: aws-actions/amazon-ecs-render-task-definition@v1 | |
with: | |
task-definition: task-definition.json | |
container-name: "rocket" | |
image: ${{ env.REGISTRY }}/${{ env.REPOSITORY }}:apiserver-${{ needs.BuildAPI.outputs.image-version }} #${{ github.run_number }} | |
# inject the expected React package URL for CORS logic | |
environment-variables: | | |
RUST_LOG=INFO | |
VITE_URL=https://cairo-remix.nethermind.io | |
PROMTAIL_USERNAME=${{secrets.PROMTAIL_USERNAME}} | |
PROMTAIL_PASSWORD=${{secrets.PROMTAIL_PASSWORD}} | |
- name: Deploy Amazon ECS task definition | |
uses: aws-actions/amazon-ecs-deploy-task-definition@v1 | |
with: | |
task-definition: ${{ steps.task-def.outputs.task-definition }} | |
service: ${{ env.PROD_SERVICE_NAME }} | |
cluster: ${{ env.PROD_CLUSTER }} | |
wait-for-service-stability: true | |
DeployReact_Prod: | |
runs-on: ubuntu-latest | |
needs: [BuildReact, BuildAPI] | |
steps: | |
- name: Get artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: react-github-actions-build | |
path: artifact | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-region: us-east-2 | |
role-to-assume: arn:aws:iam::228016254426:role/Aws-GH-Action-Assume-Role-Starknet-Production | |
role-session-name: GHStarknet | |
- name: Deploy to S3 | |
run: | | |
aws s3 sync . s3://${{ env.PROD_BUCKET_NAME }} --acl public-read | |
working-directory: artifact | |