Refactor Docker setup for development environment: rename compose file, update service configurations, and VSCode settings

This commit is contained in:
Luis Eduardo
2025-02-02 04:20:01 +00:00
parent d7612836e6
commit eb0f8870e7
8 changed files with 94 additions and 205 deletions

View File

@@ -1,18 +1,15 @@
name: pgbackweb-dev
services:
app:
container_name: pbw_app
devcontainer:
container_name: pbw_devcontainer
build:
context: ../
dockerfile: ./docker/Dockerfile.dev
ports:
- "8085:8085"
volumes:
- ../:/app
- pbw_vol_app_ssh:/root/.ssh
- pbw_vol_app_gh:/root/.config/gh
- pbw_vol_app_go_mod_cache:/root/go/pkg/mod
- ../..:/workspaces:cached
networks:
- pbw_network
depends_on:
@@ -53,7 +50,7 @@ services:
- "9090:9090"
environment:
MINIO_ROOT_USER: "root"
MINIO_ROOT_PASSWORD: "password"
MINIO_ROOT_PASSWORD: "root"
volumes:
- pbw_vol_minio:/data
command: minio server /data/minio --console-address ":9090"
@@ -61,9 +58,6 @@ services:
- pbw_network
volumes:
pbw_vol_app_ssh:
pbw_vol_app_gh:
pbw_vol_app_go_mod_cache:
pbw_vol_postgres:
pbw_vol_minio:

View File

@@ -0,0 +1,85 @@
{
"dockerComposeFile": "./compose.yaml",
"service": "devcontainer",
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
"customizations": {
"vscode": {
"extensions": [
"golang.go",
"bradlc.vscode-tailwindcss",
"standard.vscode-standard",
"denoland.vscode-deno",
"mhutchie.git-graph",
"mutantdino.resourcemonitor",
"Compile-TomaszKasperczyk.copy-to-llm"
],
"settings": {
/////
// Editor settings
/////
"editor.formatOnSave": true,
"editor.foldingStrategy": "indentation",
"editor.rulers": [
80
],
"files.eol": "\n",
/////
// Language specific settings
/////
"[json]": {
"editor.defaultFormatter": "vscode.json-language-features"
},
"[jsonc]": {
"editor.defaultFormatter": "vscode.json-language-features"
},
// JavaScript & Standard
"standard.enable": true,
"standard.autoFixOnSave": true,
"[typescript]": {
"editor.defaultFormatter": "denoland.vscode-deno"
},
"[javascript]": {
"editor.defaultFormatter": "standard.vscode-standard"
},
"[css]": {
"editor.defaultFormatter": "vscode.css-language-features"
},
"[html]": {
"editor.defaultFormatter": "vscode.html-language-features"
},
"[markdown]": {
"editor.defaultFormatter": "vscode.markdown-language-features"
},
// Go & Golangci-lint
"[go]": {
"editor.defaultFormatter": "golang.go"
},
"go.lintTool": "golangci-lint",
"go.lintFlags": [
"--fast"
],
// Deno
"deno.enable": true,
"deno.enablePaths": [
"./scripts"
],
/////
// Tailwind CSS + NodX
/////
"tailwindCSS.includeLanguages": {
"go": "go"
},
"tailwindCSS.experimental.classRegex": [
[
"Class\\(([^)]*)\\)",
"[\"`]([^\"`]*)[\"`]"
], // Class("...") or Class(`...`)
[
"ClassMap\\{([^)]*)\\}",
"[\"`]([^\"`]*)[\"`]"
] // ClassMap{"..."} or ClassMap{`...`}
]
}
}
}
}

View File

@@ -11,4 +11,4 @@ PBW_ENCRYPTION_KEY="encryption-key"
# Database connection string for a PostgreSQL database where the pgbackweb
# will store its data.
PBW_POSTGRES_CONN_STRING="postgresql://postgres:password@host.docker.internal:5432/pgbackweb?sslmode=disable"
PBW_POSTGRES_CONN_STRING="postgresql://postgres:password@pbw_postgres:5432/pgbackweb?sslmode=disable"

View File

@@ -1,7 +0,0 @@
{
"recommendations": [
"golang.go",
"bradlc.vscode-tailwindcss",
"standard.vscode-standard"
]
}

