Skip to content

Instantly share code, notes, and snippets.

@opencoca
Last active December 22, 2022 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save opencoca/e7f09ce5d9cde70296785de4a42147ee to your computer and use it in GitHub Desktop.
Save opencoca/e7f09ce5d9cde70296785de4a42147ee to your computer and use it in GitHub Desktop.
BuildnRun.sh is a straightforward bash script that streamlines and standardizes the process of building and tagging Docker images
#!/bin/bash
# Version 1.3
# Copyright (c) Startr LLC. All rights reserved.
# This script is licensed under the GNU Affero General Public License v3.0.
# For more information, see https://www.gnu.org/licenses/agpl-3.0.en.html
# OpenCo™ Cocom Build 'n' Run Script
# This simple script builds and runs this directory 's Dockerfile Image
# Set PROJECTPATH to the path of the current directory
PROJECTPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Set PROJECT to the lowercase version of the name of this directory
PROJECT=`echo ${PROJECTPATH##*/}|awk '{print tolower($0)}'`
# Set FULL_BRANCH to the name of the current Git branch
FULL_BRANCH=`echo $(git rev-parse --abbrev-ref HEAD)|awk '{print tolower($0)}'`
# Set BRANCH to the lowercase version of this name, with everything after the last forward slash removed
BRANCH=${FULL_BRANCH##*/}
# Set TAG to the output of the git describe --always --tag command, which returns a "unique identifier" for the current commit
TAG=`echo $(git describe --always --tag)|awk '{print tolower($0)}'`
# Print the values of PROJECTPATH, PROJECT, FULL_BRANCH, and BRANCH to the console
echo PROJECTPATH=$PROJECTPATH
echo PROJECT=$PROJECT
echo FULL_BRANCH=$FULL_BRANCH
echo BRANCH=$BRANCH
# Update the Git submodules so that the latest version of the code is used
git submodule update --init --recursive
# Build the Docker image using the docker build command, and tag it with the openco/$PROJECT-$BRANCH:$TAG tag
# Then tag the image with the openco/$PROJECT-$BRANCH:latest tag, and run the ./Run.sh script
echo docker build -t openco/$PROJECT-$BRANCH:$TAG .
echo docker tag -f openco/$PROJECT-$BRANCH:$TAG openco/$PROJECT-$BRANCH:latest
docker build -t openco/$PROJECT-$BRANCH:$TAG . \
&& \
docker tag openco/$PROJECT-$BRANCH:$TAG \
openco/$PROJECT-$BRANCH:latest \
&& \
#Run.sh
docker run \
-p 80:80 \
-it openco/$PROJECT-$BRANCH:latest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment