Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 23, 2025

Overview

This PR adds support for running the continuous integration workflow inside a Docker container instead of checking out files locally. This enables testing the exact same environment that will be deployed to production.

Motivation

When building Docker images for production deployment, it's critical to ensure that CI checks (linting, building, testing) are performed in the same environment that will run in production. Previously, the workflow only supported checking out code and setting up the Node.js environment on the runner, which could lead to discrepancies between the tested and deployed environments.

Changes

New Workflow Input

Added a new optional container input parameter:

  • Type: string
  • Default: "" (empty string, maintains current behavior)
  • Description: Docker container image to run CI steps in. When specified, steps will execute inside this container instead of checking out code. The container should have the project code and dependencies pre-installed.

Updated Jobs

Modified all CI jobs (setup, lint, build, test) to support container execution:

  • Added container: configuration to each job that conditionally uses the specified image
  • Made checkout and setup-node steps conditional with if: inputs.container == ''
  • Updated command execution to use npm run when in container mode

Documentation

Updated .github/workflows/continuous-integration.md with:

  • New container parameter in the inputs table
  • Comprehensive example demonstrating container-based CI workflow
  • Guidance on disabling CodeQL and dependency-review when using container mode (as they require repository checkout)

Test Coverage

Enhanced .github/workflows/__test-workflow-continuous-integration.yml to validate both modes:

  • Without container: Tests the original behavior with checkout and artifact upload
  • With container: Builds a test Docker image from npm test fixtures, loads it, and executes lint/test commands inside the container

This ensures the feature works correctly in both traditional and container-based execution modes.

Usage Example

jobs:
  # Build Docker image with application code and dependencies
  build-image:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: docker build -t my-app:${{ github.sha }} .
      - run: docker push ghcr.io/${{ github.repository }}:${{ github.sha }}

  # Run CI checks inside the container
  continuous-integration:
    needs: build-image
    uses: hoverkraft-tech/ci-github-nodejs/.github/workflows/continuous-integration.yml@main
    with:
      container: ghcr.io/${{ github.repository }}:${{ github.sha }}
      code-ql: ""  # Disable (requires checkout)
      dependency-review: false  # Disable (requires checkout)
      lint: true
      test: true

Backward Compatibility

✅ Fully backward compatible. The container input defaults to an empty string, so existing workflows continue to function without any changes.

Testing

  • ✅ Linter passes with no errors
  • ✅ CodeQL security scan passes with no vulnerabilities
  • ✅ No breaking changes to existing functionality
  • ✅ Test workflow validates both traditional and container-based execution modes

Benefits

  • Environment parity: Test in the exact environment that will run in production
  • Confidence: Promote the tested Docker image to production knowing it passed all CI checks
  • Flexibility: Choose between traditional checkout-based CI or container-based CI depending on your needs
Original prompt

Update this workflow: .github/workflows/continuous-integration.yml to allows to execute in a given image container instead of local checkout files

Use case: I build a docker image that will be promote to production so I need to perform CI check in this image to ensure that it will be the same ecosystem that is tested and deployed


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Update CI workflow to execute in a specified Docker image Add container input to continuous-integration workflow for Docker-based CI execution Oct 23, 2025
Copilot AI requested a review from neilime October 23, 2025 21:57
@neilime neilime force-pushed the copilot/update-workflow-for-docker-image branch from ffb84c7 to 7db334b Compare October 24, 2025 13:35
Copy link
Member

@neilime neilime left a comment

Choose a reason for hiding this comment

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

@copilot update test .github/workflows/__test-workflow-continuous-integration.yml to validate behavior with and without container

@neilime neilime marked this pull request as ready for review October 24, 2025 13:37
Copy link
Contributor Author

Copilot AI commented Oct 24, 2025

@copilot update test .github/workflows/__test-workflow-continuous-integration.yml to validate behavior with and without container

Updated test workflow in f780db3 to validate both scenarios:

  • Without container mode: Tests original behavior with checkout and artifact upload
  • With container mode: Builds a test container, loads it, and runs lint/test commands inside

The test workflow now builds a Docker image from the npm test fixtures and validates that commands can be executed inside the container.

Copilot AI requested a review from neilime October 24, 2025 13:44
@neilime neilime changed the title Add container input to continuous-integration workflow for Docker-based CI execution feat(continuous-integration): Add container input for OCI-based CI execution Oct 24, 2025
@neilime neilime force-pushed the copilot/update-workflow-for-docker-image branch 3 times, most recently from 2dac07e to 50e2207 Compare October 24, 2025 14:25
@neilime neilime changed the title feat(continuous-integration): Add container input for OCI-based CI execution feat(continuous-integration): add container input for OCI-based CI execution Oct 28, 2025
@neilime neilime force-pushed the copilot/update-workflow-for-docker-image branch 12 times, most recently from 57c94ce to 1a8253c Compare October 29, 2025 07:18
@neilime neilime force-pushed the copilot/update-workflow-for-docker-image branch 15 times, most recently from 02eb7b5 to 420d2d5 Compare October 29, 2025 13:04
@neilime neilime force-pushed the copilot/update-workflow-for-docker-image branch from 420d2d5 to 7505f7f Compare October 29, 2025 13:15
@neilime neilime merged commit a42cfc5 into main Oct 29, 2025
50 checks passed
@neilime neilime deleted the copilot/update-workflow-for-docker-image branch October 29, 2025 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants