reconfigure docker/caddy/build

This commit is contained in:
Timothy Pidashev
2024-09-06 20:52:04 -07:00
parent 2fcdf6272e
commit 0ff2116794
8 changed files with 119 additions and 18 deletions

View File

@@ -0,0 +1,5 @@
dev.timmypidashev.dev {
tls internal
reverse_proxy web:3000
}

View File

@@ -0,0 +1,5 @@
timmypidashev.dev {
tls pidashev.tim@gmail.com
reverse_proxy web:3000
}

27
.docker/Dockerfile.dev Normal file
View File

@@ -0,0 +1,27 @@
FROM node:22-alpine
ARG CONTAINER_WEB_VERSION
ARG ENVIRONMENT
ARG BUILD_DATE
ARG GIT_COMMIT
RUN set -eux \
& apk add \
--no-cache \
nodejs \
curl
RUN curl -L https://unpkg.com/@pnpm/self-installer | node
WORKDIR /app
COPY . .
RUN echo "PUBLIC_VERSION=${CONTAINER_WEB_VERSION}" > /app/.env && \
echo "PUBLIC_ENVIRONMENT=${ENVIRONMENT}" >> /app/.env && \
echo "PUBLIC_BUILD_DATE=${BUILD_DATE}" >> /app/.env && \
echo "PUBLIC_GIT_COMMIT=${GIT_COMMIT}" >> /app/.env
EXPOSE 3000
CMD pnpm install && pnpm run dev

View File

@@ -0,0 +1,32 @@
from node:22-alpine
WORKDIR /app
RUN set -eux \
& apk add \
--no-cache \
nodejs \
curl
COPY package.json pnpm-lock.yaml ./
ARG CONTAINER_WEB_VERSION
ARG ENVIRONMENT
ARG BUILD_DATE
ARG GIT_COMMIT
RUN echo "PUBLIC_VERSION=${CONTAINER_FHCC_VERSION}" > /app/.env && \
echo "PUBLIC_ENVIRONMENT=${ENVIRONMENT}" >> /app/.env && \
echo "PUBLIC_BUILD_DATE=${BUILD_DATE}" >> /app/.env && \
echo "PUBLIC_GIT_COMMIT=${GIT_COMMIT}" >> /app/.env
RUN pnpm install --frozen-lockfile --production
RUN pnpm run build
FROM node:22-alpine
WORKDIR /app
EXPOSE 3000
CMD node ./dist/server/entry.mjs
COPY --from=builder /app/.dist ./

1
.gitignore vendored
View File

@@ -3,6 +3,7 @@
# dependencies # dependencies
node_modules/ node_modules/
/.pnp /.pnp
.pnpm-store
.pnp.js .pnp.js
.yarn/install-state.gz .yarn/install-state.gz

View File

