feat: create Docker image, set up Docker CI #528

Merged
sw5ciprl merged 8 commits from main into main 2024-10-10 13:07:37 -07:00
2 changed files with 27 additions and 21 deletions
Showing only changes of commit 1818c26a71 - Show all commits

View File

@ -19,24 +19,4 @@ jobs:
- run: cp config.json.example config.json
coderabbitai[bot] commented 2024-10-09 10:29:30 -07:00 (Migrated from github.com)
Review

⚠️ Potential issue

Adjust image tagging and add checkout step.

While the multi-platform build and push configuration is good, there are a few issues to address:

  1. The image tags don't follow the ghcr.io format. They should be ghcr.io/<owner>/<repo>.
  2. The "latest" tag should be explicit.
  3. The repository name in the tag should match the GitHub repository name exactly (case-sensitive).
  4. There's no step to check out the repository, which is likely needed for the build context.

Please make the following changes:

  1. Add a checkout step at the beginning of the job:
- name: Checkout
  uses: actions/checkout@v4
  1. Update the tags field in the "Build and push" step:
tags: |
  ghcr.io/${{ github.repository }}:latest
  ghcr.io/${{ github.repository }}:${{ github.sha }}
  1. Consider adding a context field to specify the build context:
context: .

These changes will ensure correct image tagging and provide the necessary build context.

_:warning: Potential issue_ **Adjust image tagging and add checkout step.** While the multi-platform build and push configuration is good, there are a few issues to address: 1. The image tags don't follow the ghcr.io format. They should be `ghcr.io/<owner>/<repo>`. 2. The "latest" tag should be explicit. 3. The repository name in the tag should match the GitHub repository name exactly (case-sensitive). 4. There's no step to check out the repository, which is likely needed for the build context. Please make the following changes: 1. Add a checkout step at the beginning of the job: ```yaml - name: Checkout uses: actions/checkout@v4 ``` 2. Update the `tags` field in the "Build and push" step: ```yaml tags: | ghcr.io/${{ github.repository }}:latest ghcr.io/${{ github.repository }}:${{ github.sha }} ``` 3. Consider adding a `context` field to specify the build context: ```yaml context: . ``` These changes will ensure correct image tagging and provide the necessary build context. <!-- This is an auto-generated comment by CodeRabbit -->
coderabbitai[bot] commented 2024-10-09 10:29:30 -07:00 (Migrated from github.com)
Review

🛠️ Refactor suggestion

Consider adding conditions for running the Docker job.

The new docker job is a valuable addition to the workflow. To optimize CI/CD pipeline efficiency, consider adding conditions to control when this job runs. For example:

docker:
  runs-on: ubuntu-latest
  if: github.event_name == 'push' && github.ref == 'refs/heads/main'
  # ... rest of the job configuration

This condition would run the Docker job only for pushes to the main branch, which is typically when you want to build and push new Docker images. Adjust the condition as needed based on your branching and release strategy.

_:hammer_and_wrench: Refactor suggestion_ **Consider adding conditions for running the Docker job.** The new `docker` job is a valuable addition to the workflow. To optimize CI/CD pipeline efficiency, consider adding conditions to control when this job runs. For example: ```yaml docker: runs-on: ubuntu-latest if: github.event_name == 'push' && github.ref == 'refs/heads/main' # ... rest of the job configuration ``` This condition would run the Docker job only for pushes to the main branch, which is typically when you want to build and push new Docker images. Adjust the condition as needed based on your branching and release strategy. <!-- This is an auto-generated comment by CodeRabbit -->
coderabbitai[bot] commented 2024-10-10 10:44:24 -07:00 (Migrated from github.com)
Review

💡 Codebase verification

Action Required: Add a Checkout Step to the Workflow

The build and push step is missing a checkout step. Please add a checkout step before the build and push step to ensure the repository code is available for the Docker build process.

- name: Checkout
  uses: actions/checkout@v4
🔗 Analysis chain

LGTM with a minor concern: Build and push configuration.

The build and push step is well-configured:

  1. It uses the latest version of docker/build-push-action.
  2. Multi-platform build for amd64 and arm64 is set up, enhancing deployment flexibility.
  3. The tagging strategy follows best practices, using both 'latest' and the commit SHA.

However, there's one potential issue:

There's no explicit checkout step before this build step. While some actions automatically check out the repository, it's generally safer to include an explicit checkout step to ensure the correct code is available for the build context.

Consider adding a checkout step at the beginning of the job:

- name: Checkout
  uses: actions/checkout@v4

This will ensure that the correct code is available for the Docker build process.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if a checkout step exists in the docker job

# Test: Search for a checkout step in the docker job
if grep -A 10 "docker:" .github/workflows/build.yml | grep -q "uses: actions/checkout@"; then
    echo "Checkout step found in the docker job."
else
    echo "No checkout step found in the docker job."
fi

Length of output: 177

_:bulb: Codebase verification_ **Action Required: Add a Checkout Step to the Workflow** The build and push step is missing a checkout step. Please add a checkout step before the build and push step to ensure the repository code is available for the Docker build process. ```yaml - name: Checkout uses: actions/checkout@v4 ``` <details> <summary>🔗 Analysis chain</summary> **LGTM with a minor concern: Build and push configuration.** The build and push step is well-configured: 1. It uses the latest version of `docker/build-push-action`. 2. Multi-platform build for amd64 and arm64 is set up, enhancing deployment flexibility. 3. The tagging strategy follows best practices, using both 'latest' and the commit SHA. However, there's one potential issue: There's no explicit checkout step before this build step. While some actions automatically check out the repository, it's generally safer to include an explicit checkout step to ensure the correct code is available for the build context. Consider adding a checkout step at the beginning of the job: ```yaml - name: Checkout uses: actions/checkout@v4 ``` This will ensure that the correct code is available for the Docker build process. </details> <details> <summary>🏁 Scripts executed</summary> The following scripts were executed for the analysis: Script: ```shell #!/bin/bash # Description: Verify if a checkout step exists in the docker job # Test: Search for a checkout step in the docker job if grep -A 10 "docker:" .github/workflows/build.yml | grep -q "uses: actions/checkout@"; then echo "Checkout step found in the docker job." else echo "No checkout step found in the docker job." fi ``` Length of output: 177 </details> <!-- This is an auto-generated comment by CodeRabbit -->
- run: echo '{"version":"","buildLabel":"","matchmakingBuildId":""}' > static/data/buildConfig.json
- run: npm run build
- run: npm run lint
docker:
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- name: Set up Docker buildx
uses: docker/setup-buildx-action@v3
- name: Log in to container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
platforms: linux/amd64,linux/arm64
push: true
tags: |
ghcr.io/${{ github.repository }}:latest
ghcr.io/${{ github.repository}}:${{ github.sha }}
- run: npm run lint

26
.github/workflows/docker.yml vendored Normal file
View File

@ -0,0 +1,26 @@
name: Build Docker image
on:
push:
branches:
- main
pull_request: {}
jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Set up Docker buildx
uses: docker/setup-buildx-action@v3
- name: Log in to container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
platforms: linux/amd64,linux/arm64
push: true
tags: |
ghcr.io/${{ github.repository }}:latest
ghcr.io/${{ github.repository}}:${{ github.sha }}