Fooocus is an AI-powered image generation tool that makes it easy to create custom images from descriptive prompts. Built using Gradio, Fooocus uses a prompt-centered approach to image generation, taking care of much of the behind configuration needed to produce high-quality images.
In this guide, we will demonstrate how to deploy and configure Fooocus on Koyeb's GPU instances. We will set up a custom Dockerfile
to configure authentication and push our project to GitHub. Afterwards, we will deploy the project to Koyeb to build a container image and launch it on GPU-powered hardware.
You can consult the repository for this guide to follow along on your own. You can deploy the Fooocus instance by clicking the Deploy to Koyeb button below:
You will need to set the Grace period in the Health checks section to 300 seconds during configuration. If you want to password protect your Fooocus instance, add the FOOOCUS_USERNAME
and FOOOCUS_PASSWORD
environment variables with appropriate values. You can consult the appropriate sections of this guide for additional information.
Requirements
To successfully follow and complete this guide, you need:
- A Koyeb account to build and run the Fooocus instance on GPUs.
- Access to GPU Instances on Koyeb. Join the preview today to gain access.
Steps
To complete this guide and deploy your own Fooocus instance, you'll need to follow these steps:
Create a custom Dockerfile
The Fooocus project provides Docker images based on the Dockerfile
included in the repository. However, the provided images do not configure authentication by default, meaning that, once deployed, the Fooocus instance would be accessible to anyone who visits the URL.
To mitigate this, we will create a custom Dockerfile
based on the official Dockefile
. It will conditionally write a auth.json
file to the image filesystem if the appropriate variables are configured at build time.
To begin, create a new project directory and navigate inside:
```bash copy
mkdir example-fooocus
cd example-fooocus
Inside, create a `Dockerfile` with the following contents:
```dockerfile copy
FROM ghcr.io/lllyasviel/fooocus
ARG FOOOCUS_USERNAME
ARG FOOOCUS_PASSWORD
RUN if [ -n "$FOOOCUS_USERNAME" -a -n "$FOOOCUS_PASSWORD" ]; then echo "[ { \"user\": \"$FOOOCUS_USERNAME\", \"pass\": \"$FOOOCUS_PASSWORD\" } ]" > /content/app/auth.json; fi
If the FOOOCUS_USERNAME
and FOOOCUS_PASSWORD
variables are set at build time, this Dockerfile will create the auth.json
file that Fooocus checks to configure authentication. If these values are not set, authentication will be disabled.
Push the Dockerfile to GitHub
The small Dockerfile
above is the only thing you need to configure authentication for Fooocus. Next, commit the file to a git repository and push it to GitHub.
Create a new GitHub repository and then run the following commands to commit and push changes to your GitHub repository:
```bash // // copy
git add :/
git commit -m "Initial commit"
git remote add origin git@github.com:/.git
git branch -M main
git push -u origin main
**Note:** Make sure to replace `<YOUR_GITHUB_USERNAME>` and `<YOUR_REPOSITORY_NAME>` with your GitHub username and repository name.
## Deploy Fooocus on Koyeb
Now that the `Dockerfile` is on GitHub, we can deploy it to Koyeb. On the **Overview** tab of the [Koyeb control panel](https://app.koyeb.com/), click **Create Web Service** to begin:
1. Select **GitHub** as the deployment method.
2. Select your Fooocus project repository. Alternatively, you can enter our public [Fooocus example repository](https://github.com/koyeb/example-fooocus) into the **Public GitHub repository** field at the bottom of the page: `https://github.com/koyeb/example-fooocus`.
3. In the **Environment variables** section, click **Bulk edit** to enter multiple environment variables at once. In the text box that appears, paste the following:
```bash copy
CMDARGS=--listen --port={{ PORT }}
FOOOCUS_USERNAME=
FOOOCUS_PASSWORD=
Set the variable values to reference your own information as follows:
-
CMDARGS
: The--listen --port={{ PORT }}
arguments configure Fooocus to listen for external connections. Koyeb automatically sets thePORT
environment variable to the port it exposes. This will be automatically substituted with the correct value on deployment. -
FOOOCUS_USERNAME
: Set to the username you wish to use to authenticate. Remove this environment variable to deploy without authentication. -
FOOOCUS_USERNAME
: Set to the password you wish to use to authenticate. Remove this environment variable to deploy without authentication.
- In the Instance section, select the GPU category and choose RTX-4000-SFF-ADA. These Instances are available when you request access to the GPU preview.
- In the Health checks section, set the Grace period to 300 seconds. This will provide time for the server to download all of the relevant models from Hugging Face and initialize the server.
- Click Deploy.
Koyeb will pull the provided Fooocus repository, build the Dockerfile
it contains, and run it on a GPU Instance. During deployment, Fooocus will fetch the provided model from Hugging Face and start up the service to expose it to users. If you provided authentication details, these will be configure during the build process.
Once the deployment is complete, access your Fooocus instance by visiting your Koyeb deployment URL. The application URL should have the following format:
https://<YOUR_APP_NAME>-<YOUR_KOYEB_ORG>-<HASH>.koyeb.app
Enter your provided username and password, if configured. The Fooocus prompt interface will be displayed, allowing you to generate images by describing what you would like to produce. To modify the default configuration, check the Advanced box below the prompt. From here, you can change the generator settings, the image styles, the models that will be used, and more.
Conclusion
In this guide, we discussed how to configure and deploy a Fooocus Instance on Koyeb to generate AI images. We started with the basic Fooocus Docker image and configured authentication based on user-provided variables. Afterwards, we deployed Fooocus to Koyeb by building the Dockerfile
and launching it on Koyeb's GPU Instances.
This process provides you with a fully-functional AI-powered image generator. You can tweak the settings to change the styles the generator will use, its model configuration, and the formats it outputs. As you experiment, you might want to check out the Fooocus Docker instructions and troubleshooting tips.
Top comments (0)