diff --git a/Dockerfile b/Dockerfile index c80527d20..3847a82dd 100755 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,4 @@ +# Install Stage FROM golang:1.23.2 AS install-stage WORKDIR /build @@ -20,14 +21,11 @@ RUN make generate && go vet ./... RUN make css RUN make release -# Default final base image to Alpine Linux +# Production Stage FROM alpine:3.21 AS production -# Ensure we have latest packages applied -RUN apk update \ - && apk upgrade +RUN apk update && apk upgrade -# Create a non-root user RUN addgroup -g 10001 -S iota-user \ && adduser --disabled-password --gecos '' -u 10000 --home /home/iota-user iota-user -G iota-user \ && chown -R iota-user:iota-user /home/iota-user @@ -40,13 +38,54 @@ ENV PATH=/home/iota-user:$PATH USER iota-user ENTRYPOINT run_server +# Staging Stage FROM install-stage AS staging RUN go build -o run_server cmd/server/main.go && go build -o seed_db cmd/seed/main.go CMD go run cmd/migrate/main.go up && /build/seed_db && /build/run_server +# Testing CI Stage FROM install-stage AS testing-ci -#CMD golangci-lint run && go test -v ./... CMD [ "go", "test", "-v", "./..." ] +# Testing Local Stage FROM install-stage AS testing-local -CMD [ "gow", "test", "./..." ] \ No newline at end of file +CMD [ "gow", "test", "./..." ] + +# Development Stage +FROM golang:1.23.2-alpine AS dev + +WORKDIR /app + +# Install required system dependencies +RUN apk add --no-cache \ + gcc \ + musl-dev \ + git \ + curl \ + make + +# Install Air for hot reloading +RUN curl -sSfL https://raw.githubusercontent.com/cosmtrek/air/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.61.5 + +# Install TailwindCSS +RUN case "$(uname -m)" in \ + "x86_64") ARCH="x64" ;; \ + "aarch64") ARCH="arm64" ;; \ + *) echo "Unsupported architecture: $(uname -m)" && exit 1 ;; \ + esac && \ + curl -sLO https://github.com/tailwindlabs/tailwindcss/releases/download/v3.4.15/tailwindcss-linux-${ARCH} && \ + chmod +x tailwindcss-linux-${ARCH} && \ + mv tailwindcss-linux-${ARCH} /usr/local/bin/tailwindcss + +# Install templ +RUN go install github.com/a-h/templ/cmd/templ@v0.2.793 + +# Copy Go modules and install dependencies +COPY go.mod go.sum ./ +RUN go mod download + +# Copy application source code +COPY . . + +# Set Air to run on container startup +ENTRYPOINT ["air"] diff --git a/Makefile b/Makefile index 4a13c821e..bb7d174ca 100644 --- a/Makefile +++ b/Makefile @@ -35,9 +35,13 @@ coverage-score: report: go tool cover -html=coverage.out -o ./coverage/cover.html +# Dev containers +dev-docker: + docker compose -f docker-compose.dev-docker.yml up --build + # Run PostgreSQL localdb: - docker compose -f docker-compose.dev.yml up + docker compose -f docker-compose.dev.yml up -d clear-localdb: rm -rf postgres-data/ @@ -92,4 +96,4 @@ run-iota-linter: clean-iota-linter: rm -f bin/iotalinter -.PHONY: default deps test test-watch localdb migrate-up migrate-down dev css-watch css lint release release-local clean setup build-iota-linter run-iota-linter clean-iota-linter +.PHONY: default deps test test-watch dev-docker localdb migrate-up migrate-down dev css-watch css lint release release-local clean setup build-iota-linter run-iota-linter clean-iota-linter diff --git a/docker-compose.dev-docker.yml b/docker-compose.dev-docker.yml new file mode 100644 index 000000000..4e3ee6b80 --- /dev/null +++ b/docker-compose.dev-docker.yml @@ -0,0 +1,39 @@ +version: '3.8' + +services: + app: + build: + context: . + dockerfile: Dockerfile + target: dev + ports: + - "8090:8090" + - "8080:8080" + - "3200:3200" + volumes: + - .:/app + - go-modules:/go/pkg/mod + environment: + - DB_HOST=db + - DB_USER=postgres + - DB_PASSWORD=postgres + - DB_NAME=iota_erp + - DB_PORT=5432 + depends_on: + - db + + db: + image: postgres:15.1 + restart: always + command: [ "postgres", "-c", "log_statement=all", "-c", "log_destination=stderr", "-c", "logging_collector=off" ] + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: iota_erp + ports: + - "5432:5432" + volumes: + - ./postgres-data:/var/lib/postgresql/data + +volumes: + go-modules: diff --git a/docs/CONTRIBUTING.MD b/docs/CONTRIBUTING.MD index 6247326d5..3eea1706e 100644 --- a/docs/CONTRIBUTING.MD +++ b/docs/CONTRIBUTING.MD @@ -13,6 +13,7 @@ Before starting, ensure the following tools are installed on your system: ## 🛠️ Development Setup +### Setup Locally 1. **Clone the repository**: ```bash git clone https://github.com/iota-uz/iota-sdk.git @@ -59,7 +60,28 @@ Before starting, ensure the following tools are installed on your system: air ``` -9. **Access the web app**: +### Setup With Docker +1. **Clone the repository**: + ```bash + git clone https://github.com/iota-uz/iota-sdk.git + ``` + +2. **Make env file**: + ```bash + cp .env.example .env + ``` + +3. **Run the project using Docker**: + ```bash + make dev-docker + ``` + +4. **Apply database migrations and seed data**: + ```bash + make migrate-up && make seed + ``` + +### Access the web app Open your browser and navigate to: [http://localhost:8080](http://localhost:8080) @@ -75,6 +97,6 @@ Before starting, ensure the following tools are installed on your system: TestPass123! ``` -10. **Access the GraphQL Schema**: +- **Access the GraphQL Schema**: Open Postman and connect to: [http://localhost:3200/query](http://localhost:3200/query)