Project-Books / books-api

GraphQL Books API
https://project-books.github.io/#books-api
MIT License
36 stars 61 forks source link

Dockerize backend 134 #139

Closed Wildschut closed 2 years ago

Wildschut commented 3 years ago

Summary of change

Create Multistage Dockerfile to build maven project. Define booksapi service in docker-compose with required parameters. Create the container database dependency "checkpoint" shell. This script validates the passed environment variables or lack thereof. Update the README.md to document the new required workflow with examples.

Related issue

Closes #134

Pull request checklist

Please keep this checklist in & ensure you have done the following:

For any of the optional checkboxes (e.g. the screenshots one), still check it if it does not apply.

If in doubt, get in touch with us via our Slack workspace or by creating a new Q&A discussion on GitHub

knjk04 commented 3 years ago

Thanks for working on this. Sure, feel free to revert them (e.g. using an interactive rebase). Let me know if you need a hand with this

sonarcloud[bot] commented 3 years ago

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

Wildschut commented 3 years ago

Hi @knjk04 , I think I've managed to revert the changes I made.

Can you please check if that is the case?

Specifically the impact of these 4 commits: image

If this fails (the git revert) I'll rather delete my fork and just redo the whole thing.

Wildschut commented 3 years ago

Hi @knjk04 ,

I've reverted the commits that are causing the build to fail.

Is there step(s) that I'm missing?

knjk04 commented 3 years ago

Hi @Wildschut, the build is passing now

knjk04 commented 3 years ago

@Wildschut Thanks a lot for this, I can see you've put a lot of thought into this!

I haven't been able to run this on Windows. Did you test this on Unix?

Wildschut commented 3 years ago

Hi @knjk04 , yes this was developed on an ubuntu machine.

I was heavily inspired by apache guacamole, so credit where credit is due...

That being said: The OS shouldn't matter as long as the *.sh files have their line endings with LR and not CRLR.

You should be able to verify if this is the case in intellij by opening the start.sh and looking in the bottom right (I think).

The dockerfile itself should be platform agnostic. And the build of the jar itself, the files get copied over to a linux container and compiled inside it, so thats abstracted away from the platform as well...

Otherwise, please share your output so I can help trace what is wrong/where its failing.

Wildschut commented 3 years ago

Hi @knjk04 , had you managed to get it running?

Any feedback for me?

knjk04 commented 3 years ago

Hi @Wildschut, I'm so sorry for the delay in getting back to you (frankly, I forgot).

I'm using Docker Desktop on Windows (Docker Engine v20.10.8). I have buildkit enabled:

  "features": {
    "buildkit": true
  }

I have also set it via Powershell using the answer from dev-null: https://stackoverflow.com/questions/62984255/docker-buildkit-for-docker-for-windows.

Output of docker-compose build booksapi: https://gist.github.com/knjk04/15c4cba690ac74dfd522a4b77be33b8c.

http://localhost:8080/graphiql:

image

It looks like the db is running, but the backend isn't:

image

Do you know what I might be missing/doing wrong? I'd imagine this is something wrong on my end (perhaps something else I need to do on Windows), so I can continue to look into this on my end

Wildschut commented 3 years ago

Hi @knjk04 ,

Thanks for getting back to me :D

Ok, so from the output you've shared the build is passing. So the booksapi image is being created.

Now what remains is to run the image - create an container.

Can you please share the output of the following command docker-compose up booksapi

Please also share the docker-compose.yml. I'd like to verify the env's your passing...

I dont think windows is the issue here because you're able to run other containers...

knjk04 commented 3 years ago

After running docker-compose build --build-arg mvn_arg="clean package -DskipTests" booksapi:

PS C:\Users\karan\playground\bapi-docker-139> docker-compose up booksapi
Creating network "bapi-docker-139_default" with the default driver
Creating booksapi ... done
Attaching to booksapi
: No such file or directory
booksapi exited with code 127
PS C:\Users\karan\playground\bapi-docker-139>

image

It looks like it's still not running. See docker-compose.

Wildschut commented 3 years ago

Ok, based off the error you've received (127), the start.sh file attributes (line endings) has been changed.

Please execute the follow ps command:

Get-Content ./docker/bin/start.sh  
 -raw | % {$_ -replace "`r", ""} | Set-Content -NoNewline ./docker/bin/start.sh

Then refresh the image by rebuilding it: docker-compose build --build-arg mvn_arg="clean package -DskipTests"

Finally generate an container of the refreshed image: docker-compose up booksapi

knjk04 commented 2 years ago

@Wildschut Do you have an update on this?

Wildschut commented 2 years ago

Hi @knjk04 , was out of the loop for a while.

I'll resolve it within 3 days. Once done, I'll mention you so this van move forward.

Thanks

sonarcloud[bot] commented 2 years ago

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

knjk04 commented 2 years ago

@Wildschut I've made the necessary changes, as someone else's work depends on this. Thanks a lot for all of your help with this!