Building Docker Images and Deployment file with LDL

This guide will walk you through the process of building and pushing a Docker image, and then creating a deployment file using Lagrange Definition Language (LDL) to deploy your application on the Swan Chain network.

Background

When you deploy your application to SwanChain using the Swan SDK, you need to upload a project with a Dockerfile or a deploy.yaml to GitHub. This article describes how to create a project with a Dockerfile or a deploy.yaml file and upload it to GitHub.

Key Concepts

  • A Dockerfile is a text document containing commands to assemble a Docker image.

  • A deploy.yaml file, written in Lagrange Definition Language (LDL), specifies deployment details for your Applications. This gives you more flexibility to add multiple dependent services and more configurations to your application

Building and Pushing Your Docker Image

  1. Download the template: Download the docker-application-template

  2. Navigate to the app folder:

cd docker-application-template/app
  1. Modify the application code: Edit the main.py file.

For example:

from fastapi import FastAPI
from datetime import datetime

app = FastAPI()

@app.get("/")
def read_root():
    current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    return {"Hello!"  f"Today is - {current_time}"}
  1. Push your code to GitHub

You’re now ready to use your repo URL and the Swan SDK to deploy your first application!


If you believe the Dockerfile alone cannot meet your complex deployment requirements, the next steps will guide you in preparing and creating a deploy.yaml file yourself.

  1. Build the Docker image: Navigate to the root folder and run:

cd docker-application-template
docker build --platform linux/amd64 --tag <username>/<repo>:<tag> .
  1. Push to container registry:

docker push <username>/<repo>:<tag>

Creating Deployment Files with LDL

  1. Create a new project folder:

mkdir my-swan-app-with-ldl
cd my-swan-app-with-ldl
  1. Create the deploy.yaml file:

Create a deploy.yaml file in the root of the folder with the following content:

version: "2.0"
services:
  hello-world:
    image: <username>/<repo>:<tag>
    expose:
      - port: 7860
        as: 80
deployment:
  hello-world:
    lagrange:
      count: 1

Note: Replace <username>/<repo>:<tag> with your Docker image information.

  1. Push the LDL project to GitHub

Next Steps

With your Docker image built and pushed, and your LDL deployment file created, you're now ready to deploy your application on the Swan Chain network using Swan SDK. Refer to the Swan SDK documentation for the next steps in the deployment process.

For more information on customizing your deployment settings with LDL, check out the LDL documentation.

Last updated