Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ EMAIL_ADMIN_ADDRESS=dev@zenfulcode.com
STRIPE_ENABLED=true
STRIPE_SECRET_KEY=sk_test_your_key
STRIPE_PUBLIC_KEY=pk_test_your_key
STRIPE_WEBHOOK_SECRET=whsec_your_webhook_signing_secret
STRIPE_PAYMENT_DESCRIPTION=Commercify Store Purchase

PAYPAL_ENABLED=true
PAYPAL_CLIENT_ID=your_client_id
Expand All @@ -36,7 +38,8 @@ MOBILEPAY_MERCHANT_SERIAL_NUMBER=your_merchant_serial_number
MOBILEPAY_SUBSCRIPTION_KEY=your_subscription_key
MOBILEPAY_CLIENT_ID=your_client_id
MOBILEPAY_CLIENT_SECRET=your_client_secret
MOBILEPAY_RETURN_URL=https://your-site.com/payment/complete
MOBILEPAY_WEBHOOK_URL=https://your-site.com/api/webhooks/mobilepay
MOBILEPAY_PAYMENT_DESCRIPTION=Commercify Store Purchase
MOBILEPAY_MARKET=NOK
MOBILEPAY_MARKET=NOK

RETURN_URL=https://your-site.com/payment/complete
45 changes: 45 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
FROM golang:1.24-alpine AS builder

WORKDIR /app

# Install build dependencies
RUN apk add --no-cache git

# Copy the entire codebase first
COPY . .

# Delete the go.work files that reference external modules
RUN rm -f go.work go.work.sum

# Build all three applications
RUN go mod download
RUN go build -o commercify cmd/api/main.go
RUN go build -o commercify-migrate cmd/migrate/main.go
RUN go build -o commercify-seed cmd/seed/main.go

# Create a minimal final image
FROM alpine:latest

WORKDIR /app

# Install runtime dependencies
RUN apk add --no-cache ca-certificates tzdata bash

# Copy the binaries from the builder stage
COPY --from=builder /app/commercify /app/commercify
COPY --from=builder /app/commercify-migrate /app/commercify-migrate
COPY --from=builder /app/commercify-seed /app/commercify-seed
COPY --from=builder /app/migrations /app/migrations
COPY --from=builder /app/templates /app/templates

# Copy .env file if it exists (will be overridden by env_file in docker-compose)
# COPY --from=builder /app/.env /app/

# Set executable permissions for all binaries
RUN chmod +x /app/commercify /app/commercify-migrate /app/commercify-seed

# Expose the port
EXPOSE 6091

# Run the API by default
CMD ["/app/commercify"]
12 changes: 6 additions & 6 deletions cmd/seed/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ func main() {
fmt.Println("Shipping rates seeded successfully")
}

if *allFlag || *webhooksFlag {
if err := seedWebhooks(db); err != nil {
log.Fatalf("Failed to seed webhooks: %v", err)
}
fmt.Println("Webhooks seeded successfully")
}
// if *allFlag || *webhooksFlag {
// if err := seedWebhooks(db); err != nil {
// log.Fatalf("Failed to seed webhooks: %v", err)
// }
// fmt.Println("Webhooks seeded successfully")
// }

