Skip to content

Commit

Permalink
Merge pull request #28 from xeptagondev/main
Browse files Browse the repository at this point in the history
Phase 2 Release
  • Loading branch information
reinaotsuka authored Aug 1, 2024
2 parents 4011a1f + cc2ea6d commit d1c6100
Show file tree
Hide file tree
Showing 650 changed files with 54,712 additions and 5,374 deletions.
156 changes: 156 additions & 0 deletions .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
name: Carbon Transparency Test Deployment
on:
workflow_dispatch:
push:
branches:
- "staging"
paths:
- backend/**
- web/**
- .github/workflows/deployment*

env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: us-east-1

jobs:
changes:
name: Carbon Transparency Deploy Pre
runs-on: ubuntu-latest
outputs:
backend-changes: ${{ steps.changes.outputs.backend-changes }}
workflows-changes: ${{ steps.changes.outputs.workflows-changes }}
frontend-changes: ${{ steps.changes.outputs.frontend-changes }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Determine changed services
id: changes
run: |
CHANGED_FILES=$(git diff --name-only HEAD^ HEAD)
if echo "$CHANGED_FILES" | grep -q "backend/"; then
echo "Backend changes detected."
echo "backend-changes=true" >> $GITHUB_OUTPUT
else
echo "No Backend changes detected."
echo "backend-changes=false" >> $GITHUB_OUTPUT
fi
if echo echo "$CHANGED_FILES" | grep -q ".github/workflows/"; then
echo "Workflow changes detected."
echo "workflows-changes=true" >> $GITHUB_OUTPUT
else
echo "No Workflow changes detected."
echo "workflows-changes=false" >> $GITHUB_OUTPUT
fi
if echo "$CHANGED_FILES" | grep -q "web/"; then
echo "Frontend changes detected."
echo "frontend-changes=true" >> $GITHUB_OUTPUT
else
echo "No Frontend changes detected."
echo "frontend-changes=false" >> $GITHUB_OUTPUT
fi
backend-deploy:
needs: changes
if: needs.changes.outputs.backend-changes == 'true' || needs.changes.outputs.workflows-changes == 'true'
name: Carbon Transparency Backend Deploy
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-'backend'
cancel-in-progress: true
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- 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: us-east-1
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Build, tag, and push the backend images to Amazon ECR
id: build-backend-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: transparency-services
IMAGE_TAG: ${{ github.head_ref || github.ref_name }}
run: |
# Build a docker container and push it to ECR
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f backend/services/Dockerfile .
echo "Pushing image to ECR..."
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
- name: Deploy backend images to Amazon EC2
id: deploy-backend
env:
PRIVATE_KEY: ${{ secrets.AWS_SSH_KEY_PRIVATE }}
HOSTNAME: ${{secrets.HOST_IP }}
USER_NAME: ec2-user
run: |
echo "$PRIVATE_KEY" > private_key && chmod 600 private_key
ssh -o StrictHostKeyChecking=no -i private_key ${USER_NAME}@${HOSTNAME} '
repos/carbon-transparency/mrv_backend_deploy.sh '
frontend-deploy:
needs: changes
if: needs.changes.outputs.frontend-changes == 'true' || needs.changes.outputs.workflows-changes == 'true'
name: Carbon Transparency Frontend Deploy
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-'web'
cancel-in-progress: true
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- 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: us-east-1
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Build, tag, and push the frontend images to Amazon ECR
id: build-frontend-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: transparency-web
IMAGE_TAG: ${{ github.head_ref || github.ref_name }}
run: |
# Build a docker container and push it to ECR
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f web/Dockerfile . --build-arg PORT=3030 --build-arg REACT_APP_BACKEND=http://localhost:9000 --build-arg REACT_APP_STAT_URL=http://localhost:9100 --build-arg COUNTRY_NAME="CountryX" --build-arg COUNTRY_FLAG_URL="https://carbon-common-dev.s3.amazonaws.com/flag.png" --build-arg COUNTRY_CODE="NG" --build-arg REACT_APP_MAP_TYPE="Mapbox" --build-arg REACT_APP_GOVERNMENT_MINISTRY:"Ministry Of Environment" --build-arg REACT_APP_MAPBOXGL_ACCESS_TOKEN=${{ secrets.MAPBOXGL_ACCESS_TOKEN }}
echo "Pushing image to ECR..."
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
- name: Deploy frontend images to Amazon EC2
id: deploy-frontend
env:
PRIVATE_KEY: ${{ secrets.AWS_SSH_KEY_PRIVATE }}
HOSTNAME: ${{secrets.HOST_IP }}
USER_NAME: ec2-user
run: |
echo "$PRIVATE_KEY" > private_key && chmod 600 private_key
ssh -o StrictHostKeyChecking=no -i private_key ${USER_NAME}@${HOSTNAME} '
repos/carbon-transparency/mrv_frontend_deploy.sh '
101 changes: 0 additions & 101 deletions .github/workflows/frontend-deployment.yml

This file was deleted.

Loading

0 comments on commit d1c6100

Please sign in to comment.