Skip to content

CI/CD Integration

Automate USL application deployment.

GitHub Actions

.github/workflows/deploy.yml:

name: Deploy

on:
  push:
    branches: [main]

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v3

    - name: Setup USL
      run: |
        curl -fsSL https://raw.githubusercontent.com/shaifulshabuj/USL/main/scripts/install.sh | sh
        echo "$HOME/.usl/bin" >> $GITHUB_PATH

    - name: Compile
      run: usl compile my-app.usl

    - name: Generate Code
      run: usl generate --target typescript --output ./backend

    - name: Test
      run: |
        cd backend
        npm ci
        npm test

    - name: Build Docker Image
      run: docker build -t my-app:${{ github.sha }} .

    - name: Push to Registry
      run: |
        echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
        docker push my-app:${{ github.sha }}

    - name: Deploy to Kubernetes
      run: |
        kubectl set image deployment/my-app my-app=my-app:${{ github.sha }}

GitLab CI

.gitlab-ci.yml:

stages:
  - build
  - test
  - deploy

build:
  stage: build
  script:
    - curl -fsSL https://raw.githubusercontent.com/shaifulshabuj/USL/main/scripts/install.sh | sh
    - usl compile my-app.usl
    - usl generate --target typescript --output ./backend

test:
  stage: test
  script:
    - cd backend
    - npm ci
    - npm test

deploy:
  stage: deploy
  script:
    - docker build -t my-app:latest .
    - docker push my-app:latest
    - kubectl apply -f k8s/
  only:
    - main

CircleCI

.circleci/config.yml:

version: 2.1

jobs:
  build:
    docker:
      - image: cimg/node:18.0
    steps:
      - checkout
      - run: curl -fsSL https://raw.githubusercontent.com/shaifulshabuj/USL/main/scripts/install.sh | sh
      - run: usl compile my-app.usl
      - run: usl generate --target typescript

  test:
    docker:
      - image: cimg/node:18.0
    steps:
      - run: npm ci
      - run: npm test

  deploy:
    docker:
      - image: cimg/node:18.0
    steps:
      - run: docker build -t my-app .
      - run: docker push my-app

workflows:
  build-test-deploy:
    jobs:
      - build
      - test:
          requires:
            - build
      - deploy:
          requires:
            - test
          filters:
            branches:
              only: main

Back to Deployment Overview