os: linux language: shell branches: only: - code-server-golang services: - docker env: global: - DOCKERHUB="linuxserver/mods" - BASEIMAGE="code-server" - MODNAME="golang" jobs: include: - stage: PR-BuildImage if: (type IN (pull_request)) script: # Build image - docker build --no-cache -t ${DOCKERHUB}:${BASEIMAGE}-${MODNAME}-${TRAVIS_COMMIT} . - stage: BuildImage if: (NOT (type IN (pull_request))) script: # Set version - GO_WEBSITE=$(curl -sX GET https://golang.org/dl/) - GO_VERSION=${GO_VERSION:-$(echo "$GO_WEBSITE" | grep -o '.*linux-amd64.*' | grep -oP '(?<=go).*(?=.linux)')} - if [ $(echo "$GO_VERSION" | tr -d -c '.' | awk '{ print length; }') = "1" ]; then GO_TAG="${GO_VERSION}.0"; else GO_TAG="${GO_VERSION}"; fi - GO_TAG_MINOR=$(echo "$GO_TAG" | awk 'BEGIN{FS=OFS="."} NF--') - GO_TAG_MAJOR=$(echo "$GO_TAG_MINOR" | awk 'BEGIN{FS=OFS="."} NF--') - echo "GO_TAG is $GO_TAG GO_TAG_MINOR is $GO_TAG_MINOR GO_TAG_MAJOR is $GO_TAG_MAJOR" - if [ "$GO_VERSION" == $(echo "$GO_WEBSITE" | grep -o '.*linux-amd64.*' | grep -oP '(?<=go).*(?=.linux)') ]; then LATEST="true"; fi - if [ "$GO_VERSION" == $(echo "$GO_WEBSITE" | grep -o 'download" href=".*linux-amd64.tar.gz">' | grep -oP '(?<=go/go).*(?=.linux)' | grep -m 1 ^${GO_TAG_MINOR}) ]; then LATEST_MINOR="true"; fi - if [ "$GO_VERSION" == $(echo "$GO_WEBSITE" | grep -o 'download" href=".*linux-amd64.tar.gz">' | grep -oP '(?<=go/go).*(?=.linux)' | grep -m 1 ^${GO_TAG_MAJOR}) ]; then LATEST_MAJOR="true"; fi - echo "LATEST is ${LATEST:-not true}, LATEST_MINOR is ${LATEST_MINOR:-not true}, LATEST_MAJOR is ${LATEST_MAJOR:-not true}" # Build image - docker build --no-cache --build-arg GO_VERSION=${GO_VERSION} -t ${DOCKERHUB}:${BASEIMAGE}-${MODNAME}-${GO_TAG} . - if [ "$LATEST_MAJOR" == "true" ]; then docker tag ${DOCKERHUB}:${BASEIMAGE}-${MODNAME}-${GO_TAG} ${DOCKERHUB}:${BASEIMAGE}-${MODNAME}-${GO_TAG_MAJOR}; fi - if [ "$LATEST_MINOR" == "true" ]; then docker tag ${DOCKERHUB}:${BASEIMAGE}-${MODNAME}-${GO_TAG} ${DOCKERHUB}:${BASEIMAGE}-${MODNAME}-${GO_TAG_MINOR}; fi - if [ "$LATEST" == "true" ]; then docker tag ${DOCKERHUB}:${BASEIMAGE}-${MODNAME}-${GO_TAG} ${DOCKERHUB}:${BASEIMAGE}-${MODNAME}; fi # Login to DockerHub - echo $DOCKERPASS | docker login -u $DOCKERUSER --password-stdin # Push all of the tags - docker push ${DOCKERHUB}:${BASEIMAGE}-${MODNAME}-${GO_TAG} - if [ "$LATEST_MAJOR" == "true" ]; then docker push ${DOCKERHUB}:${BASEIMAGE}-${MODNAME}-${GO_TAG_MAJOR}; fi - if [ "$LATEST_MINOR" == "true" ]; then docker push ${DOCKERHUB}:${BASEIMAGE}-${MODNAME}-${GO_TAG_MINOR}; fi - if [ "$LATEST" == "true" ]; then docker push ${DOCKERHUB}:${BASEIMAGE}-${MODNAME}; fi