if *allFlag || *cartsFlag {
if err := seedCarts(db); err != nil {
Expand Down
17 changes: 16 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Config struct {
Stripe StripeConfig
PayPal PayPalConfig
MobilePay MobilePayConfig
CORS CORSConfig
}

// ServerConfig holds server-specific configuration
Expand Down Expand Up @@ -64,13 +65,15 @@ type StripeConfig struct {
PublicKey string
WebhookSecret string
PaymentDescription string
ReturnURL string
Enabled bool
}

// PayPalConfig holds PayPal-specific configuration
type PayPalConfig struct {
ClientID string
ClientSecret string
ReturnURL string
Sandbox bool
Enabled bool
}
Expand All @@ -89,6 +92,12 @@ type MobilePayConfig struct {
IsTestMode bool
}

// CORSConfig holds CORS-specific configuration
type CORSConfig struct {
AllowedOrigins []string
AllowAllOrigins bool
}

// LoadConfig loads configuration from environment variables
func LoadConfig() (*Config, error) {
readTimeout, err := strconv.Atoi(getEnv("SERVER_READ_TIMEOUT", "15"))
Expand Down Expand Up @@ -189,11 +198,13 @@ func LoadConfig() (*Config, error) {
PublicKey: getEnv("STRIPE_PUBLIC_KEY", ""),
WebhookSecret: getEnv("STRIPE_WEBHOOK_SECRET", ""),
PaymentDescription: getEnv("STRIPE_PAYMENT_DESCRIPTION", "Commercify Store Purchase"),
ReturnURL: getEnv("RETURN_URL", ""),
Enabled: stripeEnabled,
},
PayPal: PayPalConfig{
ClientID: getEnv("PAYPAL_CLIENT_ID", ""),
ClientSecret: getEnv("PAYPAL_CLIENT_SECRET", ""),
ReturnURL: getEnv("RETURN_URL", ""),
Sandbox: paypalSandbox,
Enabled: paypalEnabled,
},
Expand All @@ -202,13 +213,17 @@ func LoadConfig() (*Config, error) {
SubscriptionKey: getEnv("MOBILEPAY_SUBSCRIPTION_KEY", ""),
ClientID: getEnv("MOBILEPAY_CLIENT_ID", ""),
ClientSecret: getEnv("MOBILEPAY_CLIENT_SECRET", ""),
ReturnURL: getEnv("MOBILEPAY_RETURN_URL", ""),
ReturnURL: getEnv("RETURN_URL", ""),
WebhookURL: getEnv("MOBILEPAY_WEBHOOK_URL", ""),
PaymentDescription: getEnv("MOBILEPAY_PAYMENT_DESCRIPTION", "Commercify Store Purchase"),
Market: getEnv("MOBILEPAY_MARKET", "NOK"),
Enabled: mobilePayEnabled,
IsTestMode: mobilePayTestMode,
},
CORS: CORSConfig{
AllowedOrigins: []string{"*"},
AllowAllOrigins: true,
},
}, nil
}

Expand Down
111 changes: 111 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
services:
# PostgreSQL database service
postgres:
image: postgres:15-alpine
container_name: commercify-postgres
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: commercify
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 10s
timeout: 5s
retries: 5

# Commercify API service
api:
build:
context: .
dockerfile: Dockerfile
container_name: commercify-api
env_file:
- .env
environment:
DB_HOST: postgres
DB_PORT: 5432
DB_USER: postgres
DB_PASSWORD: postgres
DB_NAME: commercify

# AUTH_JWT_SECRET: ${AUTH_JWT_SECRET}

# EMAIL_ENABLED: ${EMAIL_ENABLED:-false}
# EMAIL_SMTP_HOST: ${EMAIL_SMTP_HOST}
# EMAIL_SMTP_PORT: ${EMAIL_SMTP_PORT}
# EMAIL_SMTP_USERNAME: ${EMAIL_SMTP_USERNAME}
# EMAIL_SMTP_PASSWORD: ${EMAIL_SMTP_PASSWORD}
# EMAIL_FROM_ADDRESS: ${EMAIL_FROM_ADDRESS}
# EMAIL_FROM_NAME: ${EMAIL_FROM_NAME}
# EMAIL_ADMIN_ADDRESS: ${EMAIL_ADMIN_ADDRESS}

# STRIPE_ENABLED: ${STRIPE_ENABLED:-false}
# STRIPE_SECRET_KEY: ${STRIPE_SECRET_KEY}
# STRIPE_PUBLIC_KEY: ${STRIPE_PUBLIC_KEY}
# STRIPE_WEBHOOK_SECRET: ${STRIPE_WEBHOOK_SECRET}
# STRIPE_PAYMENT_DESCRIPTION: ${STRIPE_PAYMENT_DESCRIPTION}

# PAYPAL_ENABLED: ${PAYPAL_ENABLED:-false}
# PAYPAL_CLIENT_ID: ${PAYPAL_CLIENT_ID}
# PAYPAL_CLIENT_SECRET: ${PAYPAL_CLIENT_SECRET}
# PAYPAL_SANDBOX: ${PAYPAL_SANDBOX:-true}

# MOBILEPAY_ENABLED: ${MOBILEPAY_ENABLED:-false}
# MOBILEPAY_TEST_MODE: ${MOBILEPAY_TEST_MODE:-true}
# MOBILEPAY_MERCHANT_SERIAL_NUMBER: ${MOBILEPAY_MERCHANT_SERIAL_NUMBER}
# MOBILEPAY_SUBSCRIPTION_KEY: ${MOBILEPAY_SUBSCRIPTION_KEY}
# MOBILEPAY_CLIENT_ID: ${MOBILEPAY_CLIENT_ID}
# MOBILEPAY_CLIENT_SECRET: ${MOBILEPAY_CLIENT_SECRET}
# MOBILEPAY_RETURN_URL: ${MOBILEPAY_RETURN_URL}
# MOBILEPAY_WEBHOOK_URL: ${MOBILEPAY_WEBHOOK_URL}
# MOBILEPAY_PAYMENT_DESCRIPTION: ${MOBILEPAY_PAYMENT_DESCRIPTION}
# MOBILEPAY_MARKET: ${MOBILEPAY_MARKET:-dk}

ports:
- "6091:6091"
restart: unless-stopped
depends_on:
postgres:
condition: service_healthy

# Convenience services for database operations
migrate:
build:
context: .
dockerfile: Dockerfile
profiles: ["tools"]
entrypoint: ["/app/commercify-migrate"]
command: ["-up"]
environment:
DB_HOST: postgres
DB_PORT: 5432
DB_USER: postgres
DB_PASSWORD: postgres
DB_NAME: commercify
depends_on:
postgres:
condition: service_healthy

seed:
build:
context: .
dockerfile: Dockerfile
profiles: ["tools"]
entrypoint: ["/app/commercify-seed"]
command: ["-all"]
environment:
DB_HOST: postgres
DB_PORT: 5432
DB_USER: postgres
DB_PASSWORD: postgres
DB_NAME: commercify
depends_on:
postgres:
condition: service_healthy

volumes:
postgres_data:
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/joho/godotenv v1.5.1
github.com/lib/pq v1.10.9
github.com/stretchr/testify v1.10.0
github.com/stripe/stripe-go/v72 v72.122.0
github.com/stripe/stripe-go/v82 v82.1.0
golang.org/x/crypto v0.37.0
)

