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

Docker containers #65

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Docker containers #65

wants to merge 5 commits into from

Conversation

AnkurSheel
Copy link
Member

@AnkurSheel AnkurSheel commented May 26, 2021

Added a basic docker compose file to spin up the DB, client and API projects.
The 3 projects run on the following ports

If you runthe ./runClient.sh and navigate to http://localhost:5002, there are a few errors which I think we should fix soon . That means there is still a fair bit of work that needs to be done before everything runs smoothly but I think merging this in its current state has a few advantages

  • Same DX across rider and VS (I use Rider exclusively now)
  • No need to download SQL server
  • Helps find the bits that will need to be fixed when we actually think about deploying this

@DotNetDublin DotNetDublin added the enhancement New feature or request label May 26, 2021
@DotNetDublin
Copy link
Member

Thanks @AnkurSheel!

Probably best if someone with a bit of knowledge on Docker considers this pull request although I will try and read up over the coming days and take a look.

How is your docker experience @jonhilt?

See this discussion for background as well as Ankur's note above.

@jonhilt
Copy link
Collaborator

jonhilt commented Jun 1, 2021

I have some Docker experience (enough to have learned the hard way why .dockerignore can be very important!)

I've had a go at running the script mentioned here and encountered an error:

Microsoft ODBC Driver 17 for SQL Server : Login failed for user 'SA'

If I get a moment I'll dig further in to see if it's something about my setup but is this anything you encountered @AnkurSheel?

image

@AnkurSheel
Copy link
Member Author

AnkurSheel commented Jun 1, 2021

I just tried deleteing the images and running ./runDb.sh and it seems to be fine for me.
I did not have an SQL server installed before so I wonder if the SA account is not available on your setup?

Maybe this is the issue
"When SQL Server is installed using Windows Authentication mode and is later changed to SQL Server and Windows Authentication mode, the SA login is initially disabled."

https://docs.microsoft.com/en-us/sql/relational-databases/errors-events/mssqlserver-18456-database-engine-error?view=sql-server-ver15

As an aside, I think we should eventually move away from IntegratedSecurity Mode

@jonhilt
Copy link
Collaborator

jonhilt commented Jun 2, 2021

Thanks @AnkurSheel.

As it turns out I think it may have been operator error! I hadn't run ./runDb.sh first!

Unless I missed something else, it seemed like I had to make a few small tweaks to get this to run (and be able to add time entries).

  • Removed `app.UseHttpsRedirection' from the API's startup config (because the API running via Docker is non-https only)
  • Added an environment variable to the docker-compose file to make it use a valid DB connection (I used the SA account here on the basis that this doesn't really matter for development use, obviously a different scenario if we look to Docker for prod deployment)
  • Updated the client project (via program.cs and appsettings.json) to point to http://localhost:5000 for the API

This made everything work here, but I'm conscious that Docker isn't exactly my forte so I may have just hacked this until it worked and you are very welcome to tell me if I missed something and didn't need to make these changes @AnkurSheel!

@AnkurSheel
Copy link
Member Author

AnkurSheel commented Jun 2, 2021

As it turns out I think it may have been operator error! I hadn't run ./runDb.sh first!

Thats odd. ./runClient.sh also runs the db step from docker-compose.yml. ./runDb.sh just spins up the db so that you can still debug using your IDE. But glad its working for you now :)

The changes seem correct. I didn't want to make too many changes to the code as part of this PR as I felt it required a broader conversation on what we want to do.
Depending on what we go with, we could drive this through the dockerfile and have sensible defaults for debugging.

Removed `app.UseHttpsRedirection' from the API's startup config (because the API running via Docker is non-https only)

I think we can use https in docker but it might be a little complex. Maybe we could drive that through a redirect when hosting.

