Skip to content

Merge pull request #59 from OpenConceptLab/OpenConceptLab/ocl_online#… #720

Merge pull request #59 from OpenConceptLab/OpenConceptLab/ocl_online#…

Merge pull request #59 from OpenConceptLab/OpenConceptLab/ocl_online#… #720

Workflow file for this run

name: Build
on:
push:
branches: [ "main" ]
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
env:
AWS_REGION: "us-east-2" # set this to your preferred AWS region, e.g. us-west-1
ECR_REPOSITORY: "oclweb3" # set this to your Amazon ECR repository name
ECS_SERVICE_QA: "qa-web3" # set this to your Amazon ECS service name
ECS_CLUSTER_QA: "ocl-qa-demo" # set this to your Amazon ECS cluster name
ECS_SERVICE_STAGING: "staging-web3" # set this to your Amazon ECS service name
ECS_CLUSTER_STAGING_PRODUCTION: "ocl-staging-production" # set this to your Amazon ECS cluster name
ECS_SERVICE_PRODUCTION: "production-web3" # set this to your Amazon ECS service name
jobs:
eslint:
name: Eslint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Fail if start-prod.sh writes a secret-shaped variable into env-config.js
run: |
ALLOWLIST="RECAPTCHA_SITE_KEY|ERRBIT_KEY"
LEAKS=$(grep -oE 'var [A-Za-z_]+' start-prod.sh | awk '{print $2}' | grep -E 'SECRET|PASSWORD|_KEY' | grep -vE "^(${ALLOWLIST})$" || true)
if [ -n "$LEAKS" ]; then
echo "::error::start-prod.sh writes secret-shaped variable(s) into the publicly-served env-config.js: $LEAKS"
echo "If this is intentionally public (like a DSN-style key), add it to ALLOWLIST above. Otherwise remove it."
exit 1
fi
- name: Run linting rules
uses: actions/setup-node@v3
with:
node-version: 22
cache: 'npm'
- run: npm ci
- run: ./node_modules/eslint/bin/eslint.js --ext .jsx,.js src/
build:
needs: [eslint]
name: Build and push image
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Compute version and short sha
id: version
run: |
echo "tag=$(bash release_version.sh full-version)" >> $GITHUB_OUTPUT
echo "sha=$(bash release_version.sh sha)" >> $GITHUB_OUTPUT
- name: Log in to Docker Hub
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Setup SSH for premium repos
run: |
mkdir -p ~/.ssh
echo "${{ secrets.PRIVATE_GIT_PACKAGES_DEPLOY_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan github.com >> ~/.ssh/known_hosts
- name: Setup SSH agent
uses: webfactory/ssh-agent@v0.9.0
with:
ssh-private-key: ${{ secrets.PRIVATE_GIT_PACKAGES_DEPLOY_KEY }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push Docker image
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
with:
context: .
push: true
ssh: default
tags: openconceptlab/oclweb3:nightly, openconceptlab/oclweb3:${{ steps.version.outputs.tag }}
build-args: |
SOURCE_COMMIT=${{ steps.version.outputs.sha }}
PRIVATE_PACKAGES_GIT=${{secrets.PRIVATE_PACKAGES_GIT}}
cache-from: type=gha
cache-to: type=gha,mode=max
release:
needs: [build]
runs-on: ubuntu-latest
name: Release
environment: rc
permissions:
contents: write
steps:
- name: Checkout repo
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.RELEASE_TOKEN }}
- name: Publish release and bump version
run: bash release_version.sh publish
env:
GH_TOKEN: ${{ secrets.RELEASE_TOKEN }}
deploy-qa:
needs: [release]
name: Deploy to QA
runs-on: ubuntu-latest
environment: qa
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
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: Checkout repo
uses: actions/checkout@v3
- name: Compute version and short sha
id: version
run: echo "tag=$(bash release_version.sh full-version)" >> $GITHUB_OUTPUT
- name: Push image to Amazon ECR
id: push-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ steps.version.outputs.tag }}
run: |
# Build a docker container and
# push it to ECR so that it can
# be deployed to ECS.
docker pull openconceptlab/oclweb3:$IMAGE_TAG
docker tag openconceptlab/oclweb3:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
docker tag openconceptlab/oclweb3:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:qa
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
docker push $ECR_REGISTRY/$ECR_REPOSITORY:qa
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
- name: Download task definition
run: |
aws ecs describe-task-definition --task-definition $ECS_SERVICE_QA --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: ${{ env.ECS_SERVICE_QA }}
image: ${{ steps.push-image.outputs.image }}
- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v2
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ env.ECS_SERVICE_QA }}
cluster: ${{ env.ECS_CLUSTER_QA }}
deploy-staging:
needs: [deploy-qa]
name: Deploy to Staging
runs-on: ubuntu-latest
environment: staging
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
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: Checkout repo
uses: actions/checkout@v3
- name: Compute version and short sha
id: version
run: echo "tag=$(bash release_version.sh full-version)" >> $GITHUB_OUTPUT
- name: Push image to Amazon ECR
id: push-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ steps.version.outputs.tag }}
run: |
# Build a docker container and
# push it to ECR so that it can
# be deployed to ECS.
docker pull openconceptlab/oclweb3:$IMAGE_TAG
docker tag openconceptlab/oclweb3:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:staging
docker push $ECR_REGISTRY/$ECR_REPOSITORY:staging
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
- name: Download task definition
run: |
aws ecs describe-task-definition --task-definition $ECS_SERVICE_STAGING --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: ${{ env.ECS_SERVICE_STAGING }}
image: ${{ steps.push-image.outputs.image }}
- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v2
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ env.ECS_SERVICE_STAGING }}
cluster: ${{ env.ECS_CLUSTER_STAGING_PRODUCTION }}
deploy-production:
needs: [deploy-staging]
name: Deploy to Production
runs-on: ubuntu-latest
environment: production
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
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: Checkout repo
uses: actions/checkout@v3
- name: Compute version and short sha
id: version
run: echo "tag=$(bash release_version.sh full-version)" >> $GITHUB_OUTPUT
- name: Push image to Amazon ECR
id: push-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ steps.version.outputs.tag }}
run: |
# Build a docker container and
# push it to ECR so that it can
# be deployed to ECS.
docker pull openconceptlab/oclweb3:$IMAGE_TAG
docker tag openconceptlab/oclweb3:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:production
docker push $ECR_REGISTRY/$ECR_REPOSITORY:production
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
- name: Download task definition
run: |
aws ecs describe-task-definition --task-definition $ECS_SERVICE_PRODUCTION --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: ${{ env.ECS_SERVICE_PRODUCTION }}
image: ${{ steps.push-image.outputs.image }}
- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v2
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ env.ECS_SERVICE_PRODUCTION }}
cluster: ${{ env.ECS_CLUSTER_STAGING_PRODUCTION }}
wait-for-service-stability: true
wait-for-minutes: 15