Skip to content

Commit

Permalink
First commit for CI/CD
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien CAFFET committed May 27, 2024
1 parent 26d277f commit a8e1ff7
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 0 deletions.
89 changes: 89 additions & 0 deletions .github/workflows/deploy-faucet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Faucet deployment

on:
push:
branches:
- dev
- prod

permissions:
id-token: write
contents: read

env:
PRODUCT: nuklaivm
COMPONENT: backend
APPLICATION: faucet
API_PORT: 10591
AWS_REGION: eu-west-1
BUILD_FOLDER: build


jobs:
build_and_deploy:
runs-on: ubuntu-latest
environment: ${{ github.ref == 'refs/heads/prod' && 'prod' || github.ref == 'refs/heads/dev' && 'dev' || 'dev' }}

steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5

- name: Set dev ENV
if: github.ref == 'refs/heads/dev'
run: |
echo "ENV=dev" >> $GITHUB_ENV
echo "AWS_ACCOUNT_ID=722484512985" >> $GITHUB_ENV
- name: Set prod ENV
if: github.ref == 'refs/heads/prod'
run: |
echo "ENV=prod" >> $GITHUB_ENV
echo "AWS_ACCOUNT_ID=146563424647" >> $GITHUB_ENV
- name: Upgrade deployment files with environment information
uses: cschleiden/replace-tokens@v1
with:
tokenPrefix: '${'
tokenSuffix: '}'
files: '["infra/aws/*.json"]'
env:
AWS_ACCOUNT_ID: ${{ env.AWS_ACCOUNT_ID }}
AWS_REGION: ${{ env.AWS_REGION }}

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::${{ env.AWS_ACCOUNT_ID }}:role/${{ env.PRODUCT }}-${{ env.COMPONENT }}-deployer-${{ env.AWS_REGION }}-${{ env.ENV }}
aws-region: ${{ env.AWS_REGION }}

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

- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ env.AWS_ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com
ECR_REPOSITORY: ${{ env.PRODUCT }}-${{ env.COMPONENT }}-${{ env.APPLICATION }}-${{ env.ENV }}
IMAGE_TAG: ${{ github.sha }}
run: |
docker build -f Dockerfile -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
- 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: infra/aws/task-definition-${{ env.COMPONENT }}-${{ env.APPLICATION }}.json
container-name: ${{ env.APPLICATION }}
image: ${{ steps.build-image.outputs.image }}

- 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.APPLICATION }}
cluster: ${{ env.PRODUCT }}-${{ env.COMPONENT }}-${{ env.ENV }}
wait-for-service-stability: true
17 changes: 17 additions & 0 deletions infra/aws/appspec-backend-faucet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"version": 0.0,
"Resources": [
{
"TargetService": {
"Type": "AWS::ECS::Service",
"Properties": {
"TaskDefinition": "arn:aws:ecs:${AWS_DEFAULT_REGION}:${AWS_ACCOUNT_ID}:task-definition/${PRODUCT}-${PLATFORM}-${COMPONENT}-${APPLICATION}-${ENV}",
"LoadBalancerInfo": {
"ContainerName": "${APPLICATION}",
"ContainerPort": "${API_PORT}"
}
}
}
}
]
}
64 changes: 64 additions & 0 deletions infra/aws/task-definition-backend-faucet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"cpu": "256",
"memory": "2048",
"volumes": [],
"networkMode": "awsvpc",
"family": "${PRODUCT}-${COMPONENT}-${APPLICATION}-${ENV}",
"requiresCompatibilities": ["FARGATE"],
"placementConstraints": [],
"executionRoleArn": "arn:aws:iam::${AWS_ACCOUNT_ID}:role/${PRODUCT}-${COMPONENT}-${APPLICATION}-ecs-taskexec-${AWS_REGION}-${ENV}",
"taskRoleArn": "arn:aws:iam::${AWS_ACCOUNT_ID}:role/${PRODUCT}-${COMPONENT}-${APPLICATION}-ecs-task-${AWS_REGION}-${ENV}",
"containerDefinitions": [
{
"name": "${APPLICATION}",
"cpu": 256,
"memory": 2048,
"linuxParameters": {
"initProcessEnabled": true
},
"essential": true,
"volumesFrom": [],
"mountPoints": [],
"image": "",
"portMappings": [
{
"protocol": "tcp",
"containerPort": "${API_PORT}",
"hostPort": "${API_PORT}"
}
],
"environment": [
{
"name": "AWS_REGION",
"value": "${AWS_REGION}"
},
{
"name": "ENV",
"value": "${ENV}"
}
],
"secrets": [
{
"name": "NUKLAI_RPC",
"valueFrom": "arn:aws:ssm:${AWS_REGION}:${AWS_ACCOUNT_ID}:parameter/${ENV}/${PRODUCT}/${COMPONENT}/rpc_node_url_nuklai"
},
{
"name": "PRIVATE_KEY_BYTES",
"valueFrom": "arn:aws:ssm:${AWS_REGION}:${AWS_ACCOUNT_ID}:parameter/${ENV}/${PRODUCT}/${COMPONENT}/faucet/private_key_bytes"
},
{
"name": "ADMIN_TOKEN",
"valueFrom": "arn:aws:ssm:${AWS_REGION}:${AWS_ACCOUNT_ID}:parameter/${ENV}/${PRODUCT}/${COMPONENT}/faucet/admin_token"
}
],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/fargate/service/${PRODUCT}-${COMPONENT}-${APPLICATION}-${ENV}",
"awslogs-region": "${AWS_REGION}",
"awslogs-stream-prefix": "ecs"
}
}
}
]
}
8 changes: 8 additions & 0 deletions infra/scripts/startup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
APP_DIR="/app"

echo "NUKLAI_RPC="$NUKLAI_RPC"" >> ${APP_DIR}/.env
echo "PRIVATE_KEY_BYTES="$PRIVATE_KEY_BYTES"" >> ${APP_DIR}/.env
echo "ADMIN_TOKEN="$ADMIN_TOKEN"" >> ${APP_DIR}/.env

echo "${@}" | xargs -I % sh -c '%'

0 comments on commit a8e1ff7

Please sign in to comment.