yalegria / devops-git-actions

0 stars 0 forks source link

How to Spin a Project to DockerHub with Semaphore #31

Open Voxelghiest opened 2 years ago

Voxelghiest commented 2 years ago

How to Spin a Semaphore Project to DockerHub

This tutorial assumes you have created a repo using the instructions from #30. The sample Java repo that Semaphore creates actually has built-in functionality to spin the project to DockerHub. All you need to do is follow the steps outlined in the READ_ME file of the repo, which I have copied here and modified slightly.

CI/CD pipeline on Semaphore

The Semaphore pipeline is configured to:

  1. Build the project
  2. Run tests
  3. Build Docker image
  4. Push image to hub.docker.com

Semaphore pipeline configuration is located at .semaphore/semaphore.yml, in your project's repo.

Setting up

To set up this pipeline on your Semaphore account:

  1. If you don't have sem command line tool installed, do so using
    curl https://storage.googleapis.com/sem-cli-releases/get.sh | bash and then connect to your account using
    sem connect <your organization>.semaphoreci.com <your private API token>. You can get the private token from your account dashboard at me.semaphoreci.com/account.
  2. Be sure to clone the repo to your local device, if you haven't already, and navigate into that folder from the command line.
  3. This pipeline relies on public Docker repository to push artifacts of successful builds. Create an account on https://hub.docker.com/ if you don't have one.
  4. Add your hub.docker.com credentials to ./docker-hub-secret.yml, at the root of the repo. The credentials should remain private, so don't publish them to your Git repository by mistake.
  5. Add your ./docker-hub-secret.yml credentials to Semaphore with sem create -f docker-hub-secret.yml

After pushing a new commit to the master branch, Semaphore will initiate a workflow, which you can examine by returning to your Semaphore dashboard and selecting the project name: Pic1

Once the pipeline runs, you'll be able to see the results from the workflow details page, which should look something like this: pipeline-result