Publish docker image to jfrog artifactory from github actions CICD pipeline

Viewed 4600

I am implementing CICD pipeline with github actions. I want to publish the docker image to jfrog artifactory. Does anybody has any idea how to implement that?

4 Answers

A complete sample with login, build and push to a jfrog artifactory.

This sample exepected a Dockerfile at the root of the repository, and secrets stored in GitHub Secrets.

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout ️
        uses: actions/checkout@v2
      -
        name: Set up QEMU ️
        uses: docker/setup-qemu-action@v1
      -
        name: Set up Docker Buildx 
        uses: docker/setup-buildx-action@v1
      -
        name: Login to JFrog   
        uses: docker/login-action@v1
        with:
          registry: <your artifactory>.jfrog.io
          username: ${{ secrets.JFROG_USER_WRITER }}
          password: ${{ secrets.JFROG_PASSWORD_WRITER }}
      -
        name: Build and push 
        id: docker_build
        uses: docker/build-push-action@v2
        with:
          push: true
          tags: <your artifactory>.jfrog.io/<your image name>:latest

You should just be able to log into the registry without using the jfrog cli with docker login. F.e:

  - uses: actions/checkout@v2
      - name: Login to DockerHub Registry
        run: docker login -u ${{ secrets.REGISTRY_USERNAME }} -p ${{ secrets.REGISTRY_PASSWORD }} artifactory.<yourcompanyrepo>.com

Using the docker-login github action, you could specify the registry.

F.e.

  • name: Login to GitHub Container Registry uses: docker/login-action@v1 with: registry: artifactory..com username: user password: pass

An easier attitude would be using the JFrog CLI and the Setup JFrog CLI GitHub Action:

  1. In your local machine, configure and export your JFrog server:
# Interactively, create a new server
jfrog c add

# Create a server token. This token can be used as a secret in your workflow named: "JF_ARTIFACTORY_SECRET".
jfrog c export
  1. Run the Setup JFrog CLI GitHub Action:
- uses: jfrog/setup-jfrog-cli@v1
  env:
    JF_ARTIFACTORY: ${{ secrets.JF_ARTIFACTORY_SECRET }}
- run: |
    jfrog rt docker-push <image tag> <target repo>
    
    # Optional - publish build info to Artifactory
    jfrog rt bp

Read more about it:

Related