Pipeline: build in docker, release a tag, push file to tag in github

How to clone repository, build docker image, get a git sha commit from dockerfile, release a tag in github with that sha commit and upload files from docker images to it ?

  1. How to delete all leftovers (images, volumes, containers) from dind (docker build --force-rm --no-cache -t my-image .)
  2. How to create tag in github and in the same time upload files to this tag ? Is it even possible ?
  3. How to get git informations from step 0 (git clone). I want to use it tag step (git config remote.origin.url https://{NEED_USERNAME}:{github_token }@github.com/{NEED_USERNAME}/{NEED_REPONAME}.git)

Of course if it there another solution to my use case I will use it. :slight_smile:
Thanks

For example:

Dockerfile

FROM alpine:3.8
RUN apk update && apk add --no-cache git maven
RUN git clone https://github.com/efsavage/hello-world-war
RUN cd hello-world-war && mvn package
RUN cp target/my-app.jar /dest
RUN git log --format="%H" -n 1 > /dest/sha

.drone.yml

pipeline:
  build:
    image: docker
    commands:
      - docker build --force-rm --no-cache -t my-image .
      - GIT_SHA=$(cat /dest/sha)
    volumes:
     - /var/run/docker.sock:/var/run/docker.sock
     - /here:/dest
   tag:
     image: docker:git 
     secrets: [ github_token ]
     commands:
       - git config remote.origin.url https://{NEED_USERNAME}:{github_token }@github.com/{NEED_USERNAME}/{NEED_REPONAME}.git
       - git tag vMY_APP_${GIT_SHA}
       - git push origin vMY_APP_${GIT_SHA} 
   github_release:
     image: plugins/github-release
     secrets: [ github_token ]
     files:  /dest/my-app.jar
     checksum:
       - sha256
     when:
       event: tag
     volumes:
        - /here:/dest
1 Like