Build Docker image and publish to DockerHub in CI

in open-source •  7 years ago 

build_docker_images.png

Issue: #14

I added a file (Dockerfile) that created the image of the docker:

FROM alpine:edge
# install bash
RUN \
  apk add --no-cache bash
# install screen
RUN \
  apk add screen
# install java
RUN \
  apk add --no-cache openjdk8
# install mongodb
RUN \
  echo '@testing http://dl-4.alpinelinux.org/alpine/edge/testing' >> /etc/apk/repositories && \
  apk add --no-cache mongodb@testing
VOLUME ["/data/db","/tmp","/opt"]
ADD \
  build/libs/shop-0.0.1-SNAPSHOT.jar /opt/shop.jar
ADD \
  start_on_docker.sh /opt/start.sh
RUN \
  touch /opt/shop.jar
RUN \
  chmod u+x /opt/start.sh
# ENV JAVA_OPTS="-Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=9001,suspend=n"
CMD /opt/start.sh
EXPOSE 9000

I have added the mongodb and program shop launch file:

#!/bin/bash
echo "start database"
screen -d -m mongod
echo "start program"
java -jar /opt/shop.jar

I added to .travis.yml

sudo: required

services:
  - docker

after_success:
 - docker login -u shopateverything -p $DOCKER_PASS
 - export TAG=`if [ "$TRAVIS_BRANCH" == "master" ]; then echo "latest"; else echo $TRAVIS_BRANCH; fi`
 - export IMAGE_NAME=shopateverything/shop
 - docker build -t $IMAGE_NAME:$TRAVIS_COMMIT .
 - docker tag $IMAGE_NAME:$TRAVIS_COMMIT $IMAGE_NAME:$TAG
 - docker push $IMAGE_NAME:$TAG

I created an account on docker hub - shopateverything and create repository shop.

https://hub.docker.com/r/shopateverything/shop/

When travis is built, a docker image is created and posted on the docker hub.

Pull request

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!