Expand Down
13 changes: 2 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dhui/dktest v0.4.5 h1:uUfYBIVREmj/Rw6MvgmqNAYzTiKOHJak+enB5Di73MM=
Expand Down Expand Up @@ -56,12 +55,10 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stripe/stripe-go/v72 v72.122.0 h1:eRXWqnEwGny6dneQ5BsxGzUCED5n180u8n665JHlut8=
github.com/stripe/stripe-go/v72 v72.122.0/go.mod h1:QwqJQtduHubZht9mek5sds9CtQcKFdsykV9ZepRWwo0=
github.com/stripe/stripe-go/v82 v82.1.0 h1:+05j4HAaC4vrkLo98e8CvJ3SeGVylij0kYPTOLeTYGg=
github.com/stripe/stripe-go/v82 v82.1.0/go.mod h1:majCQX6AfObAvJiHraPi/5udwHi4ojRvJnnxckvHrX8=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 h1:TT4fX+nBOA/+LUkobKGW1ydGcn+G3vRw9+g5HwCphpk=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0/go.mod h1:L7UH0GbB0p47T4Rri3uHjbpCFYrVrwc1I25QhNPiGK8=
go.opentelemetry.io/otel v1.29.0 h1:PdomN/Al4q/lN6iBJEN3AwPvUiHPMlt93c8bqTG5Llw=
Expand All @@ -72,21 +69,15 @@ go.opentelemetry.io/otel/trace v1.29.0 h1:J/8ZNK4XgR7a21DZUAsbF8pZ5Jcw1VhACmnYt3
go.opentelemetry.io/otel/trace v1.29.0/go.mod h1:eHl3w0sp3paPkYstJOmAimxhiFXPg+MMTlEh3nsQgWQ=
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.37.0 h1:kJNSjF/Xp7kU0iB2Z+9viTPMW4EqqsrywMXLJOOsXSE=
golang.org/x/crypto v0.37.0/go.mod h1:vg+k43peMZ0pUMhYmVAWysMK35e6ioLh3wB8ZCAfbVc=
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8=
golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20=
golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0=
golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Loading