From eb0f8870e7d2030f287dfc0f8ef7a1a8deebed7e Mon Sep 17 00:00:00 2001 From: Luis Eduardo Date: Sun, 2 Feb 2025 04:20:01 +0000 Subject: [PATCH 01/22] Refactor Docker setup for development environment: rename compose file, update service configurations, and VSCode settings --- .../compose.yaml | 14 +-- .devcontainer/devcontainer.json | 85 ++++++++++++++++ .env.dev | 2 +- .vscode/extensions.json | 7 -- .vscode/settings.json | 69 ------------- docker/Dockerfile.cicd | 98 ------------------- docker/Dockerfile.dev | 2 +- docker/README.md | 22 +---- 8 files changed, 94 insertions(+), 205 deletions(-) rename docker/compose.dev.yaml => .devcontainer/compose.yaml (81%) create mode 100644 .devcontainer/devcontainer.json delete mode 100644 .vscode/extensions.json delete mode 100644 .vscode/settings.json delete mode 100644 docker/Dockerfile.cicd diff --git a/docker/compose.dev.yaml b/.devcontainer/compose.yaml similarity index 81% rename from docker/compose.dev.yaml rename to .devcontainer/compose.yaml index 3b9722f..f2c5ac6 100644 --- a/docker/compose.dev.yaml +++ b/.devcontainer/compose.yaml @@ -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: diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..bd89559 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -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{`...`} + ] + } + } + } +} \ No newline at end of file diff --git a/.env.dev b/.env.dev index 37d7ced..c639858 100644 --- a/.env.dev +++ b/.env.dev @@ -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" diff --git a/.vscode/extensions.json b/.vscode/extensions.json deleted file mode 100644 index 99b3852..0000000 --- a/.vscode/extensions.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "recommendations": [ - "golang.go", - "bradlc.vscode-tailwindcss", - "standard.vscode-standard" - ] -} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 2db35ef..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -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: `...` - ] -} \ No newline at end of file diff --git a/docker/Dockerfile.cicd b/docker/Dockerfile.cicd deleted file mode 100644 index 55078b7..0000000 --- a/docker/Dockerfile.cicd +++ /dev/null @@ -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 . . diff --git a/docker/Dockerfile.dev b/docker/Dockerfile.dev index 03f10a7..fec8e35 100644 --- a/docker/Dockerfile.dev +++ b/docker/Dockerfile.dev @@ -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"] diff --git a/docker/README.md b/docker/README.md index b8f51b6..d2b289b 100644 --- a/docker/README.md +++ b/docker/README.md @@ -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. From e45054452d461bad5910d42612b0848e482614cb Mon Sep 17 00:00:00 2001 From: Luis Eduardo Date: Sun, 2 Feb 2025 04:29:30 +0000 Subject: [PATCH 02/22] Refactor GitHub Actions workflow for linting, testing, and building: streamline steps and update matrix configuration --- .github/workflows/lint-test-build.yaml | 57 ++++++++++---------------- 1 file changed, 21 insertions(+), 36 deletions(-) diff --git a/.github/workflows/lint-test-build.yaml b/.github/workflows/lint-test-build.yaml index 8ccf065..c5014a7 100644 --- a/.github/workflows/lint-test-build.yaml +++ b/.github/workflows/lint-test-build.yaml @@ -1,47 +1,32 @@ -name: Lint, test & build - +name: Lint, test, and build on: + workflow_dispatch: + pull_request: push: branches: - - main - pull_request: - branches: + - develop - main jobs: - build-test-lint: - name: Build, test & lint - runs-on: ubuntu-latest + lint-test-build: strategy: matrix: - platform: [linux/amd64, linux/arm64] + os: [ubuntu-24.04, ubuntu-24.04-arm] + + name: Lint, test, and build the code + runs-on: ${{ matrix.os }} + timeout-minutes: 20 + steps: - - name: Checkout code + - name: Checkout uses: actions/checkout@v4 - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Build Docker image - run: | - docker buildx create --use - docker buildx build \ - --platform ${{ matrix.platform }} \ - -t pbw-test-${{ matrix.platform }}:latest \ - -f ./docker/Dockerfile.cicd \ - --load . - - - name: Run dependencies check - run: docker run --rm --platform ${{ matrix.platform }} pbw-test-${{ matrix.platform }}:latest task check-deps - - - name: Run linter - run: docker run --rm --platform ${{ matrix.platform }} pbw-test-${{ matrix.platform }}:latest task lint-only - - - name: Run tests - run: docker run --rm --platform ${{ matrix.platform }} pbw-test-${{ matrix.platform }}:latest task test-only - - - name: Build project - run: docker run --rm --platform ${{ matrix.platform }} pbw-test-${{ matrix.platform }}:latest task build + - name: Run lint, test, and build + uses: devcontainers/ci@v0.3 + with: + push: never + runCmd: | + task check-deps + task lint-only + task test-only + task build From f874eee6ad60476df0fdbc66f3869783719b8a98 Mon Sep 17 00:00:00 2001 From: Luis Eduardo Date: Sun, 2 Feb 2025 04:40:37 +0000 Subject: [PATCH 03/22] Add dependency installation and permission fix tasks to lint-test-build workflow --- .github/workflows/lint-test-build.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/lint-test-build.yaml b/.github/workflows/lint-test-build.yaml index 2456850..714833f 100644 --- a/.github/workflows/lint-test-build.yaml +++ b/.github/workflows/lint-test-build.yaml @@ -29,6 +29,9 @@ jobs: with: push: never runCmd: | + npm install + go mod download + task fixperms task check-deps task lint-only task test-only From 61858315f00bea7b8a978ed6c810b08221caec3c Mon Sep 17 00:00:00 2001 From: Luis Eduardo Date: Mon, 3 Feb 2025 02:40:57 +0000 Subject: [PATCH 04/22] Enhance Dockerfile to validate TARGETPLATFORM for multi-arch builds --- docker/Dockerfile | 9 +++++---- docker/Dockerfile.dev | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 3065e0c..8591f8c 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,6 +1,3 @@ -# Declare the target platform to support multi-arch builds -ARG TARGETPLATFORM - # 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 @@ -8,9 +5,13 @@ FROM golang:1.23.1-bookworm AS golang # Set the base image FROM debian:12.7 -# Re-declare ARG after FROM to make it available in this build stage +# Declare ARG to make it available in the RUN commands ARG TARGETPLATFORM RUN echo "Building for ${TARGETPLATFORM}" +RUN if [ "${TARGETPLATFORM}" != "linux/amd64" ] && [ "${TARGETPLATFORM}" != "linux/arm64" ]; then \ + echo "Unsupported architecture: ${TARGETPLATFORM}" && \ + exit 1; \ + fi # Set the general environment variables, and move to temp dir ENV DEBIAN_FRONTEND="noninteractive" diff --git a/docker/Dockerfile.dev b/docker/Dockerfile.dev index 8d778cd..7cca7fc 100644 --- a/docker/Dockerfile.dev +++ b/docker/Dockerfile.dev @@ -1,6 +1,3 @@ -# Declare the target platform to support multi-arch builds -ARG TARGETPLATFORM - # 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 @@ -8,9 +5,13 @@ FROM golang:1.23.1-bookworm AS golang # Set the base image FROM debian:12.7 -# Re-declare ARG after FROM to make it available in this build stage +# Declare ARG to make it available in the RUN commands ARG TARGETPLATFORM RUN echo "Building for ${TARGETPLATFORM}" +RUN if [ "${TARGETPLATFORM}" != "linux/amd64" ] && [ "${TARGETPLATFORM}" != "linux/arm64" ]; then \ + echo "Unsupported architecture: ${TARGETPLATFORM}" && \ + exit 1; \ + fi # Set the general environment variables, and move to temp dir ENV DEBIAN_FRONTEND="noninteractive" From 54fa7514db43d0e5f7b2e42614363f31b9f35c98 Mon Sep 17 00:00:00 2001 From: Luis Eduardo Date: Mon, 3 Feb 2025 02:41:03 +0000 Subject: [PATCH 05/22] Refactor lint-test-build workflow to support multi-platform builds with updated matrix configuration --- .github/workflows/lint-test-build.yaml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint-test-build.yaml b/.github/workflows/lint-test-build.yaml index 714833f..5f75aaa 100644 --- a/.github/workflows/lint-test-build.yaml +++ b/.github/workflows/lint-test-build.yaml @@ -14,10 +14,13 @@ jobs: lint-test-build: strategy: matrix: - os: [ubuntu-24.04, ubuntu-24.04-arm] + vars: [ + {os: ubuntu-24.04, platform: linux/amd64}, + {os: ubuntu-24.04-arm, platform: linux/arm64} + ] name: Lint, test, and build the code - runs-on: ${{ matrix.os }} + runs-on: ${{ matrix.vars.os }} timeout-minutes: 20 steps: @@ -27,6 +30,7 @@ jobs: - name: Run lint, test, and build uses: devcontainers/ci@v0.3 with: + platform: ${{ matrix.vars.platform }} push: never runCmd: | npm install From 277784d4ff6e963b7dc87dbd9ac16879fd8b6349 Mon Sep 17 00:00:00 2001 From: Luis Eduardo Date: Mon, 3 Feb 2025 02:44:56 +0000 Subject: [PATCH 06/22] Optimize command execution in lint-test-build workflow for improved efficiency --- .github/workflows/lint-test-build.yaml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/lint-test-build.yaml b/.github/workflows/lint-test-build.yaml index 5f75aaa..da11096 100644 --- a/.github/workflows/lint-test-build.yaml +++ b/.github/workflows/lint-test-build.yaml @@ -32,11 +32,11 @@ jobs: with: platform: ${{ matrix.vars.platform }} push: never - runCmd: | - npm install - go mod download - task fixperms - task check-deps - task lint-only - task test-only + runCmd: > + npm install && \ + go mod download && \ + task fixperms && \ + task check-deps && \ + task lint-only && \ + task test-only && \ task build From 90d4adbf08b0a6ca35cbb434ad2b1b11c06d2c43 Mon Sep 17 00:00:00 2001 From: Luis Eduardo Date: Mon, 3 Feb 2025 03:20:13 +0000 Subject: [PATCH 07/22] Add Docker buildx setup for multi-architecture builds in lint-test-build workflow --- .github/workflows/lint-test-build.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/lint-test-build.yaml b/.github/workflows/lint-test-build.yaml index da11096..a86a367 100644 --- a/.github/workflows/lint-test-build.yaml +++ b/.github/workflows/lint-test-build.yaml @@ -27,6 +27,11 @@ jobs: - name: Checkout uses: actions/checkout@v4 + - name: Setup Docker buildx for multi-architecture builds + uses: docker/setup-buildx-action@v3 + with: + use: true + - name: Run lint, test, and build uses: devcontainers/ci@v0.3 with: From 2dd479472a9658634dcfda53366590632ba99be7 Mon Sep 17 00:00:00 2001 From: Luis Eduardo Date: Mon, 3 Feb 2025 03:24:16 +0000 Subject: [PATCH 08/22] Simplify Docker buildx setup in lint-test-build workflow by replacing action with direct command --- .github/workflows/lint-test-build.yaml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/lint-test-build.yaml b/.github/workflows/lint-test-build.yaml index a86a367..8f06ffa 100644 --- a/.github/workflows/lint-test-build.yaml +++ b/.github/workflows/lint-test-build.yaml @@ -28,9 +28,7 @@ jobs: uses: actions/checkout@v4 - name: Setup Docker buildx for multi-architecture builds - uses: docker/setup-buildx-action@v3 - with: - use: true + run: docker buildx create --use - name: Run lint, test, and build uses: devcontainers/ci@v0.3 From f38666cd6750d419124f9f4a9f03d330aca2d439 Mon Sep 17 00:00:00 2001 From: Luis Eduardo Date: Mon, 3 Feb 2025 03:28:04 +0000 Subject: [PATCH 09/22] Update lint-test-build workflow to use docker/setup-buildx-action and install Skopeo --- .github/workflows/lint-test-build.yaml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint-test-build.yaml b/.github/workflows/lint-test-build.yaml index 8f06ffa..f14b3da 100644 --- a/.github/workflows/lint-test-build.yaml +++ b/.github/workflows/lint-test-build.yaml @@ -28,7 +28,14 @@ jobs: uses: actions/checkout@v4 - name: Setup Docker buildx for multi-architecture builds - run: docker buildx create --use + uses: docker/setup-buildx-action@v3 + with: + use: true + + - name: Install Skopeo # For some reason required by devcontainers/ci + run: | + sudo apt-get update + sudo apt-get install -y skopeo - name: Run lint, test, and build uses: devcontainers/ci@v0.3 From bcff9d5c13f8ef7b57b9ff670335781ec17cc689 Mon Sep 17 00:00:00 2001 From: Luis Eduardo Date: Mon, 3 Feb 2025 03:42:37 +0000 Subject: [PATCH 10/22] Add devcontainer configuration for CI and update lint-test-build workflow to use it --- .devcontainer/devcontainer-ci.json | 10 ++++++++++ .github/workflows/lint-test-build.yaml | 5 +++-- 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 .devcontainer/devcontainer-ci.json diff --git a/.devcontainer/devcontainer-ci.json b/.devcontainer/devcontainer-ci.json new file mode 100644 index 0000000..2655ac1 --- /dev/null +++ b/.devcontainer/devcontainer-ci.json @@ -0,0 +1,10 @@ +// For the moment --platform is not supported in devcontainers/ci when +// using docker compose, so in this devcontainer config file we are +// using the Dockerfile directly to run actions in CI. +// +// https://github.com/devcontainers/cli/issues/404 +{ + "build": { + "dockerfile": "../docker/Dockerfile.dev" + } +} \ No newline at end of file diff --git a/.github/workflows/lint-test-build.yaml b/.github/workflows/lint-test-build.yaml index f14b3da..166ee1a 100644 --- a/.github/workflows/lint-test-build.yaml +++ b/.github/workflows/lint-test-build.yaml @@ -18,7 +18,7 @@ jobs: {os: ubuntu-24.04, platform: linux/amd64}, {os: ubuntu-24.04-arm, platform: linux/arm64} ] - + name: Lint, test, and build the code runs-on: ${{ matrix.vars.os }} timeout-minutes: 20 @@ -40,8 +40,9 @@ jobs: - name: Run lint, test, and build uses: devcontainers/ci@v0.3 with: - platform: ${{ matrix.vars.platform }} push: never + configFile: .devcontainer/devcontainer-ci.json + platform: ${{ matrix.vars.platform }} runCmd: > npm install && \ go mod download && \ From bccb6e32fe2ff9d0b2cccd2d8f83d35cead12ffa Mon Sep 17 00:00:00 2001 From: Luis Eduardo Date: Mon, 3 Feb 2025 03:47:38 +0000 Subject: [PATCH 11/22] Fix devcontainer configuration by updating the Dockerfile path and context --- .devcontainer/devcontainer-ci.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer-ci.json b/.devcontainer/devcontainer-ci.json index 2655ac1..76b868a 100644 --- a/.devcontainer/devcontainer-ci.json +++ b/.devcontainer/devcontainer-ci.json @@ -5,6 +5,7 @@ // https://github.com/devcontainers/cli/issues/404 { "build": { - "dockerfile": "../docker/Dockerfile.dev" + "context": "..", + "dockerfile": "docker/Dockerfile.dev" } } \ No newline at end of file From f169aabe14b534c8bacc696facdb1b6953adb3b9 Mon Sep 17 00:00:00 2001 From: Luis Eduardo Date: Mon, 3 Feb 2025 03:48:46 +0000 Subject: [PATCH 12/22] Fix devcontainer CI configuration by updating Dockerfile path and context --- .devcontainer/devcontainer-ci.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.devcontainer/devcontainer-ci.json b/.devcontainer/devcontainer-ci.json index 76b868a..4944c60 100644 --- a/.devcontainer/devcontainer-ci.json +++ b/.devcontainer/devcontainer-ci.json @@ -5,7 +5,7 @@ // https://github.com/devcontainers/cli/issues/404 { "build": { - "context": "..", - "dockerfile": "docker/Dockerfile.dev" + "context": "../", + "dockerfile": "../docker/Dockerfile.dev" } } \ No newline at end of file From b8c7c11790095816c4194d3db3f14199cc5c4a20 Mon Sep 17 00:00:00 2001 From: Luis Eduardo Date: Mon, 3 Feb 2025 03:51:59 +0000 Subject: [PATCH 13/22] Prepare devcontainer configuration for CI by renaming devcontainer-ci.json --- .github/workflows/lint-test-build.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/lint-test-build.yaml b/.github/workflows/lint-test-build.yaml index 166ee1a..afe3d4a 100644 --- a/.github/workflows/lint-test-build.yaml +++ b/.github/workflows/lint-test-build.yaml @@ -27,6 +27,11 @@ jobs: - name: Checkout uses: actions/checkout@v4 + - name: Prepare devcontainer-ci.json + run: | + rm -f .devcontainer/devcontainer.json + mv .devcontainer/devcontainer-ci.json .devcontainer/devcontainer.json + - name: Setup Docker buildx for multi-architecture builds uses: docker/setup-buildx-action@v3 with: From 3e509ba17aba93707dff44f9ff5f45b3cbabd6ed Mon Sep 17 00:00:00 2001 From: Luis Eduardo Date: Mon, 3 Feb 2025 03:54:14 +0000 Subject: [PATCH 14/22] Remove configFile reference from lint-test-build workflow --- .github/workflows/lint-test-build.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/lint-test-build.yaml b/.github/workflows/lint-test-build.yaml index afe3d4a..abf57b9 100644 --- a/.github/workflows/lint-test-build.yaml +++ b/.github/workflows/lint-test-build.yaml @@ -46,7 +46,6 @@ jobs: uses: devcontainers/ci@v0.3 with: push: never - configFile: .devcontainer/devcontainer-ci.json platform: ${{ matrix.vars.platform }} runCmd: > npm install && \ From edb78f1b2c4fa0b42e3c52f07e37e0a9c6ef511e Mon Sep 17 00:00:00 2001 From: Luis Eduardo Date: Mon, 3 Feb 2025 03:57:58 +0000 Subject: [PATCH 15/22] Reorder preparation of devcontainer configuration in lint-test-build workflow --- .github/workflows/lint-test-build.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/lint-test-build.yaml b/.github/workflows/lint-test-build.yaml index abf57b9..de87bdf 100644 --- a/.github/workflows/lint-test-build.yaml +++ b/.github/workflows/lint-test-build.yaml @@ -27,11 +27,6 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Prepare devcontainer-ci.json - run: | - rm -f .devcontainer/devcontainer.json - mv .devcontainer/devcontainer-ci.json .devcontainer/devcontainer.json - - name: Setup Docker buildx for multi-architecture builds uses: docker/setup-buildx-action@v3 with: @@ -42,6 +37,11 @@ jobs: sudo apt-get update sudo apt-get install -y skopeo + - name: Prepare devcontainer-ci.json + run: | + rm -f .devcontainer/devcontainer.json + mv .devcontainer/devcontainer-ci.json .devcontainer/devcontainer.json + - name: Run lint, test, and build uses: devcontainers/ci@v0.3 with: From b9fb31e60d0351934514b507dcb706325f7db5f3 Mon Sep 17 00:00:00 2001 From: Luis Eduardo Date: Mon, 3 Feb 2025 04:01:46 +0000 Subject: [PATCH 16/22] Update Dockerfile and Dockerfile.dev to streamline PATH environment variable configuration --- docker/Dockerfile | 4 +++- docker/Dockerfile.dev | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 8591f8c..bf219c8 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -15,8 +15,10 @@ RUN if [ "${TARGETPLATFORM}" != "linux/amd64" ] && [ "${TARGETPLATFORM}" != "lin # Set the general environment variables, and move to temp dir ENV DEBIAN_FRONTEND="noninteractive" +ENV PATH="$PATH:/usr/local/go/bin" +ENV PATH="$PATH:/usr/local/go-bin" +ENV PATH="$PATH:/usr/local/dl-bin" ENV GOBIN="/usr/local/go-bin" -ENV PATH="$PATH:/usr/local/go-bin:/usr/local/dl-bin:/usr/local/go/bin" RUN mkdir -p /app/temp /usr/local/go-bin /usr/local/dl-bin WORKDIR /app/temp diff --git a/docker/Dockerfile.dev b/docker/Dockerfile.dev index 7cca7fc..fd87547 100644 --- a/docker/Dockerfile.dev +++ b/docker/Dockerfile.dev @@ -15,8 +15,10 @@ RUN if [ "${TARGETPLATFORM}" != "linux/amd64" ] && [ "${TARGETPLATFORM}" != "lin # Set the general environment variables, and move to temp dir ENV DEBIAN_FRONTEND="noninteractive" +ENV PATH="$PATH:/usr/local/go/bin" +ENV PATH="$PATH:/usr/local/go-bin" +ENV PATH="$PATH:/usr/local/dl-bin" ENV GOBIN="/usr/local/go-bin" -ENV PATH="$PATH:/usr/local/go-bin:/usr/local/dl-bin:/usr/local/go/bin" RUN mkdir -p /app/temp /usr/local/go-bin /usr/local/dl-bin WORKDIR /app/temp From be2422ac7540c7e109fef963976eaf4be4357a90 Mon Sep 17 00:00:00 2001 From: Luis Eduardo Date: Mon, 3 Feb 2025 04:06:25 +0000 Subject: [PATCH 17/22] Remove unnecessary 'go mod download' step from lint-test-build workflow --- .github/workflows/lint-test-build.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/lint-test-build.yaml b/.github/workflows/lint-test-build.yaml index de87bdf..92d5ad2 100644 --- a/.github/workflows/lint-test-build.yaml +++ b/.github/workflows/lint-test-build.yaml @@ -49,7 +49,6 @@ jobs: platform: ${{ matrix.vars.platform }} runCmd: > npm install && \ - go mod download && \ task fixperms && \ task check-deps && \ task lint-only && \ From 53380c9dcf5c20697b3ff6f3d60dd9bacff6c737 Mon Sep 17 00:00:00 2001 From: Luis Eduardo Date: Mon, 3 Feb 2025 04:17:15 +0000 Subject: [PATCH 18/22] Remove devcontainer-ci.json and update lint-test-build workflow to build Docker image directly --- .devcontainer/devcontainer-ci.json | 11 ----------- .github/workflows/lint-test-build.yaml | 22 +++++++--------------- 2 files changed, 7 insertions(+), 26 deletions(-) delete mode 100644 .devcontainer/devcontainer-ci.json diff --git a/.devcontainer/devcontainer-ci.json b/.devcontainer/devcontainer-ci.json deleted file mode 100644 index 4944c60..0000000 --- a/.devcontainer/devcontainer-ci.json +++ /dev/null @@ -1,11 +0,0 @@ -// For the moment --platform is not supported in devcontainers/ci when -// using docker compose, so in this devcontainer config file we are -// using the Dockerfile directly to run actions in CI. -// -// https://github.com/devcontainers/cli/issues/404 -{ - "build": { - "context": "../", - "dockerfile": "../docker/Dockerfile.dev" - } -} \ No newline at end of file diff --git a/.github/workflows/lint-test-build.yaml b/.github/workflows/lint-test-build.yaml index 92d5ad2..896fa75 100644 --- a/.github/workflows/lint-test-build.yaml +++ b/.github/workflows/lint-test-build.yaml @@ -32,25 +32,17 @@ jobs: with: use: true - - name: Install Skopeo # For some reason required by devcontainers/ci - run: | - sudo apt-get update - sudo apt-get install -y skopeo - - - name: Prepare devcontainer-ci.json - run: | - rm -f .devcontainer/devcontainer.json - mv .devcontainer/devcontainer-ci.json .devcontainer/devcontainer.json + - name: Build the Docker image + run: docker buildx build --platform ${{ matrix.vars.platform }} -t pgbackweb:latest . - name: Run lint, test, and build - uses: devcontainers/ci@v0.3 - with: - push: never - platform: ${{ matrix.vars.platform }} - runCmd: > + run: > + docker run --rm -v $PWD:/app -w /app pgbackweb:latest /bin/bash -c "\ npm install && \ + go mod download && \ task fixperms && \ task check-deps && \ task lint-only && \ task test-only && \ - task build + task build \ + " From 60dd3b265cae8507315435ac99094be5cb0fdc79 Mon Sep 17 00:00:00 2001 From: Luis Eduardo Date: Mon, 3 Feb 2025 04:20:06 +0000 Subject: [PATCH 19/22] Refactor lint-test-build workflow to improve readability of Docker run command --- .github/workflows/lint-test-build.yaml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/lint-test-build.yaml b/.github/workflows/lint-test-build.yaml index 896fa75..4264ff4 100644 --- a/.github/workflows/lint-test-build.yaml +++ b/.github/workflows/lint-test-build.yaml @@ -37,12 +37,12 @@ jobs: - name: Run lint, test, and build run: > - docker run --rm -v $PWD:/app -w /app pgbackweb:latest /bin/bash -c "\ - npm install && \ - go mod download && \ - task fixperms && \ - task check-deps && \ - task lint-only && \ - task test-only && \ - task build \ + docker run --rm -v $PWD:/app -w /app pgbackweb:latest /bin/bash -c " + npm install && + go mod download && + task fixperms && + task check-deps && + task lint-only && + task test-only && + task build " From 1a349a9287f0a6ee5c4fdb0a838ab67c485b26ef Mon Sep 17 00:00:00 2001 From: Luis Eduardo Date: Mon, 3 Feb 2025 04:21:21 +0000 Subject: [PATCH 20/22] Refactor Docker build command in lint-test-build workflow for improved readability --- .github/workflows/lint-test-build.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint-test-build.yaml b/.github/workflows/lint-test-build.yaml index 4264ff4..0b3121f 100644 --- a/.github/workflows/lint-test-build.yaml +++ b/.github/workflows/lint-test-build.yaml @@ -33,7 +33,11 @@ jobs: use: true - name: Build the Docker image - run: docker buildx build --platform ${{ matrix.vars.platform }} -t pgbackweb:latest . + run: > + docker buildx build + --platform ${{ matrix.vars.platform }} + --tag pgbackweb:latest + --file docker/Dockerfile.dev . - name: Run lint, test, and build run: > From a483c327b57205c0b430f7dbf132349445760d31 Mon Sep 17 00:00:00 2001 From: Luis Eduardo Date: Mon, 3 Feb 2025 04:29:38 +0000 Subject: [PATCH 21/22] Update lint-test-build workflow to include Docker image loading and streamline run command --- .github/workflows/lint-test-build.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint-test-build.yaml b/.github/workflows/lint-test-build.yaml index 0b3121f..b1f53f1 100644 --- a/.github/workflows/lint-test-build.yaml +++ b/.github/workflows/lint-test-build.yaml @@ -35,13 +35,15 @@ jobs: - name: Build the Docker image run: > docker buildx build + --load --platform ${{ matrix.vars.platform }} --tag pgbackweb:latest --file docker/Dockerfile.dev . - name: Run lint, test, and build run: > - docker run --rm -v $PWD:/app -w /app pgbackweb:latest /bin/bash -c " + docker run --rm -v $PWD:/app pgbackweb:latest /bin/bash -c " + cd /app && npm install && go mod download && task fixperms && From 0b625fc88e59422b638ada83bae38ddee1a8eda4 Mon Sep 17 00:00:00 2001 From: Luis Eduardo Date: Mon, 3 Feb 2025 04:37:23 +0000 Subject: [PATCH 22/22] Add default git configuration to Dockerfiles for safe.directory --- docker/Dockerfile | 4 ++++ docker/Dockerfile.dev | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/docker/Dockerfile b/docker/Dockerfile index bf219c8..1728c7b 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -82,6 +82,10 @@ RUN set -e && \ # Make binaries executable chmod +x /usr/local/dl-bin/* +# Default git config +# https://github.com/golangci/golangci-lint/issues/4033 +RUN git config --global --add safe.directory '*' + # Go to the app dir, delete the temporary dir and create backups dir WORKDIR /app RUN rm -rf /app/temp && \ diff --git a/docker/Dockerfile.dev b/docker/Dockerfile.dev index fd87547..ea08e62 100644 --- a/docker/Dockerfile.dev +++ b/docker/Dockerfile.dev @@ -82,6 +82,10 @@ RUN set -e && \ # Make binaries executable chmod +x /usr/local/dl-bin/* +# Default git config +# https://github.com/golangci/golangci-lint/issues/4033 +RUN git config --global --add safe.directory '*' + # Go to the app dir, delete the temporary dir and create backups dir WORKDIR /app RUN rm -rf /app/temp && \