Added an environment variable to the docker-compose file to make it use a valid DB connection (I used the SA account here on the basis that this doesn't really matter for development use, obviously a different scenario if we look to Docker for prod deployment)

I didn't get as far as adding TimeEntries but an environment variable is what I would do as well with a value in appsettings as a sensible default for people who don't want to run the db from the container
I will look at adding a test user. Should be relatively easy to do.

Updated the client project (via program.cs and appsettings.json) to point to http://localhost:5000 for the API

Could be an environment variable as well but that's probably overkill. Makes it easy to manage the ports through docker-compose though

@AnkurSheel
Copy link
Member Author

@jonhilt Thanks for making the changes.
How do we feel about merging this PR?
I have added support to create a test User and everything seems to be working fine for me.

@DotNetDublin
Copy link
Member

Hi @AnkurSheel

Thanks for your work on this. As mentioned on the roundup I've been investing in some Docker tutorials so hope to review the pull request this evening or tomorrow evening which may mean I have some questions for you.

Other than that once @jonhilt is happy we can hopefully see this merged this week.

Thanks again.

@DotNetDublin
Copy link
Member

Hi @AnkurSheel

I'll apologise in advance for the newbie Docker questions however I was wondering if I could run a couple of things past you.

After watching various tutorials I have a reasonable understanding on what each of the Docker files is doing and the purpose of the docker compose file so that's great. As I'm keen to keep this project "beginner friendly" I'm aiming to put together a high level guide outlining the steps required to utilise docker within the project.

Firstly can I just check that my approach was correct?

  1. Install Docker for Windows
  2. Open the command prompt and change directory to build which contains the docker-compose file docker-compose.yml
  3. Run the below commands
  4. docker-compose build
  5. docker-compose up

After which I see the below within Docker.

docker

However when I select to browse Timekeeper_Client I get the below SSL error.

ssl-error

I watched this YouTube tutorial on enabling HTTPS support for localhost however to get it working for now is there a step I'm missing that would allow it work via HTTP?

A couple of other newbie questions.

  1. Do you think we should add a Timekeeper_Server Docker file. Perhaps following the Chris Sainty tutorial?
  2. It would be nice if the Docker files displayed within the Solution Explorer of Visual Studio if that were possible?
  3. Is the container organisation support feature worth exploring?
  4. In relation to the database am I correct in saying that it would be recreated each time the container is started so if you added test data and then restarted the container these data changes would be lost?
  5. In this YouTube video they discuss running Docker within Visual Studio. I only see that option shown when I select to start a single project rather than multiple start-up projects and I see WSL 2 rather than Docker. and when I select WSL 2 I'm warned that "No distributions are installed." Something I can look into however I was wondering if you knew how to start the container within Visual Studio using F5?

Thanks in advance and @jonhilt may have other views on the above.

@AnkurSheel
Copy link
Member Author

AnkurSheel commented Jul 1, 2021

Hey @DotNetDublin

No worries. Always happy to answer any questions.

Firstly can I just check that my approach was correct?

That works. However, you can compress the steps to

  1. Install Docker for Windows.
  2. Open the command prompt and run ./runClient.sh from the root folder.
    [Optional] If you just want to bring up the db, run ./runDb.sh from the root folder.

However when I select to browse Timekeeper_Client I get the below SSL error.

Can you try navigating to http://localhost:5002/? I see that the url has https in your screenshot
As you have rightly mentioned, it does not work with SSL support currently. Thanks for sharing the video. I will watch it over the weekend and see what /how I can bring over

Do you think we should add a Timekeeper_Server Docker file. Perhaps following the Chris Sainty tutorial?

That's the plan. But I would like to do it in a separate PR

It would be nice if the Docker files displayed within the Solution Explorer of Visual Studio if that were possible?

I haven't worked with VS for a while now. But you should be able to add a solution folder

Is the container organization support feature worth exploring?

Probably not. It depends on how deep down the devops rabbit hole we want to go. I think its not a problem we need to solve unless we are at a massive scale.

In relation to the database am I correct in saying that it would be recreated each time the container is started so if you added test data and then restarted the container these data changes would be lost?

Yes. I am not a big fan of persisting data for local db. I think we should seed the data on startup. This enables us to use the local db for integration tests. Not a strong opinion in this case and happy to go either way.

In this YouTube video they discuss running Docker within Visual Studio. I only see that option shown when I select to start a single project rather than multiple start-up projects and I see WSL 2 rather than Docker. and when I select WSL 2 I'm warned that "No distributions are installed." Something I can look into however I was wondering if you knew how to start the container within Visual Studio using F5?

Sorry. I have been using Rider for C# dev and am not updated on docker support in Visual Studio. Unless, I am devving on the docker files, I prefer to use the command line to spin up/down the containers

As an aside, you might find this article I wrote(on the back of this work) interesting How to run SQL Server in a Docker container

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants