-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(docs): add websocket endpoint and advanced flag documentation (#5)
- Loading branch information
Showing
7 changed files
with
614 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Advanced Flag in ForgeX | ||
|
||
The `--advanced` flag in ForgeX serves as a switch to enable additional features during project creation. It is applied with the `create` command and unlocks the following features: | ||
|
||
- **HTMX Support using Templ:** Enables the integration of HTMX support for dynamic web pages using Templ. | ||
|
||
- **CI/CD Workflow Setup using GitHub Actions:** Automates the setup of a CI/CD workflow using GitHub Actions. | ||
|
||
- **Websocket Support:** WebSocket endpoint that sends continuous data streams through the WS protocol. | ||
|
||
- **Tailwind:** Adds Tailwind CSS support to the project. | ||
|
||
- **Docker:** Docker configuration for Go projects. | ||
|
||
- **React:** Frontend written in TypeScript, including an example fetch request to the backend. | ||
|
||
## Using the `--advanced` Flag | ||
|
||
To utilize the `--advanced` flag, use the following command: | ||
|
||
```bash | ||
forgex create --name <project_name> --framework <selected_framework> --driver <selected_driver> --advanced | ||
``` | ||
|
||
By including the --advanced flag, users can choose one or all of the advanced features. The flag enhances the simplicity of ForgeX while offering flexibility for users who require additional functionality. | ||
|
||
## Recreating the Project Semi-Interactively | ||
To recreate the project using the same configuration semi-interactively, use the following command: | ||
|
||
```bash | ||
forgex create --name my-project --framework chi --driver mysql --advanced | ||
``` | ||
|
||
## Non-Interactive Setup | ||
Non-Interactive setup is also possible: | ||
```bash | ||
forgex create --name my-project --framework chi --driver mysql --advanced --feature htmx --feature githubaction --feature websocket --feature tailwind | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
# Advanced Flag: Docker Configuration in ForgeX | ||
|
||
The Docker advanced flag provides the app's Dockerfile configuration and creates or updates the `docker-compose.yml` file, which is generated if a DB driver is used. | ||
The Dockerfile includes a two-stage build, resulting in a smaller final image without unnecessary build dependencies. The configuration adjusts dynamically based on the advanced features selected. | ||
|
||
## Dockerfile | ||
|
||
### Standard Dockerfile | ||
|
||
```dockerfile | ||
FROM golang:1.23-alpine AS build | ||
|
||
RUN apk add --no-cache curl | ||
|
||
WORKDIR /app | ||
|
||
COPY go.mod go.sum ./ | ||
RUN go mod download | ||
|
||
COPY . . | ||
|
||
RUN go install github.com/a-h/templ/cmd/templ@latest && \ | ||
templ generate && \ | ||
curl -sL https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-linux-x64 -o tailwindcss && \ | ||
chmod +x tailwindcss && \ | ||
./tailwindcss -i cmd/web/assets/css/input.css -o cmd/web/assets/css/output.css | ||
|
||
RUN go build -o main cmd/api/main.go | ||
|
||
FROM alpine:3.20.1 AS prod | ||
WORKDIR /app | ||
COPY --from=build /app/main /app/main | ||
EXPOSE ${PORT} | ||
CMD ["./main"] | ||
``` | ||
|
||
## Dockerfile with React Flag | ||
|
||
```dockerfile | ||
FROM golang:1.23-alpine AS build | ||
|
||
WORKDIR /app | ||
|
||
COPY go.mod go.sum ./ | ||
RUN go mod download | ||
|
||
COPY . . | ||
|
||
RUN go build -o main cmd/api/main.go | ||
|
||
FROM alpine:3.20.1 AS prod | ||
WORKDIR /app | ||
COPY --from=build /app/main /app/main | ||
EXPOSE ${PORT} | ||
CMD ["./main"] | ||
|
||
FROM node:20 AS frontend_builder | ||
WORKDIR /frontend | ||
|
||
COPY frontend/package*.json ./ | ||
RUN npm install | ||
COPY frontend/. . | ||
RUN npm run build | ||
|
||
FROM node:20-slim AS frontend | ||
RUN npm install -g serve | ||
COPY --from=frontend_builder /frontend/dist /app/dist | ||
EXPOSE 5173 | ||
CMD ["serve", "-s", "/app/dist", "-l", "5173"] | ||
``` | ||
|
||
## Docker Compose | ||
docker-compose.yml pulls environment variables from the .env file. Below is an example configuration if the Docker flag is used with the MySQL DB driver: | ||
|
||
```dockerfile | ||
services: | ||
app: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
target: prod | ||
restart: unless-stopped | ||
ports: | ||
- ${PORT}:${PORT} | ||
environment: | ||
APP_ENV: ${APP_ENV} | ||
PORT: ${PORT} | ||
FORGEX_DB_HOST: ${FORGEX_DB_HOST} | ||
FORGEX_DB_PORT: ${FORGEX_DB_PORT} | ||
FORGEX_DB_DATABASE: ${FORGEX_DB_DATABASE} | ||
FORGEX_DB_USERNAME: ${FORGEX_DB_USERNAME} | ||
FORGEX_DB_PASSWORD: ${FORGEX_DB_PASSWORD} | ||
depends_on: | ||
mysql_fx: | ||
condition: service_healthy | ||
networks: | ||
- forgex | ||
mysql_fx: | ||
image: mysql:latest | ||
restart: unless-stopped | ||
environment: | ||
MYSQL_DATABASE: ${FORGEX_DB_DATABASE} | ||
MYSQL_USER: ${FORGEX_DB_USERNAME} | ||
MYSQL_PASSWORD: ${FORGEX_DB_PASSWORD} | ||
MYSQL_ROOT_PASSWORD: ${FORGEX_DB_ROOT_PASSWORD} | ||
ports: | ||
- "${FORGEX_DB_PORT}:3306" | ||
volumes: | ||
- mysql_volume_fx:/var/lib/mysql | ||
healthcheck: | ||
test: ["CMD", "mysqladmin", "ping", "-h", "${FORGEX_DB_HOST}", "-u", "${FORGEX_DB_USERNAME}", "--password=${FORGEX_DB_PASSWORD}"] | ||
interval: 5s | ||
timeout: 5s | ||
retries: 3 | ||
start_period: 15s | ||
networks: | ||
- forgex | ||
|
||
volumes: | ||
mysql_volume_fx: | ||
networks: | ||
forgex: | ||
``` | ||
## Notes | ||
Cleaning Docker Leftovers | ||
If you are testing multiple frameworks locally, ensure to clean up Docker leftovers such as volumes. Use the following commands: | ||
|
||
```dockerfile | ||
docker compose down --volumes | ||
docker compose up --build | ||
``` | ||
|
||
or | ||
|
||
```bash | ||
docker compose build --no-cache && docker compose up | ||
``` |
40 changes: 40 additions & 0 deletions
40
contents/docs/ForgeX/advanced-flag/go-releaser/goreleaser.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
Release process for Go projects, providing extensive customization options through its configuration file, `.goreleaser.yml`. By default, it ensures dependency cleanliness, builds binaries for various platforms and architectures, facilitates pre-release creation, and organizes binary packaging into archives with naming schemes. | ||
|
||
For comprehensive insights into customization possibilities, refer to the [GoReleaser documentation](https://goreleaser.com/customization/). | ||
|
||
## Usage with Tags | ||
|
||
To initiate release builds with GoReleaser, you need to follow these steps: | ||
|
||
- **Tag Creation:** | ||
When your project is ready for a release, create a new tag in your Git repository. For example: | ||
```bash | ||
git tag v1.0.0 | ||
``` | ||
|
||
- **Tag Pushing:** | ||
Push the tag to the repository to trigger GoReleaser: | ||
```bash | ||
git push origin v1.0.0 | ||
``` | ||
|
||
Following these steps ensures proper tagging of your project, prompting GoReleaser to execute configured releases. This approach simplifies release management and automates artifact distribution. | ||
|
||
## Go Test - Continuous Integration for Go Projects | ||
|
||
The `go-test.yml` file defines a GitHub Actions workflow for continuous integration (CI) of Go projects within a GitHub repository. | ||
|
||
## Workflow Steps | ||
|
||
The job outlined in this workflow includes the following steps: | ||
|
||
1. **Checkout:** | ||
Fetches the project's codebase from the repository. | ||
|
||
2. **Go Setup:** | ||
Configures the Go environment with version 1.21.x. | ||
|
||
3. **Build and Test:** | ||
Builds the project using `go build` and runs tests across all packages (`./...`) using `go test`. | ||
|
||
This workflow serves to automate the testing process of a Go project within a GitHub repository, ensuring code quality and reliability with each commit and pull request. |
78 changes: 78 additions & 0 deletions
78
contents/docs/ForgeX/advanced-flag/htmx-template/htmx-templ.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
The WEB directory contains the web-related components and assets for the project. It leverages [htmx](https://github.com/bigskysoftware/htmx) and [templ](https://github.com/a-h/templ) in Go for dynamic web content generation. | ||
|
||
## Structure | ||
|
||
``` | ||
web/ | ||
│ | ||
│ | ||
├── assets/ | ||
│ └── js/ | ||
│ └── htmx.min.js # htmx library for dynamic HTML content | ||
│ | ||
├── base.templ # Base template for HTML structure | ||
├── base_templ.go # Generated Go code for base template | ||
├── efs.go # Embeds static files into the Go binary | ||
│ | ||
├── hello.go # Handler for the Hello Web functionality | ||
├── hello.templ # Template for rendering the Hello form and post data | ||
└── hello_templ.go # Generated Go code for hello template | ||
``` | ||
|
||
## Usage | ||
|
||
- **Navigate to Project Directory:** | ||
```bash | ||
cd my-project | ||
``` | ||
|
||
- **Install Templ CLI:** | ||
```bash | ||
go install github.com/a-h/templ/cmd/templ@latest | ||
``` | ||
|
||
- **Generate Templ Function Files:** | ||
```bash | ||
templ generate | ||
``` | ||
|
||
- **Start Server:** | ||
```bash | ||
make run | ||
``` | ||
|
||
## Makefile | ||
|
||
Automates templ with Makefile entries, which are automatically created if the htmx advanced flag is used. | ||
It detects if templ is installed or not and generates templates with the make build command. | ||
Both Windows and Unix-like OS are supported. | ||
|
||
```bash | ||
all: build | ||
|
||
templ-install: | ||
@if ! command -v templ > /dev/null; then \ | ||
read -p "Go's 'templ' is not installed on your machine. Do you want to install it? [Y/n] " choice; \ | ||
if [ "$$choice" != "n" ] && [ "$$choice" != "N" ]; then \ | ||
go install github.com/a-h/templ/cmd/templ@latest; \ | ||
if [ ! -x "$$(command -v templ)" ]; then \ | ||
echo "templ installation failed. Exiting..."; \ | ||
exit 1; \ | ||
fi; \ | ||
else \ | ||
echo "You chose not to install templ. Exiting..."; \ | ||
exit 1; \ | ||
fi; \ | ||
fi | ||
|
||
build: templ-install | ||
@echo "Building..." | ||
@templ generate | ||
@go build -o main cmd/api/main.go | ||
``` | ||
|
||
## Templating | ||
|
||
Templates are generated using the `templ generate` command after project creation. These templates are then compiled into Go code for efficient execution. | ||
|
||
You can test HTMX functionality on `localhost:PORT/web` endpoint. |
Oops, something went wrong.