CD/CI with Docker Compose

CD/CI with Docker Compose


1. Set up environment

CloudLab
  • Deploy your Cloud experiment, Docker branch.
  • For today’s lecture, each student should launch their own experiment.
Setup GitHub repository
Docker Hub Token
  • Open a browser, visit Docker Hub and login to your account.
  • On the top right corner, click on your profile, then select Account Settings
  • Select Personal access tokens
  • Click on Generate new token
    • Access token description: GitHub Secret
    • Expiration date: 90 days
    • Access permissions: Read & Write
  • Then click on Generate
  • Keep the page with the personal access token open, as we will need that for later.
Setup GitHub secret
  • Go to the GitHub repository that you crealed earlier.
  • Visit Settings/Secrets and variables/Actions/new repository secret
  • Add the following secrets:
    • DOCKERHUB_TOKEN: your DockerHub login name
    • DOCKERHUB_USERNAME: The secret token generated by Docker Hub earlier.
Setup GitHub runner
  • Go to the GitHub repository that you crealed earlier.
  • Visit Settings/Actions/Runners
  • Click on New self-hosted runner
    • Select Linux/x64
    • SSH into your Docker experiment on CloudLab
    • Run all the commands under Download and Configure section.
    • Keep the terminal open.

2. Prepare the service

Making edit
  • You can do this directly via the GitHub browser environment.
  • Modify docker-compose.yml as follows
    • Adjust lines 6 and 8 to replace my Docker Hub username with your DockerHub username.
  • Modify .github/workflows/publish.yml as follows
    • Adjust lines 5 and 15 with the branch containing your contents (most likely main)
    • Adjust line 32 to replace my Docker Hub username with your DockerHub username.
Deploy your service
  • Login into your CloudLab Docker experiment using another terminal.
  • Clone the Git repository (use HTTPS option)
  • Change into the repository and run the followings:
1
2
docker compose build go_app --no-cache
docker compose up -d
  • Open a browser tab and use your experiment hostname at port 8080.
Observe CD/CI
  • Change to the test being displayed by editing the main.go file.
  • Observe the Action workflow being carried out, and that the browser display the content of the web app being changed by refreshing.