|
| 1 | +--- |
| 2 | +title: Adding Custom 1-Click Deploy to Your App |
| 3 | +sidebar_position: 800 |
| 4 | +description: Add a custom 1-Click Deploy link to deploy your own app. |
| 5 | +--- |
| 6 | + |
| 7 | +# Adding Custom 1-Click Deploy to Your App |
| 8 | + |
| 9 | +This tutorial will show you how to add a 1-Click Deploy link to deploy your app to the Defang Playground. A 1-Click Deploy link points to a special Defang URL. Clicking this link will trigger a deployment of a project to Defang. The link is often placed as a button in the `README.md` file of your project repository, and is the easiest way to allow anyone to deploy your app. |
| 10 | + |
| 11 | +:::info |
| 12 | +If you are trying to use 1-Click Deploy with one of our [samples](https://defang.io/samples/), we have a separate tutorial on [how to use 1-Click Deploy](/docs/tutorials/using-one-click-deploy). |
| 13 | +::: |
| 14 | + |
| 15 | +## Pre-requisites |
| 16 | + |
| 17 | +- A [GitHub](https://github.com/) repository for your project |
| 18 | + |
| 19 | +## Step 1 - Prepare Your App |
| 20 | + |
| 21 | +You will need a `compose.yaml` file in the root folder of your project to describe the services which will be deployed. Learn more about writing [Compose files](/docs/concepts/compose#example-of-a-compose-file). |
| 22 | + |
| 23 | +## Step 2 - Copy the GitHub Workflow |
| 24 | + |
| 25 | +In your project, add a new folder named `.github`, then add a folder `workflows` inside it, and copy the entire GitHub Workflow `deploy.yaml` file from [here](https://github.com/DefangLabs/samples/blob/main/starter-sample/.github/workflows/deploy.yaml) into the `workflows` folder. |
| 26 | + |
| 27 | +If your app requires [configuration](/docs/concepts/configuration) (e.g. API keys, passwords, etc.), learn more about [managing config variables with the Defang GitHub Action](https://github.com/DefangLabs/defang-github-action). |
| 28 | + |
| 29 | +You should have a `.yaml` file similar to the one below: |
| 30 | +```yaml |
| 31 | +name: Deploy |
| 32 | + |
| 33 | +on: |
| 34 | + push: |
| 35 | + branches: |
| 36 | + - main |
| 37 | + |
| 38 | +jobs: |
| 39 | + deploy: |
| 40 | + environment: playground |
| 41 | + runs-on: ubuntu-latest |
| 42 | + permissions: |
| 43 | + contents: read |
| 44 | + id-token: write |
| 45 | + |
| 46 | + steps: |
| 47 | + - name: Checkout Repo |
| 48 | + uses: actions/checkout@v4 |
| 49 | + |
| 50 | + - name: Deploy |
| 51 | + uses: DefangLabs/[email protected] |
| 52 | +``` |
| 53 | +
|
| 54 | +## Step 3 - Get the Encoded URL |
| 55 | +
|
| 56 | +You will need the encoded version of your project repository's URL. This will be used as a redirect for the 1-Click Deploy link. |
| 57 | +
|
| 58 | +1. Copy the URL of your repository's homepage. It should look something like the following: |
| 59 | +``` |
| 60 | +https://github.com/<your-github-username>/<your-repo-name> |
| 61 | +``` |
| 62 | +2. You can go online and paste the URL from the step above into a URL encoder tool of your choice. You should end up with an encoded URL, similar to the one shown below: |
| 63 | + |
| 64 | +``` |
| 65 | +https%3A%2F%2Fgithub.com%2F<your-github-username>%2F<your-repo-name> |
| 66 | +``` |
| 67 | + |
| 68 | +## Step 4 - Create the 1-Click Deploy Link |
| 69 | + |
| 70 | +You will need to create a 1-Click Deploy link with the following format: `https://portal.defang.dev/redirect?url=` + your encoded URL. This ensures that the user can get [logged in](/docs/concepts/authentication/) to Defang before they get redirected to clone your app for deployment. |
| 71 | + |
| 72 | +:::tip |
| 73 | +Optionally, you can add `&name=<your-project-here>` to the end of the link if you'd like to suggest a name for the user to use for their deployment. |
| 74 | +::: |
| 75 | + |
| 76 | +The finished link should look similar to the one below: |
| 77 | +``` |
| 78 | +https://portal.defang.dev/redirect?url=https%3A%2F%2Fgithub.com%2F<your-github-username>%2F<your-project-here>&name=<your-project-here> |
| 79 | +``` |
| 80 | + |
| 81 | +Now you have a link for anyone to deploy your app to Defang, with just 1 click. |
| 82 | + |
| 83 | +## Step 5 - Use the Link |
| 84 | +For example, you can add it as a link in a Markdown file: |
| 85 | +``` |
| 86 | +[1-Click Deploy Link](https://portal.defang.dev/redirect?url=<your-encoded-url>&name=<your-project-here>) |
| 87 | +``` |
| 88 | +Or perhaps you can add it to a button with your own styling: |
| 89 | +``` |
| 90 | +[](https://portal.defang.dev/redirect?url=<your-encoded-url>&name=<your-project-here>) |
| 91 | +``` |
0 commit comments