Skip to content

platform-build

platform-build #84

name: platform-build
on:
push:
branches: ["karrio-platform"]
workflow_dispatch:
jobs:
changes:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.changes.outputs.version }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v2
id: changes
with:
filters: |
version:
- 'apps/api/karrio/server/VERSION'
platform-server-build:
needs: changes
if: ${{ needs.changes.outputs.version == 'true' || github.event_name == 'workflow_dispatch' }}
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
outputs:
version: ${{ steps.get_tag.outputs.tag }}
env:
DOCKER_BUILDKIT: 1
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
token: ${{ secrets.GH_PAT }}
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- id: get_tag
run: |
echo "tag=$(cat ./apps/api/karrio/server/VERSION)" >> "$GITHUB_OUTPUT"
- name: Build JS client
run: |
docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli generate \
-i /local/schemas/openapi.yml \
-g typescript-fetch \
-o /local/packages/karriojs/api/generated \
--additional-properties=typescriptThreePlus=true \
--additional-properties=modelPropertyNaming=snake_case \
--additional-properties=useSingleRequestParameter=true
cd packages/karriojs
npm install
npx gulp build --output "${GITHUB_WORKSPACE}/apps/api/karrio/server/static/karrio/js/karrio.js"
cd -
- name: Build embeddable elements
run: |
cd packages/elements
npm install
npm run build
ELEMENTS_STATIC="${GITHUB_WORKSPACE}/apps/api/karrio/server/static/karrio/elements"
mkdir -p "${ELEMENTS_STATIC}" "${ELEMENTS_STATIC}/chunks"
cp dist/elements.js dist/globals.css "${ELEMENTS_STATIC}/"
cp dist/ratesheet.js dist/ratesheet.html "${ELEMENTS_STATIC}/"
cp dist/devtools.js dist/devtools.css dist/devtools.html "${ELEMENTS_STATIC}/"
cp dist/template-editor.js dist/template-editor.html "${ELEMENTS_STATIC}/"
cp dist/connections.js dist/connections.html "${ELEMENTS_STATIC}/"
[ -d dist/chunks ] && cp dist/chunks/* "${ELEMENTS_STATIC}/chunks/"
cd -
- name: Build platform server image
run: |
echo 'Build and push karrio-platform server:${{ steps.get_tag.outputs.tag }}...'
echo ${{ secrets.GH_PAT }} | docker login ghcr.io -u USERNAME --password-stdin
EDITION=platform \
KARRIO_IMAGE=ghcr.io/karrioapi/cloud \
./bin/build-insiders-image ${{ steps.get_tag.outputs.tag }} &&
docker push ghcr.io/karrioapi/cloud:${{ steps.get_tag.outputs.tag }} || exit 1
platform-ecr-publish:
needs: platform-server-build
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Pull platform server image
run: |
echo ${{ secrets.GH_PAT }} | docker login ghcr.io -u USERNAME --password-stdin
docker pull ghcr.io/karrioapi/cloud:${{ needs.platform-server-build.outputs.version }}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
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@v2
with:
mask-password: true
- name: Tag and push to AWS ECR
run: |
docker tag ghcr.io/karrioapi/cloud:${{ needs.platform-server-build.outputs.version }} 563562701692.dkr.ecr.us-east-1.amazonaws.com/karrio/api:${{ needs.platform-server-build.outputs.version }}
docker push 563562701692.dkr.ecr.us-east-1.amazonaws.com/karrio/api:${{ needs.platform-server-build.outputs.version }}
platform-infra-deploy:
needs: [platform-server-build, platform-ecr-publish]
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
token: ${{ secrets.GH_PAT }}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ca-central-1
- name: Install Pulumi CLI
run: |
curl -fsSL https://get.pulumi.com | sh
export PATH=$PATH:$HOME/.pulumi/bin
echo "$HOME/.pulumi/bin" >> $GITHUB_PATH
- name: Deploy with Pulumi
env:
PULUMI_CONFIG_PASSPHRASE: ${{ secrets.PULUMI_CONFIG_PASSPHRASE }}
PULUMI_STATE_BUCKET: ${{ secrets.PULUMI_STATE_BUCKET }}
run: |
pulumi login s3://${{ secrets.PULUMI_STATE_BUCKET }}
cd ee/platform/infra && npm install && pulumi up -s karrio-us --skip-preview --yes