Self-Hosting Your Project π
This section explains how to deploy and run your project in a self-hosted environment. You have three main options:
- Using Docker directly with the provided Dockerfile π³
- Using the Makefile for an automated build and run process βοΈ
- Executing the Go code directly with command-line flags π¨βπ»
Option 1: Docker Deployment π³
The Docker deployment is based on the production Dockerfile located at docker/Dockerfile.prod
. Follow these steps:
1. Prepare the Environment File π
Copy the example.env
file to .env
and edit the file to fill in your parameters:
HOST="localhost"
PORT=8080
EMAIL_ADDR="test@test.com"
EMAIL_PASS="smtp_server_password"
EMAIL_HOST="smtp.example.com"
EMAIL_PORT=587
SECRET="my_backend_secret"
2. Build the Docker Image ποΈ
Run the following command in the root of your project to build the image:
docker build -f docker/Dockerfile.prod -t simpleauthlink .
3. Run the Docker Container π’
Once the image is built, start a container using the environment file:
docker run --name simpleauthlink --env-file .env -p 8080:80 simpleauthlink
This command maps the containerβs port 80 to port 8080 on your host.
Option 2: Using the Makefile βοΈ
The Makefile in the root of the project simplifies the build and run process. It contains two targets: api
(for building and running the API container) and clean-api
(for cleaning up previous containers and images).
1. Set Up the Environment File π
As with the Docker approach, copy and edit example.env to .env with your configuration:
HOST="localhost"
PORT=8080
EMAIL_ADDR="test@test.com"
EMAIL_PASS="smtp_server_password"
EMAIL_HOST="smtp.example.com"
EMAIL_PORT=587
SECRET="my_backend_secret"
2. Build and Run Using Make πββοΈ
Run the following command from your project root:
make run api
This will:
- Clean up any previous containers and images.
- Build the Docker image using the docker/Dockerfile.prod.
- Run the container with the environment variables from .env and expose the API on the configured port.
Option 3: Running the Go Code Directly π¨βπ»
If you prefer to run the API without Docker, you can execute the Go code directly. The entry point is cmd/authapi/main.go
and it accepts several flags for configuration.
The available flags include:
--host
or environment variableHOST
(default:"localhost"
)--port
or environment variablePORT
(default:8080
)--email-addr
or environment variableEMAIL_ADDR
(required)--email-pass
or environment variableEMAIL_PASS
(required)--email-host
or environment variableEMAIL_HOST
(required)--email-port
or environment variableEMAIL_PORT
(default: as defined in code)--secret
or environment variable SECRET (required)
Running Directly πββοΈ
Set the required environment variables or pass them as command-line flags. For example:
go run cmd/simpleauthlink/main.go \
--host="localhost" \
--port=8080 \
--email-addr="test@test.com" \
--email-pass="smtp_server_password" \
--email-host="smtp.example.com" \
--email-port=587 \
--secret="my_backend_secret"
Or set the environment variables first:
export HOST="localhost"
export PORT=8080
export EMAIL_ADDR="test@test.com"
export EMAIL_PASS="smtp_server_password"
export EMAIL_HOST="smtp.example.com"
export EMAIL_PORT=587
export SECRET="my_backend_secret"
go run cmd/simpleauthlink/main.go
Choose the option that best fits your deployment needs. The Docker and Makefile options are ideal for containerized environments, while running the Go code directly might be preferred for development or custom setups.