{"id":23910567,"url":"https://github.com/p-ilipili/docker_ex","last_synced_at":"2026-05-06T06:39:53.040Z","repository":{"id":270676903,"uuid":"911115866","full_name":"p-ilipili/docker_ex","owner":"p-ilipili","description":"Docker exam featuring an api container and 3 individual containers performing a different test each on the api. Outcomes of the tests are logged in a shared logfile. All output is logged in another file.","archived":false,"fork":false,"pushed_at":"2025-01-02T09:55:50.000Z","size":9,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-23T17:13:44.401Z","etag":null,"topics":["api","docker","docker-compose","docker-container","dockerfile","fastapi"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/p-ilipili.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-01-02T09:27:24.000Z","updated_at":"2025-01-02T10:03:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"96fde53a-bd9f-4520-96a8-08c90bea0943","html_url":"https://github.com/p-ilipili/docker_ex","commit_stats":null,"previous_names":["p-ilipili/docker_ex"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/p-ilipili/docker_ex","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/p-ilipili%2Fdocker_ex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/p-ilipili%2Fdocker_ex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/p-ilipili%2Fdocker_ex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/p-ilipili%2Fdocker_ex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/p-ilipili","download_url":"https://codeload.github.com/p-ilipili/docker_ex/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/p-ilipili%2Fdocker_ex/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":284353057,"owners_count":26990132,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-14T02:00:06.101Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","docker","docker-compose","docker-container","dockerfile","fastapi"],"created_at":"2025-01-05T07:17:14.778Z","updated_at":"2026-05-06T06:39:53.029Z","avatar_url":"https://github.com/p-ilipili.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Docker Exam\nDocker exam featuring an api container and 3 individual containers performing a different test each on the api.\nOutcomes of the tests are logged in a shared logfile. \nAll output is logged in another file.\n\n\n## Presentation\nFor the correction of this exercise, we will try to create a CI/CD pipeline to test an API. We will put ourselves in the shoes of a team that is supposed to create a set of tests to be applied automatically before deployment.\n\nIn our scenario, a team has created an application that allows to use a sentiment analysis algorithm: it allows to predict if a sentence is positive or negative. This API will be deployed in a container whose image is for the moment datascientest/fastapi:1.0.0.\n\nLet's look at the entry points of our API:\n\n- /status returns 1 if the API is running\n- /permissions returns a user's permissions\n- /v1/sentiment returns the sentiment analysis using an old model\n- /v2/sentiment returns the sentiment analysis using a new template\n\nThe /status entry point simply checks that the API is working.\nThe /permissions entry point allows someone, identified by a username and a password to see which version of the template they have access to.\nFinally the last two take a sentence as input, check that the user is identified,\ncheck that the user has the right to use this template and if so, return the sentiment score: -1 is negative; +1 is positive.\n\nTo download the image, run the following command : `docker image pull datascientest/fastapi:1.0.0`\n\nTo test the API manually, run the command : `docker container run -p 8000:8000 datascientest/fastapi:1.0.0`\n\nThe API is available on port 8000 of the host machine. At the entry point /docs you can find a detailed description of the entry points.\n\nWe will define some test scenarios that will be done via separate containers.\n\n## Tests\n### Authentication\nIn this first test, we are going to check that the identification logic works well. To do this, we will need to make GET requests on the /permissions entry point.\nWe know that two users exist alice and bob and their passwords are wonderland and builder. We'll try a 3rd test with a password that doesn't work: clementine and mandarine.\n\nThe first two requests should return a 200 error code while the third should return a 403 error code.\n\n### Authorization\nIn this second test, we will verify that our user authorization logic is working properly. We know that bob only has access to v1 while alice has access to both versions.\nFor each of the users, we will make a query on the /v1/sentiment and /v2/sentiment entry points:\nwe must then provide the arguments username, password and sentence which contains the sentence to be analyzed.\n\n### Content\nIn this last test, we check that the API works as it should. We will test the following sentences with the alice account:\n\nlife is beautiful\nthat sucks\nFor each version of the model, we should get a positive score for the first sentence and a negative score for the second sentence.\nThe test will consist in checking the positivity or negativity of the score.\n\n## Building the tests\nFor each of the tests, we want to create a separate container that will run those tests.\nThe idea of having one container per test means that the entire test pipeline does not have to be changed if only one of the components has changed.\n\nWhen a test is run, if an environment variable LOG is set to 1, then a log should be printed in a api_test.log file.\n\nYou are free to choose the technology used: the Python libraries requests and os seem to be affordable options.\n\n## Solution\n\nA shared volume for the logfile and another one for the scripts so scripts can be adapted when containers are offline.\nThis also avoids copying the scripts to the containers.\nShared network of course.\nUse for loops to cycle through users, urls and sentences.\nCreate dependencies between the containers to order the tests and avoid simultaneous writing to the log file.\nAnd some other stuff.\n\n**NB: don't forget to create the 'logs' folder. This could be added in the code with a check 'if exists'.**\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fp-ilipili%2Fdocker_ex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fp-ilipili%2Fdocker_ex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fp-ilipili%2Fdocker_ex/lists"}