Spring Boot(Dockerized&Gradle) Deploy To Digital Ocean With Github Actions

Hüseyin Serkan Özaydin
3 min readAug 13, 2021

Hi everyone, we’ll talk about Spring Boot Project deploy to digital ocean with Github Actions. But let first talk about Github Actions

Github Actions

Github Actions help you automate tasks within your software development lifecycle. And it is event-driven. Such as, when you create a PR to main branch automatically Github Action builds your project and send your QA teams. PR is event in scenario.

Whatever, I don’t want tell a long story to you. Let’s create our workflow.

Firstly, you have to have an account at Docker Hub. Docker Hub is repository of images. If you have an account or you created an account we can continue.

Secondly, create a folder like “.github/workflows/blank.yml” at your project’s root path.

Open blank.yml file. Paste below script to your blank.yml file.

We can talk about above script.

name: Name of your workflow

on: push: branches: It is an event. It says “When push to your main branch trigger the workflow”

jobs: It is a set of steps that execute on the same runner

uses: When you are using a Github Action’s library you have to use keyword.

script: It’s command of appleboy library. And it runs cli command at your linux server.

Actions Secrets

You saw “DOCKER_HUB_PASSWORD”,”DOCKER_HUB_USERNAME”,”HOST”,”PASSWORD”,”PORT”,”USERNAME” fields at above script. Them all of secrets of your project. And you can definite at your project’s Github Project.

DOCKER_HUB_PASSWORD: Your Docker Hub account’s password

DOCKER_HUB_USERNAME: Your Docker Hub account’s username

HOST: Your Digital Ocean server’s IP

PASSWORD: Your Digital Ocean server’s password

PORT: Your Digital Ocean server’s SSH port (Default: 22)

USERNAME: Your Digital Ocean server’s user’s username (Default: root)

If you define all secrets at your Github project you can push your project to the “main” branch. And open the “Actions” tab.

Don’t Forget:

Firstly, you have to create a Dockerfile at your project root file

Secondly, if you use Gradle at your project you have to run below CLI command at your project’s root path

git update-index --chmod=+x gradlew
git commit -m "Make gradlew executable"

--

--