Publish docker image to jfrog artifactory from github actions CICD pipeline

12.2k views Asked by At

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?

5

There are 5 answers

0
mattrzr On

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
0
Quentin On

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
0
yahavi On

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:

0
ivey221 On

Based on the answer of @Quentin,

You might face an error while running Docker Buildx step saying:

Error response from daemon: manifest for not found: manifest unknown: The named manifest is not known to the registry

The solution for this problem is to run docker context create builders in a separate step then use the created builders within Docker Buildx step as following:

...

- name: Set up Docker Context for Buildx
  id: buildx-context
  run: |
    docker context create builders

- name: Set up Docker Buildx
  uses: docker/setup-buildx-action@v2
  with:
    version: latest
    endpoint: builders
...
0
mattrzr On

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