Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build docker images #21

Closed
wants to merge 82 commits into from
Closed

Build docker images #21

wants to merge 82 commits into from

Conversation

AlekSi
Copy link
Member

@AlekSi AlekSi commented Mar 3, 2025

No description provided.

AlekSi added 17 commits March 3, 2025 20:09
WIP
WIP
@AlekSi AlekSi requested a review from Copilot March 3, 2025 18:45
Comment on lines 113 to 117
- name: Build ${{ steps.version.outputs.debian_version }}
if: steps.version.outputs.debian_version != ''
run: ./ferretdb_packaging/build_packages.sh --os ${{ matrix.os }} --pg ${{ matrix.pg }} --version ${{ steps.version.outputs.debian_version }} --test-clean-install

- name: Upload
- name: Upload .deb packages

Check failure

Code scanning / CodeQL

Cache Poisoning via execution of untrusted code High

Potential cache poisoning in the context of the default branch due to privilege checkout of untrusted code. (
pull_request_target
).

Copilot Autofix AI 21 days ago

Copilot could not generate an autofix suggestion

Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.

Comment on lines +199 to +202
- name: Initialize Docker builder
run: make -C ferretdb_packaging docker-init

- name: Build local development Docker image

Check failure

Code scanning / CodeQL

Checkout of untrusted code in trusted context Critical

Potential execution of untrusted code on a privileged workflow (
pull_request_target
)
path: packaging

- name: Initialize Docker builder
run: make -C ferretdb_packaging docker-init

Check failure

Code scanning / CodeQL

Artifact poisoning Critical

Potential artifact poisoning in
make -C ferretdb_packaging docker-init
, which may be controlled by an external user (
pull_request_target
).

Copilot Autofix AI 21 days ago

To fix the problem, we need to ensure that the contents of the downloaded artifact are extracted to a temporary directory and verified before being used. This can be achieved by creating a temporary directory, extracting the artifact there, and then running the make command with the verified contents.

  1. Create a temporary directory for extracting the artifact.
  2. Modify the actions/download-artifact@v4 step to extract the artifact to the temporary directory.
  3. Verify the contents of the extracted artifact.
  4. Use the verified contents in the make command.
Suggested changeset 1
.github/workflows/ferretdb_packages.yml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/ferretdb_packages.yml b/.github/workflows/ferretdb_packages.yml
--- a/.github/workflows/ferretdb_packages.yml
+++ b/.github/workflows/ferretdb_packages.yml
@@ -193,2 +193,5 @@
 
+      - name: Create temporary directory for artifacts
+        run: mkdir -p ${{ runner.temp }}/artifacts/
+
       - name: Download .deb package
@@ -197,3 +200,12 @@
           name: deb12-${{ matrix.pg }}-${{ steps.version.outputs.debian_version }}
-          path: packaging
+          path: ${{ runner.temp }}/artifacts/
+
+      - name: Verify artifact contents
+        run: |
+          # Add verification logic here
+          # Example: Check if the expected files are present
+          if [ ! -f ${{ runner.temp }}/artifacts/expected_file ]; then
+            echo "Expected file not found!"
+            exit 1
+          fi
 
EOF
@@ -193,2 +193,5 @@

- name: Create temporary directory for artifacts
run: mkdir -p ${{ runner.temp }}/artifacts/

- name: Download .deb package
@@ -197,3 +200,12 @@
name: deb12-${{ matrix.pg }}-${{ steps.version.outputs.debian_version }}
path: packaging
path: ${{ runner.temp }}/artifacts/

- name: Verify artifact contents
run: |
# Add verification logic here
# Example: Check if the expected files are present
if [ ! -f ${{ runner.temp }}/artifacts/expected_file ]; then
echo "Expected file not found!"
exit 1
fi

Copilot is powered by AI and may make mistakes. Always verify output.

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Comment on lines +202 to +212
- name: Build local development Docker image
if: steps.version.outputs.docker_development_tag_flags != ''
run: >
make -C ferretdb_packaging docker-build
POSTGRES_VERSION=${{ matrix.pg }}
DOCUMENTDB_VERSION=${{ steps.version.outputs.debian_version }}
FILE=development
OUTPUT='type=docker'
TAGS=${{ steps.version.outputs.docker_development_tag_flags }}

- name: Build local production Docker image

Check failure

Code scanning / CodeQL

Checkout of untrusted code in trusted context Critical

Potential execution of untrusted code on a privileged workflow (
pull_request_target
)
Comment on lines +204 to +210
run: >
make -C ferretdb_packaging docker-build
POSTGRES_VERSION=${{ matrix.pg }}
DOCUMENTDB_VERSION=${{ steps.version.outputs.debian_version }}
FILE=development
OUTPUT='type=docker'
TAGS=${{ steps.version.outputs.docker_development_tag_flags }}

Check failure

Code scanning / CodeQL

Artifact poisoning Critical

Potential artifact poisoning in
make -C ferretdb_packaging docker-build POSTGRES_VERSION=${ matrix.pg } DOCUMENTDB_VERSION=${ steps.version.outputs.debian_version } FILE=development OUTPUT='type=docker' TAGS=${ steps.version.outputs.docker_development_tag_flags }
, which may be controlled by an external user (
pull_request_target
).

Copilot Autofix AI 21 days ago

To fix the artifact poisoning issue, we need to ensure that the contents of the downloaded artifact are extracted to a temporary directory and verified before use. This can be achieved by creating a temporary directory for the artifact extraction and updating the workflow to use this directory. Additionally, we should add verification steps to ensure the integrity of the downloaded artifact.

  1. Create a temporary directory for artifact extraction.
  2. Update the actions/download-artifact@v4 step to extract the artifact to the temporary directory.
  3. Add verification steps to ensure the integrity of the downloaded artifact before using it.
Suggested changeset 1
.github/workflows/ferretdb_packages.yml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/ferretdb_packages.yml b/.github/workflows/ferretdb_packages.yml
--- a/.github/workflows/ferretdb_packages.yml
+++ b/.github/workflows/ferretdb_packages.yml
@@ -193,2 +193,5 @@
 
+      - name: Create temporary directory for artifact
+        run: mkdir -p ${{ runner.temp }}/artifacts/
+
       - name: Download .deb package
@@ -197,3 +200,14 @@
           name: deb12-${{ matrix.pg }}-${{ steps.version.outputs.debian_version }}
-          path: packaging
+          path: ${{ runner.temp }}/artifacts/
+
+      - name: Verify downloaded artifact
+        run: |
+          # Add verification logic here
+          echo "Verifying artifact..."
+          # Example: Check if the expected file exists
+          if [ ! -f "${{ runner.temp }}/artifacts/packaging/deb12-${{ matrix.pg }}-${{ steps.version.outputs.debian_version }}.deb" ]; then
+            echo "Artifact verification failed!"
+            exit 1
+          fi
+          echo "Artifact verified successfully."
 
EOF
@@ -193,2 +193,5 @@

- name: Create temporary directory for artifact
run: mkdir -p ${{ runner.temp }}/artifacts/

- name: Download .deb package
@@ -197,3 +200,14 @@
name: deb12-${{ matrix.pg }}-${{ steps.version.outputs.debian_version }}
path: packaging
path: ${{ runner.temp }}/artifacts/

- name: Verify downloaded artifact
run: |
# Add verification logic here
echo "Verifying artifact..."
# Example: Check if the expected file exists
if [ ! -f "${{ runner.temp }}/artifacts/packaging/deb12-${{ matrix.pg }}-${{ steps.version.outputs.debian_version }}.deb" ]; then
echo "Artifact verification failed!"
exit 1
fi
echo "Artifact verified successfully."

Copilot is powered by AI and may make mistakes. Always verify output.

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Comment on lines +212 to +242
- name: Build local production Docker image
if: steps.version.outputs.docker_production_tag_flags != ''
run: >
make -C ferretdb_packaging docker-build
POSTGRES_VERSION=${{ matrix.pg }}
DOCUMENTDB_VERSION=${{ steps.version.outputs.debian_version }}
FILE=production
OUTPUT='type=docker'
TAGS=${{ steps.version.outputs.docker_production_tag_flags }}

# - name: Login to Docker Hub
# uses: docker/login-action@v3
# with:
# username: ferretdbbot
# password: ${{ secrets.DOCKER_HUB_TOKEN }}

# - name: Login to GitHub Container Registry
# uses: docker/login-action@v3
# with:
# registry: ghcr.io
# username: ${{ github.actor }}
# password: ${{ secrets.GITHUB_TOKEN }}

# - name: Login to Quay.io
# uses: docker/login-action@v3
# with:
# registry: quay.io
# username: ferretdbbot
# password: ${{ secrets.QUAY_TOKEN }}

- name: Build and push development Docker images

Check failure

Code scanning / CodeQL

Checkout of untrusted code in trusted context Critical

Potential execution of untrusted code on a privileged workflow (
pull_request_target
)
Comment on lines +214 to +220
run: >
make -C ferretdb_packaging docker-build
POSTGRES_VERSION=${{ matrix.pg }}
DOCUMENTDB_VERSION=${{ steps.version.outputs.debian_version }}
FILE=production
OUTPUT='type=docker'
TAGS=${{ steps.version.outputs.docker_production_tag_flags }}

Check failure

Code scanning / CodeQL

Artifact poisoning Critical

Potential artifact poisoning in
make -C ferretdb_packaging docker-build POSTGRES_VERSION=${ matrix.pg } DOCUMENTDB_VERSION=${ steps.version.outputs.debian_version } FILE=production OUTPUT='type=docker' TAGS=${ steps.version.outputs.docker_production_tag_flags }
, which may be controlled by an external user (
pull_request_target
).

Copilot Autofix AI 21 days ago

To fix the problem, we need to ensure that the downloaded artifact is treated as untrusted and extracted to a temporary directory. This prevents any potential malicious content from overriding existing files in the workspace. Additionally, we should verify the contents of the artifact before using it in subsequent steps.

  • Create a temporary directory for extracting the artifact.
  • Modify the actions/download-artifact step to extract the artifact to the temporary directory.
  • Verify the contents of the artifact before using it.
Suggested changeset 1
.github/workflows/ferretdb_packages.yml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/ferretdb_packages.yml b/.github/workflows/ferretdb_packages.yml
--- a/.github/workflows/ferretdb_packages.yml
+++ b/.github/workflows/ferretdb_packages.yml
@@ -193,2 +193,5 @@
 
+      - name: Create temporary directory for artifacts
+        run: mkdir -p ${{ runner.temp }}/artifacts/
+
       - name: Download .deb package
@@ -197,3 +200,8 @@
           name: deb12-${{ matrix.pg }}-${{ steps.version.outputs.debian_version }}
-          path: packaging
+          path: ${{ runner.temp }}/artifacts/
+
+      - name: Verify artifact contents
+        run: |
+          # Add verification logic here
+          ls ${{ runner.temp }}/artifacts/
 
EOF
@@ -193,2 +193,5 @@

- name: Create temporary directory for artifacts
run: mkdir -p ${{ runner.temp }}/artifacts/

- name: Download .deb package
@@ -197,3 +200,8 @@
name: deb12-${{ matrix.pg }}-${{ steps.version.outputs.debian_version }}
path: packaging
path: ${{ runner.temp }}/artifacts/

- name: Verify artifact contents
run: |
# Add verification logic here
ls ${{ runner.temp }}/artifacts/

Copilot is powered by AI and may make mistakes. Always verify output.

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Comment on lines 242 to 252
- name: Build and push development Docker images
if: steps.version.outputs.docker_development_tag_flags != ''
run: >
make -C ferretdb_packaging docker-build
POSTGRES_VERSION=${{ matrix.pg }}
DOCUMENTDB_VERSION=${{ steps.version.outputs.debian_version }}
FILE=development
OUTPUT='type=image,push=true'
TAGS=${{ steps.version.outputs.docker_development_tag_flags }}

# Build and push Docker images
- name: Build and push production Docker images

Check failure

Code scanning / CodeQL

Checkout of untrusted code in trusted context Critical

Potential execution of untrusted code on a privileged workflow (
pull_request_target
)
Comment on lines +244 to +250
run: >
make -C ferretdb_packaging docker-build
POSTGRES_VERSION=${{ matrix.pg }}
DOCUMENTDB_VERSION=${{ steps.version.outputs.debian_version }}
FILE=development
OUTPUT='type=image,push=true'
TAGS=${{ steps.version.outputs.docker_development_tag_flags }}