69
.vscode/settings.json vendored
View File

@@ -1,69 +0,0 @@
{
/////
// Editor settings
/////
"editor.formatOnSave": true,
"editor.foldingStrategy": "indentation",
"editor.rulers": [
80
],
"files.eol": "\n",
/////
// Language specific settings
/////
"[json]": {
"editor.defaultFormatter": "vscode.json-language-features"
},
"[jsonc]": {
"editor.defaultFormatter": "vscode.json-language-features"
},
// JavaScript & Standard
"standard.enable": true,
"standard.autoFixOnSave": true,
"[javascript]": {
"editor.defaultFormatter": "standard.vscode-standard"
},
"[css]": {
"editor.defaultFormatter": "vscode.css-language-features"
},
"[html]": {
"editor.defaultFormatter": "vscode.html-language-features"
},
"[markdown]": {
"editor.defaultFormatter": "vscode.markdown-language-features"
},
"[go]": {
"editor.defaultFormatter": "golang.go"
},
/////
// Tailwind CSS + Gomponents
// https://gist.github.com/eduardolat/438a1de077ccac6b9792153e708c1824
/////
"tailwindCSS.includeLanguages": {
"go": "go",
},
"tailwindCSS.experimental.classRegex": [
[
"Class\\(([^)]*)\\)",
"[\"`]([^\"`]*)[\"`]"
], // Class("...") or Class(`...`)
[
"Classes\\(([^)]*)\\)",
"[\"`]([^\"`]*)[\"`]"
], // Classes("...") or Classes(`...`)
[
"Class\\{([^)]*)\\}",
"[\"`]([^\"`]*)[\"`]"
], // Class{"..."} or Class{`...`}
[
"Classes\\{([^)]*)\\}",
"[\"`]([^\"`]*)[\"`]"
], // Classes{"..."} or Classes{`...`}
[
"Class:\\s*[\"`]([^\"`]*)[\"`]"
], // Class: "..." or Class: `...`
[
"Classes:\\s*[\"`]([^\"`]*)[\"`]"
], // Classes: "..." or Classes: `...`
]
}

View File

@@ -1,98 +0,0 @@
# To make sure we have the node, and golang binaries
FROM node:20.17.0-bookworm AS node
FROM golang:1.23.1-bookworm AS golang
# Set the base image, general environment variables, and move to temp dir
FROM debian:12.7
ENV DEBIAN_FRONTEND=noninteractive
ENV PATH="$PATH:/usr/local/go/bin"
WORKDIR /app/temp
# Copy node binaries
COPY --from=node /usr/local/bin/ /usr/local/bin/
COPY --from=node /usr/local/include/ /usr/local/include/
COPY --from=node /usr/local/lib/ /usr/local/lib/
COPY --from=node /usr/local/share/ /usr/local/share/
# Copy the golang binaries
COPY --from=golang /usr/local/go /usr/local/go
# Add PostgreSQL repository and install system dependencies
# https://www.postgresql.org/download/linux/debian/
RUN apt update && apt install -y postgresql-common && \
/usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y && \
apt update && apt install -y \
wget unzip tzdata git \
postgresql-client-13 postgresql-client-14 \
postgresql-client-15 postgresql-client-16 && \
rm -rf /var/lib/apt/lists/*
# Install downloadable binaries
RUN set -e && \
if [ "${TARGETPLATFORM}" = "linux/arm64" ]; then \
# Install task
wget --no-verbose https://github.com/go-task/task/releases/download/v3.38.0/task_linux_arm64.tar.gz && \
tar -xzf task_linux_arm64.tar.gz && \
mv ./task /usr/local/bin/task && \
# Install goose
wget --no-verbose https://github.com/pressly/goose/releases/download/v3.22.0/goose_linux_arm64 && \
mv ./goose_linux_arm64 /usr/local/bin/goose && \
# Install sqlc
wget --no-verbose https://github.com/sqlc-dev/sqlc/releases/download/v1.27.0/sqlc_1.27.0_linux_arm64.tar.gz && \
tar -xzf sqlc_1.27.0_linux_arm64.tar.gz && \
mv ./sqlc /usr/local/bin/sqlc && \
# Install golangci-lint
wget --no-verbose https://github.com/golangci/golangci-lint/releases/download/v1.60.3/golangci-lint-1.60.3-linux-arm64.tar.gz && \
tar -xzf golangci-lint-1.60.3-linux-arm64.tar.gz && \
mv ./golangci-lint-1.60.3-linux-arm64/golangci-lint /usr/local/bin/golangci-lint && \
# Install air
wget --no-verbose https://github.com/air-verse/air/releases/download/v1.52.3/air_1.52.3_linux_arm64 && \
mv ./air_1.52.3_linux_arm64 /usr/local/bin/air; \
else \
# Install task
wget --no-verbose https://github.com/go-task/task/releases/download/v3.38.0/task_linux_amd64.tar.gz && \
tar -xzf task_linux_amd64.tar.gz && \
mv ./task /usr/local/bin/task && \
# Install goose
wget --no-verbose https://github.com/pressly/goose/releases/download/v3.22.0/goose_linux_x86_64 && \
mv ./goose_linux_x86_64 /usr/local/bin/goose && \
# Install sqlc
wget --no-verbose https://github.com/sqlc-dev/sqlc/releases/download/v1.27.0/sqlc_1.27.0_linux_amd64.tar.gz && \
tar -xzf sqlc_1.27.0_linux_amd64.tar.gz && \
mv ./sqlc /usr/local/bin/sqlc && \
# Install golangci-lint
wget --no-verbose https://github.com/golangci/golangci-lint/releases/download/v1.60.3/golangci-lint-1.60.3-linux-amd64.tar.gz && \
tar -xzf golangci-lint-1.60.3-linux-amd64.tar.gz && \
mv ./golangci-lint-1.60.3-linux-amd64/golangci-lint /usr/local/bin/golangci-lint && \
# Install air
wget --no-verbose https://github.com/air-verse/air/releases/download/v1.52.3/air_1.52.3_linux_amd64 && \
mv ./air_1.52.3_linux_amd64 /usr/local/bin/air; \
fi && \
# Make binaries executable
chmod +x /usr/local/bin/task && \
chmod +x /usr/local/bin/goose && \
chmod +x /usr/local/bin/sqlc && \
chmod +x /usr/local/bin/golangci-lint && \
chmod +x /usr/local/bin/air
# Go to the app dir, delete the temporary dir and create backups dir
WORKDIR /app
RUN rm -rf /app/temp && \
mkdir /backups && \
chmod 777 /backups
##############
# START HERE #
##############
# Copy and install nodejs dependencies
COPY package.json .
RUN npm install
# Copy and install go dependencies
COPY go.mod .
COPY go.sum .
RUN go mod download
# Copy the rest of the files
COPY . .

View File

@@ -91,4 +91,4 @@ RUN echo "\n\n" >> /root/.bashrc && \
cat /usr/local/bin/startup.sh >> /root/.bashrc
# Command just to keep the container running
CMD ["tail", "-f", "/dev/null"]
CMD ["sleep", "infinity"]

View File

@@ -1,25 +1,9 @@
# Docker
This folder is responsible for storing all Dockerfiles for the different Docker images required for the project. IT IS IMPERATIVE that all images have the same dependencies and versions to ensure consistency and reproducibility across different environments.
To make sure they are identical, please always ensure that all instructions in the Dockerfiles are exactly the same up to the following comment:
```Dockerfile
##############
# START HERE #
##############
```
After the above comment, you can add the necessary instructions for the specific image. Please replicate all dependencies and environment-related instructions in all Dockerfiles.
This folder stores all Dockerfiles required for the project. It is imperative that both images have the same dependencies and versions for consistency and reproducibility across environments.
## Dockerfile
The `Dockerfile` file is the one used for building the production image.
The Dockerfile is used for building the production image that will be published for production environments. It should only contain what is strictly required to run the application.
## Dockerfile.dev
The `Dockerfile.dev` file is the one used for building the development environment image.
## Dockerfile.cicd
The `Dockerfile.cicd` file is the one used for building the CI/CD environment image.
The Dockerfile.dev is used for building the development (e.g., devcontainers) and CI environment image. It includes all dependencies included in Dockerfile and others needed for development and testing.