At the end of this tutorial, you will be able to push your code changes to Github and run it in an EC2 instance deployed AWS CodeBuild.
All of AWS services in this tutorial should be in the same region Sydney (ap-southeast-2).
- Team workshop
- Github Account
- AWS Account
- AWS Region : Sydney (ap-southeast-2)
- AWS EC2 Key Pair. Follow this tutorial and take note of your Key Pair. There is no need for us to ssh into a machine here so we can skip the
chmod
step in the guide.
-
Open AWS Codestar.
-
Click "Create a new project".
-
Choose Python (Flask) Web server / Amazon EC2.
-
Enter your Project Details.
-
Choose GitHub as your repository.
-
Click "Connect to GitHub" button.
-
Enter your GitHub reporitory details. Select repo as public.
-
After reviewing the project details, click "Create Project". This will automatically create the GitHub repository for you. You can visit GitHub afterwards to see your repository.
-
Choose the keypair that you have created in the Pre-Requisites as you Key Pair.
-
Click "Next" button, you will be redirected to the Project setup page. Try to refresh the page to see if the project setup has finished.
-
Capture screenshot of the successful build, save it along as part of your submission.
-
In the lower right side of the Project setup page, the application endpoint will show up when the deployment has finished loading. You can check the deployment status in the Continuous deployment section.
-
Click the Application Endpoint when it is ready and you should be able to see the JSON response of your Flask API.
-
Update your
helloworld/application.py
file to change your application's output using GitHub's web interface. Observe the deployment pipeline and refresh your Application Endpoint. You can change the following line under theget()
method:return Response(json.dumps({'Output': 'Hello World from Codestar'}), mimetype='application/json', status=200)
-
Capture screenshot of the failed build, save it along as part of your submission.
- Repeat the above steps 1 - 11, select 'ASP.NET Core' Web service on EC2 when creating the new codestar template wizard.
- Logon to the AWS Jenkins as below:-
-
Jenkins Server 1
-
Jenkins Server 2
-
Create a new freestyle project item with following naming convention
'aws_dotnet_<your initial/group name>'
-
Configure the jenkins job as below, make sure to replace all the userid in the screenshots
- Configure SCM and the build schedule trigger
- Create 3 shell execute under the pre jenkins action
/usr/bin/dotnet restore
/usr/bin/dotnet build
/usr/bin/dotnet test
-
Capture screenshot of the successful build, save it along as part of your submission.
-
Open the Dotnet project using your favourite editor. Make changes to the dotnet test case under the following namespace
AspNetCoreWebServiceTest/Controllers/HelloControllerTest.cs
as below where theHello World1!!!
with an extra exclamation mark.
[Fact]
public void NoInputParamGetResponseTest()
{
HelloController controller = new HelloController();
var response = controller.Get().Value as Response;
Assert.Equal("Hello World!!!", response.output);
}
-
Commit your codes to the github and watch how the build will fail.
-
Capture screenshot of the failed build, save it along as part of your submission.
-
Stabilize the test case before dockerized the app.
-
Create a Dockerfile on the root of the project directory for this dotnet project. *Hint shown during lecturer day3.
from ubuntu:latest
WORKDIR backend-svr
RUN apt-get update && \
apt-get install -y software-properties-common && \
apt-get install -y wget && \
rm -rf /var/lib/apt/lists/*
RUN wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb
RUN dpkg -i packages-microsoft-prod.deb
RUN add-apt-repository universe
RUN apt install apt-transport-https -y
RUN apt-get update
RUN wget http://ftp.us.debian.org/debian/pool/main/i/icu/libicu57_57.1-6+deb9u4_amd64.deb
RUN dpkg -i libicu57_57.1-6+deb9u4_amd64.deb
RUN apt install dotnet-sdk-3.1 -y
COPY ./ ./
RUN dotnet restore
RUN dotnet build
EXPOSE 5000:5000
CMD [ "dotnet", "run" ]
-
Commit the Dockefile into your github repository.
-
Configure your jenkins's pre build step to publish this project's image to dockerhub. Use your own dockerhub username as the prefix of the image tag along with the dockerhub credentials.
-
Capture screenshot of the successful docker build and also the image is being store on the dockerhub repo, save it along as part of your submission.
-
Try accessing the app via the end point created from the CodeStar dashboard.