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

feat: add support to build image from docker file #69

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dineshkumar-j-genea
Copy link

Description

Currently app-gen script has a limitation that only supports pulling images specified in the Compose file using docker pull, but it does not support building images locally using the build option with a Dockerfile.

It would be highly beneficial to have a feature that allows building Docker images locally during Artifact creation with the app-gen script. This would enable the user to define build instructions in the docker-compose.yml file, build the image on their local system, and then include that image in the Artifact for deployment. This approach would enhance flexibility and accommodate scenarios where local image building is necessary, such as incorporating local changes or when access to external registries is restricted.

Example of the current docker-compose.yml structure:

version: '3.8'

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    image: myapp:latest  # Specifies the name of the image to be created
    container_name: myapp-container  # Specifies the container name
    ports:
      - "8080:8080"
    environment:
      - NODE_ENV=development
    volumes:
      - ./:/app

This feature request comes from https://hub.mender.io/t/support-for-local-docker-image-builds-and-rollback-using-stored-images/7157

Mender Atlassian Ticket:

@dineshkumar-j-genea dineshkumar-j-genea marked this pull request as ready for review October 4, 2024 12:50
This commit introduces the ability to build images directly from a Dockerfile,
enhancing the build process for containerized applications.

Changelog: Added support for building images from Dockerfiles.
Ticket: MEN-7539

Signed-off-by: dineshkumar-j-genea <[email protected]>
@dineshkumar-j-genea dineshkumar-j-genea force-pushed the feature/build-with-dockerfile branch 3 times, most recently from d0888cd to 13993b2 Compare October 4, 2024 13:31
@merlin-northern
Copy link
Contributor

@dineshkumar-j-genea thank you very much for this long-awaited feature. I find it very useful, and you have no idea how many times I wanted it.
what we need is:

  • testing around it I would say at least acceptance test
  • fix the failing tests as they fail now

@dineshkumar-j-genea dineshkumar-j-genea force-pushed the feature/build-with-dockerfile branch 10 times, most recently from 3fd1f5e to d51cd04 Compare October 10, 2024 12:26
@dineshkumar-j-genea
Copy link
Author

dineshkumar-j-genea commented Oct 10, 2024

@merlin-northern I have fixed the failing test cases. can you review the changes once

@merlin-northern
Copy link
Contributor

@merlin-northern I have fixed the failing test cases. can you review the changes once

thank you very much. I would like to have my colleague Lluís opinion here as well.

This will modify the
- pull images passed as args
- image_not_present test case updated
- ci config to install the yq package before testing
- update the test script to use debian version instead of the alpine version due to the platform conflict.

Signed-off-by: Dineshkumar J <[email protected]>
@mender-test-bot
Copy link
Contributor

mender-test-bot commented Oct 11, 2024

Merging these commits will result in the following changelog entries:

Changelogs

app-update-module (feature/build-with-dockerfile)

New changes in app-update-module since master:

Features
  • Added support for building images from Dockerfiles.
    (MEN-7539)

@dineshkumar-j-genea
Copy link
Author

@lluiscampos Did you get the chance to review this PR Request?

@MuchoLucho
Copy link
Member

@lluiscampos just following up on here. Can you take a look?

@merlin-northern merlin-northern self-assigned this Oct 30, 2024
@merlin-northern
Copy link
Contributor

@lluiscampos just following up on here. Can you take a look?

there was a small re-assignment: I will take a look at it, this week for sure. sorry for the delay.

Copy link
Contributor

@merlin-northern merlin-northern left a comment

Choose a reason for hiding this comment

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

sorry for not being clear on this one: we need a separate and new test scenario for this. let me know if you want me to write one.

Comment on lines +54 to +67
--application-name myapp0a # we expect a failure here now as we are using docker-compose to pull the images now

if [ $? -ne 0 ]; then
echo "images_not_present: app-gen artifact generation failed which is expected"
return 0
else
echo "Unexpected success, we were expecting failure"
return 1
fi
# echo "images_not_present: checking install rc"
# mender install "$artifact_file" && return 2 # we expect a failure
# echo "images_not_present: checking for running containers"
# docker ps -q | grep -q . && return 3 # and we expect nothing to be running
# return 0
Copy link
Contributor

Choose a reason for hiding this comment

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

we probably should not modify the existing tests, why do we need to do it?

Copy link
Author

Choose a reason for hiding this comment

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

in this test case, if you closely observe the existing flow, you will that we used image tag to pull image and then mender install it uses the docker compose to validate the image and expected a failure, as the image argument and docker compose totally defined with different image name.

but right now, as per the requirement we are using the docker-compose also to pull an image, which means image argument is essentially becomes the optional one.

with that, during the artifact generation itself, the script will throw an error in the new logic.

Comment on lines +78 to +84
# echo "images_not_present: checking install rc"
# mender install "$artifact_file" && return 2 # we expect a failure
# sleep $timeout_s
# echo "images_not_present: checking for running containers"
# docker ps
# diff "${temp_dir}/before-rollback-$$" <(docker ps --format '{{.Image}}')
# return 0
Copy link
Contributor

Choose a reason for hiding this comment

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

there is a bit of commented out code in this pull request, could you clean that?

@dineshkumar-j-genea
Copy link
Author

dineshkumar-j-genea commented Nov 4, 2024

@merlin-northern I am right now occupied with something else. it will be better, if you can take care of test case.

but in my opinion, there is no specific test case required, as all the existing test cases are actually verifying the new changes.

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.

4 participants