GitHub to Dockerhub
Today I finally got the GitHub action that builds the spring-boot application, a docker container from the jar and then publishes it on Dockerhub to work.

The action came out looking something like this:
name: Docker
on:
workflow_dispatch:
push:
branches:
- "main"
jobs:
build:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: cd api && ./mvnw -B package
-
name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Build and push
uses: docker/build-push-action@v5
with:
context: ./api
file: ./api/Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/tcapi:latest
One thing I’ve found is that simplifying and using hardcoded variables at first can be really useful in early development
I also started working on a docker-compose.yml so that it starts both the api-container and the mongodb-container.
A next step in the process would be to find something to store in the database to make sure the project has a working persistence layer.
The reason why I’m writing a docker-compose first is that I find it’s a very easy first step towards getting the containers to talk to each other. After that kubernetes has its own CLI-tool called kompose for translating docker-compose-files into a kubernetes project.
Another thing worth noting is that at this stage there are no environment variables or login details for the mongodb-container. That way I’m keeping it simple so that I won’t have any extra layer of security until I know everything else is working as it should.
There should probably be an issue in the GitHub-repo for that.
Here’s the initial docker-compose.yml by the way.
version: "3.8"
services:
mongo_db:
image: mongo:latest
container_name: "mongodb"
ports:
- 27017:27017
volumes:
- db:/data/db
tcapi:
depends_on:
- mongo_db
image: tcarisland/tcapi:latest
restart: on-failure
ports:
- 8081:8080
volumes:
- .m2:/root/.m2
stdin_open: true
tty: true
volumes:
db:
