Automate Docker Deployment with GitHub Actions Task #4

This guide helps you automate Java app deployment to Docker Hub.

Example repository

Due date 6/29/2025 11:59 PM

Step 1: Create java repository similar to Task #3

Paste the following Dockerfile configuration:

FROM openjdk:23
WORKDIR /app
COPY src/ /app/
RUN javac *.java
CMD ["java", "HelloWorld"]

Step 2: Get username and token from dockerhub

Login to Dockerhub

Click on your profile =>Account Settings=> Click Personal Access Token => Generate Token => Save the token on your computer.

Step 3: Create GitHub Workflow

Create Github Action using Github UI

Log in to Giithub= >Select your repository => Click on Action => New workflow/Search Simple Workflow => Configure => Commit change

Your repository should have .github/workflow/somefile.yml added to your repository

.github/workflows/docker.yml

Paste the following YAML configuration:

Or create GitHub Workflow using Intellij

Create .github/workflows/docker.yml folder structure directly inside the repository using intellij

.github/workflows/docker.yml

Paste the following YAML configuration:

name: Build and Push to Docker Hub

on:
  push:
    branches:
      - master

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
      - name: Log in to Docker Hub
        run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
      - name: Build Docker Image
        run: docker build -t ${{ secrets.DOCKER_USERNAME }}/is147:${{ github.run_number }} .
      - name: Push Docker Image
        run: docker push ${{ secrets.DOCKER_USERNAME }}/is147:${{ github.run_number }}

Step 4: Commit and Push

Now commit and push your changes to trigger the GitHub Action:

git add .
git commit -m "Automate Docker build and push"
git push origin main 
OR
From Intellij git=> commit =>commit and push

Step 5: Pull and Run from Docker Hub

Once the workflow completes, you can pull and run the image:

docker pull your-dockerhub-username/hello-world:tagname
docker images
docker run your-dockerhub-username/hello-world:tagname

Step 6: How to submit on Blackboard?

  1. Break down all the requirements into stories on the GitHub project.
  2. Push the code to GitHub with solutions.
  3. Write about the use of docker and github action in the README.md file.
  4. Submit your GitHub project url , GitHub code url, and output screenshot on Blackboard.