Check failure

Code scanning / CodeQL

Artifact poisoning Critical

Potential artifact poisoning in
make -C ferretdb_packaging docker-build POSTGRES_VERSION=${ matrix.pg } DOCUMENTDB_VERSION=${ steps.version.outputs.debian_version } FILE=development OUTPUT='type=image,push=true' TAGS=${ steps.version.outputs.docker_development_tag_flags }
, which may be controlled by an external user (
pull_request_target
).

Copilot Autofix AI 21 days ago

To fix the problem, we need to ensure that the contents of the downloaded artifact are extracted to a temporary directory and verified before being used. This can be achieved by creating a temporary directory, extracting the artifact there, and then using the extracted files from the temporary directory.

  1. Create a temporary directory for extracting the artifact.
  2. Modify the actions/download-artifact@v4 step to extract the artifact to the temporary directory.
  3. Update subsequent steps to use the files from the temporary directory.
Suggested changeset 1
.github/workflows/ferretdb_packages.yml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/ferretdb_packages.yml b/.github/workflows/ferretdb_packages.yml
--- a/.github/workflows/ferretdb_packages.yml
+++ b/.github/workflows/ferretdb_packages.yml
@@ -193,2 +193,5 @@
 
+      - name: Create temporary directory for artifacts
+        run: mkdir -p ${{ runner.temp }}/artifacts/
+
       - name: Download .deb package
@@ -197,3 +200,3 @@
           name: deb12-${{ matrix.pg }}-${{ steps.version.outputs.debian_version }}
-          path: packaging
+          path: ${{ runner.temp }}/artifacts/
 
@@ -245,3 +248,3 @@
         run: >
-          make -C ferretdb_packaging docker-build
+          make -C ${{ runner.temp }}/artifacts/ferretdb_packaging docker-build
           POSTGRES_VERSION=${{ matrix.pg }}
EOF
@@ -193,2 +193,5 @@

- name: Create temporary directory for artifacts
run: mkdir -p ${{ runner.temp }}/artifacts/

- name: Download .deb package
@@ -197,3 +200,3 @@
name: deb12-${{ matrix.pg }}-${{ steps.version.outputs.debian_version }}
path: packaging
path: ${{ runner.temp }}/artifacts/

@@ -245,3 +248,3 @@
run: >
make -C ferretdb_packaging docker-build
make -C ${{ runner.temp }}/artifacts/ferretdb_packaging docker-build
POSTGRES_VERSION=${{ matrix.pg }}
Copilot is powered by AI and may make mistakes. Always verify output.

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Comment on lines +254 to +260
run: >
make -C ferretdb_packaging docker-build
POSTGRES_VERSION=${{ matrix.pg }}
DOCUMENTDB_VERSION=${{ steps.version.outputs.debian_version }}
FILE=production
OUTPUT='type=image,push=true'
TAGS=${{ steps.version.outputs.docker_production_tag_flags }}

Check failure

Code scanning / CodeQL

Artifact poisoning Critical

Potential artifact poisoning in
make -C ferretdb_packaging docker-build POSTGRES_VERSION=${ matrix.pg } DOCUMENTDB_VERSION=${ steps.version.outputs.debian_version } FILE=production OUTPUT='type=image,push=true' TAGS=${ steps.version.outputs.docker_production_tag_flags }
, which may be controlled by an external user (
pull_request_target
).

Copilot Autofix AI 21 days ago

To fix the problem, we need to ensure that the contents of the downloaded artifacts are extracted to a temporary directory and verified before use. This prevents any potential malicious artifacts from overriding existing files or executing untrusted code.

  1. Create a temporary directory for extracting the artifact.
  2. Modify the actions/download-artifact step to extract the artifact to the temporary directory.
  3. Verify the contents of the artifact before using it in subsequent steps.
Suggested changeset 1
.github/workflows/ferretdb_packages.yml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/ferretdb_packages.yml b/.github/workflows/ferretdb_packages.yml
--- a/.github/workflows/ferretdb_packages.yml
+++ b/.github/workflows/ferretdb_packages.yml
@@ -193,2 +193,5 @@
 