@@ -8,7 +8,7 @@ PROJECT_ORGANIZATION := "org.opencontainers"
CONTAINER_WEB_NAME := "web" CONTAINER_WEB_NAME := "web"
CONTAINER_WEB_VERSION := "v1.0.0" CONTAINER_WEB_VERSION := "v1.0.0"
CONTAINER_WEB_LOCATION := "src/web" CONTAINER_WEB_LOCATION := "src/"
CONTAINER_WEB_DESCRIPTION := "My portfolio website!" CONTAINER_WEB_DESCRIPTION := "My portfolio website!"
.DEFAULT_GOAL := help .DEFAULT_GOAL := help
@@ -17,7 +17,7 @@ CONTAINER_WEB_DESCRIPTION := "My portfolio website!"
help: help:
@echo "Available targets:" @echo "Available targets:"
@echo " run - Runs the docker compose file with the specified environment (dev or prod)" @echo " run - Runs the docker compose file with the specified environment (dev or release)"
@echo " build - Builds the specified docker image with the appropriate environment" @echo " build - Builds the specified docker image with the appropriate environment"
@echo " push - Pushes the built docker image to the registry" @echo " push - Pushes the built docker image to the registry"
@echo " prune - Removes all built and cached docker images and containers" @echo " prune - Removes all built and cached docker images and containers"
@@ -25,19 +25,19 @@ help:
run: run:
# Arguments: # Arguments:
# [environment]: 'dev' or 'prod' # [environment]: 'dev' or 'release'
# #
# Explanation: # Explanation:
# * Runs the docker compose file with the specified environment(compose.dev.yml, or compose.prod.yml) # * Runs the docker compose file with the specified environment(compose.dev.yml, or compose.release.yml)
# * Passes all generated arguments to the compose file. # * Passes all generated arguments to the compose file.
# Make sure we have been given proper arguments. # Make sure we have been given proper arguments.
@if [ "$(word 2,$(MAKECMDGOALS))" = "dev" ]; then \ @if [ "$(word 2,$(MAKECMDGOALS))" = "dev" ]; then \
echo "Running in development environment"; \ echo "Running in development environment"; \
elif [ "$(word 2,$(MAKECMDGOALS))" = "prod" ]; then \ elif [ "$(word 2,$(MAKECMDGOALS))" = "release" ]; then \
echo "Running in production environment"; \ echo "Running in release environment"; \
else \ else \
echo "Invalid usage. Please use 'make run dev' or 'make run prod'"; \ echo "Invalid usage. Please use 'make run dev' or 'make run release'"; \
exit 1; \ exit 1; \
fi fi
@@ -47,7 +47,7 @@ run:
build: build:
# Arguments # Arguments
# [container]: Build context(which container to build ['all' to build every container defined]) # [container]: Build context(which container to build ['all' to build every container defined])
# [environment]: 'dev' or 'prod' # [environment]: 'dev' or 'release'
# #
# Explanation: # Explanation:
# * Builds the specified docker image with the appropriate environment. # * Builds the specified docker image with the appropriate environment.
@@ -161,16 +161,16 @@ define container_build
@echo "Environment: $(ENVIRONMENT)" @echo "Environment: $(ENVIRONMENT)"
@echo "Version: $(VERSION)" @echo "Version: $(VERSION)"
@if [ "$(strip $(ENVIRONMENT))" != "dev" ] && [ "$(strip $(ENVIRONMENT))" != "prod" ]; then \ @if [ "$(strip $(ENVIRONMENT))" != "dev" ] && [ "$(strip $(ENVIRONMENT))" != "release" ]; then \
echo "Invalid environment. Please specify 'dev' or 'prod'"; \ echo "Invalid environment. Please specify 'dev' or 'release'"; \
exit 1; \ exit 1; \
fi fi
$(if $(filter $(strip $(ENVIRONMENT)),prod), \ $(if $(filter $(strip $(ENVIRONMENT)),release), \
$(eval TAG := $(PROJECT_REGISTRY)/$(CONTAINER):$(VERSION)), \ $(eval TAG := $(PROJECT_REGISTRY)/$(CONTAINER):$(VERSION)), \
) )
docker buildx build --load -t $(TAG) -f $(strip $(subst $(SPACE),,$(call container_location,$(CONTAINER))))/Dockerfile.$(ENVIRONMENT) ./$(strip $(subst $(SPACE),,$(call container_location,$(CONTAINER))))/. $(ARGS) $(call labels,$(shell echo $(CONTAINER_NAME) | tr '[:lower:]' '[:upper:]')) --no-cache docker buildx build --load -t $(TAG) -f .docker/Dockerfile.$(ENVIRONMENT) ./$(strip $(subst $(SPACE),,$(call container_location,$(CONTAINER))))/. $(ARGS) $(call labels,$(shell echo $(CONTAINER_NAME) | tr '[:lower:]' '[:upper:]')) --no-cache
endef endef
define container_location define container_location

View File

@@ -0,0 +1,33 @@
services:
caddy:
container_name: proxy
image: caddy:latest
ports:
- 80:80
- 443:443
volumes:
- ./.caddy/Caddyfile.dev:/etc/caddy/Caddyfile:rw
networks:
- proxy
depends_on:
- web
web:
container_name: web
image: web:dev
volumes:
- ./src/astro.config.mjs:/app/astro.config.mjs
- ./src/sandbox.config.json:/app/sandbox.config.json
- ./src/tailwind.config.cjs:/app/tailwind.config.cjs
- ./src/tsconfig.json:/app/tsconfig.json
- ./src/pnpm-lock.yaml:/app/pnpm-lock.yaml
- ./src/package.json:/app/package.json
- ./src/public:/app/public
- ./src/src:/app/src
networks:
- proxy
networks:
proxy:
name: proxy
external: true

View File

@@ -1,13 +1,11 @@
{ {
"name": "src", "name": "src",
"version": "0.0.1", "version": "v1.0.1",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "astro dev", "dev": "astro dev --host",
"start": "astro dev",
"build": "astro build", "build": "astro build",
"preview": "astro preview", "preview": "astro preview"
"astro": "astro"
}, },
"devDependencies": { "devDependencies": {
"@astrojs/tailwind": "3.1.1", "@astrojs/tailwind": "3.1.1",
@@ -17,4 +15,4 @@
"postcss": "8.4.21", "postcss": "8.4.21",
"tailwindcss": "3.2.7" "tailwindcss": "3.2.7"
} }
} }