mirror of
https://github.com/fleetbase/fleetbase.git
synced 2025-12-19 22:27:22 +00:00
140 lines
4.4 KiB
YAML
140 lines
4.4 KiB
YAML
name: Fleetbase CI/CD
|
|
|
|
on:
|
|
push:
|
|
branches: [ "deploy/*" ]
|
|
|
|
concurrency:
|
|
group: ${{ github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
env:
|
|
PROJECT: fleetbase
|
|
jobs:
|
|
build_service:
|
|
name: Build and Deploy the Service
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
id-token: write # This is required for requesting the JWT
|
|
contents: read # This is required for actions/checkout
|
|
|
|
steps:
|
|
- name: Checkout Code
|
|
uses: actions/checkout@v3
|
|
with:
|
|
submodules: recursive
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v2
|
|
|
|
- name: Set Dynamic ENV Vars
|
|
run: |
|
|
SHORT_COMMIT=$(echo $GITHUB_SHA | cut -c -8)
|
|
echo "VERSION=${SHORT_COMMIT}" >> $GITHUB_ENV
|
|
echo "STACK=$(basename $GITHUB_REF)" >> $GITHUB_ENV
|
|
|
|
- name: Configure AWS Credentials
|
|
uses: aws-actions/configure-aws-credentials@v2
|
|
with:
|
|
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_NUMBER }}:role/${{ env.PROJECT }}-${{ env.STACK }}-deployer
|
|
role-session-name: github
|
|
aws-region: ${{ secrets.AWS_REGION }}
|
|
|
|
- name: Login to Amazon ECR
|
|
id: login-ecr
|
|
uses: aws-actions/amazon-ecr-login@v1
|
|
|
|
- name: Build and Release
|
|
uses: docker/bake-action@v2
|
|
env:
|
|
REGISTRY: ${{ steps.login-ecr.outputs.registry }}/${{ env.PROJECT }}-${{ env.STACK }}
|
|
VERSION: ${{ env.VERSION }}
|
|
with:
|
|
push: true
|
|
files: |
|
|
./docker-bake.hcl
|
|
|
|
- name: Download ecs-tool
|
|
run: |
|
|
wget -O ecs-tool.tar.gz https://github.com/springload/ecs-tool/releases/download/1.9.6/ecs-tool_1.9.6_linux_amd64.tar.gz && tar -xvf ecs-tool.tar.gz ecs-tool
|
|
|
|
- name: Deploy the images 🚀
|
|
run: |-
|
|
set -eu
|
|
# run deploy.sh script before deployments
|
|
env "ECS_RUN.SERVICE=app" "ECS_RUN.LAUNCH_TYPE=FARGATE" ./ecs-tool run --image_tag '{container_name}-${{ env.VERSION }}' --cluster ${{ env.PROJECT }}-${{ env.STACK }} --task_definition ${{ env.PROJECT }}-${{ env.STACK }}-app --container_name app ./deploy.sh
|
|
./ecs-tool deploy --image_tag '{container_name}-${{ env.VERSION }}' --cluster ${{ env.PROJECT }}-${{ env.STACK }} -s app -s scheduler -s events
|
|
|
|
build_frontend:
|
|
name: Build and Deploy the Console
|
|
needs: [build_service]
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
id-token: write # This is required for requesting the JWT
|
|
contents: read # This is required for actions/checkout
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v3
|
|
with:
|
|
submodules: true
|
|
|
|
- name: Set Dynamic ENV Vars
|
|
run: |
|
|
SHORT_COMMIT=$(echo $GITHUB_SHA | cut -c -8)
|
|
echo "VERSION=${SHORT_COMMIT}" >> $GITHUB_ENV
|
|
echo "STACK=$(basename $GITHUB_REF)" >> $GITHUB_ENV
|
|
|
|
- name: Install Node.js
|
|
uses: actions/setup-node@v3
|
|
with:
|
|
node-version: 16
|
|
|
|
- uses: pnpm/action-setup@v2
|
|
name: Install pnpm
|
|
id: pnpm-install
|
|
with:
|
|
version: 8
|
|
run_install: false
|
|
|
|
- name: Get pnpm Store Directory
|
|
id: pnpm-cache
|
|
shell: bash
|
|
run: |
|
|
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
|
|
|
|
- uses: actions/cache@v3
|
|
name: Setup pnpm Cache
|
|
with:
|
|
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
|
|
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-pnpm-store-
|
|
|
|
- name: Install dependencies
|
|
run: pnpm install
|
|
working-directory: ./console
|
|
|
|
- name: Build
|
|
run: |
|
|
set -eu
|
|
|
|
export API_HOST=api.${{ env.STACK }}.${{ env.PROJECT }}.io
|
|
export SOCKETCLUSTER_HOST=socket.${{ env.STACK }}.${{ env.PROJECT }}.io
|
|
|
|
pnpm build
|
|
working-directory: ./console
|
|
|
|
- name: Configure AWS Credentials
|
|
uses: aws-actions/configure-aws-credentials@v2
|
|
with:
|
|
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_NUMBER }}:role/${{ env.PROJECT }}-${{ env.STACK }}-deployer
|
|
role-session-name: github
|
|
aws-region: ${{ secrets.AWS_REGION }}
|
|
|
|
- name: Deploy Console 🚀
|
|
run: |
|
|
DEPLOY_BUCKET=${{ env.PROJECT }}}-${{ env.STACK }}
|
|
wget -O- https://github.com/bep/s3deploy/releases/download/v2.11.0/s3deploy_2.11.0_linux-amd64.tar.gz | tar xzv -f - s3deploy
|
|
./s3deploy -region ${AWS_REGION} -source console/dist -bucket ${DEPLOY_BUCKET}
|