+      - name: Create temporary directory for artifacts
+        run: mkdir -p ${{ runner.temp }}/artifacts/
+
       - name: Download .deb package
@@ -197,3 +200,12 @@
           name: deb12-${{ matrix.pg }}-${{ steps.version.outputs.debian_version }}
-          path: packaging
+          path: ${{ runner.temp }}/artifacts/
+
+      - name: Verify artifact contents
+        run: |
+          # Add verification logic here
+          # Example: Check if the expected files are present
+          if [ ! -f "${{ runner.temp }}/artifacts/expected_file.deb" ]; then
+            echo "Expected file not found in the artifact"
+            exit 1
+          fi
 
EOF
@@ -193,2 +193,5 @@

- name: Create temporary directory for artifacts
run: mkdir -p ${{ runner.temp }}/artifacts/

- name: Download .deb package
@@ -197,3 +200,12 @@
name: deb12-${{ matrix.pg }}-${{ steps.version.outputs.debian_version }}
path: packaging
path: ${{ runner.temp }}/artifacts/

- name: Verify artifact contents
run: |
# Add verification logic here
# Example: Check if the expected files are present
if [ ! -f "${{ runner.temp }}/artifacts/expected_file.deb" ]; then
echo "Expected file not found in the artifact"
exit 1
fi

Copilot is powered by AI and may make mistakes. Always verify output.

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This PR introduces improvements to our Docker image build process while refactoring version‐extraction functions. Key changes include adding tests for Docker image URLs and summaries, refactoring and renaming of version/differentiation functions (for PR, branch, and tag events), and updating GitHub Actions workflows to use the new output naming conventions.

Reviewed Changes

File Description
ferretdb_packaging/defineversion/debian_test.go Adds a test for reading the default version from control files.
ferretdb_packaging/defineversion/debian.go Implements version extraction and Debian version formatting.
ferretdb_packaging/defineversion/docker_test.go Covers Docker URL generation and Docker summary output testing.
.github/workflows/ferretdb_packages.yml Updates workflow steps with new version output variables and build steps for Docker images.
ferretdb_packaging/buildkitd.toml Disables garbage collection for BuildKit workers.
ferretdb_packaging/defineversion/main.go Refactors main version command; consolidates and renames functions.
ferretdb_packaging/defineversion/main_test.go Updates tests to reflect new parsing and output logic.
ferretdb_packaging/defineversion/docker.go Refactors Docker-related functions and URL mapping logic.

Copilot reviewed 16 out of 16 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (3)

ferretdb_packaging/defineversion/main.go:44

  • [nitpick] Consider clarifying the error message when the prerelease does not start with 'ferretdb-'. For example, update it to 'git tag must include a prerelease part starting with "ferretdb-" following the format v-ferretdb-' to guide correct tag usage.
if !strings.HasPrefix(prerelease, "ferretdb-") {

ferretdb_packaging/defineversion/main_test.go:50

  • Consider adding a test case in TestParseGitTag for git tags that include build metadata (non-empty buildmetadata) to ensure that the error 'buildmetadata "%q" is present' is properly triggered.
major, minor, patch, prerelease, err := parseGitTag(tag)

.github/workflows/ferretdb_packages.yml:105

  • Ensure the renamed output variable 'debian_version' is consistently used in all subsequent workflow steps to prevent mismatches with previous naming conventions.
- name: Define version
AlekSi and others added 2 commits March 3, 2025 22:48
WIP

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Copy link

mergify bot commented Mar 3, 2025

@AlekSi this pull request has merge conflicts.

@mergify mergify bot added the conflict PRs that have merge conflicts label Mar 3, 2025
# Conflicts:
#	.github/workflows/ferretdb_packages.yml
@mergify mergify bot removed the conflict PRs that have merge conflicts label Mar 3, 2025
@AlekSi AlekSi closed this Mar 3, 2025
@AlekSi AlekSi deleted the build-docker-images branch March 3, 2025 19:11
@AlekSi AlekSi restored the build-docker-images branch March 3, 2025 19:11
Copy link

mergify bot commented Mar 3, 2025

⚠️ The sha of the head commit of this PR conflicts with #25. Mergify cannot evaluate rules on this PR. ⚠️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
not ready Issues that are not ready to be worked on; PRs that should skip CI
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants