How to push already built image to GCR

I have a build step that builds the docker image.

Then I want to use the GCR plugin to only push the image. But GCR plugin tries to also build the image by looking for Dockerfile. Is there a way to tell GCR plugin to just push the image?

pipeline:
  build:
    image: maven:3.5.3-jdk-8
    commands:
      - cd service
      - mvn package fabric8:build
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
  publish:
    image: plugins/gcr
    tags:
        - "${DRONE_COMMIT:0:8}"
    registry: gcr.io
    secrets:
      - source: my_google_creds
        target: google_credentials
    repo: my-gcp-project/services/myservice

The Docker plugin is used to build and publish images without having to mount the host machine Docker socket. Since you are already building the image and mounting the host machine docker socket, you would just execute the docker publish command.

pipeline:
  build:
    image: maven:3.5.3-jdk-8
    commands:
      - cd service
      - mvn package fabric8:build
+     - docker login --username xxxxx --password yyyyyy
+     - docker push my-gcp-project/services/myservice
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
1 Like