Coder Social home page Coder Social logo

buildscript's Introduction

build.bash

The build.bash script helps build Docker images and upload them to container registries. Reasons you might use this instead of the built-in Docker build job in your continuous integration system:

  • Run the exact same build process locally as runs in the CI environment and produces production Docker images.
  • No script modifications necessary, configure for different systems with environment variables.
  • Builds for develop, main, and test branches produce containers tagged with the branch name and pushed to container registries.
  • Branches named in the format release/x.y.z are pushed to container registries with that container tag as well as the container tag latest.
  • Other branches go through the build stage in the Dockerfile but not further (and no image is uploaded).
  • Build environment information is brought in as container labels (Git commit id, build date, version) and you can easily add more.
  • Can push to a configured container registry (Docker Hub by default) as well as the GitHub Container registry.
  • Can utilize docker-lock to handle pinning of images in each Dockerfile

You only need build.bash, the rest of this project is testing and examples.

Usage

Running from the command line

build.bash [-h] [-v] [-df Dockerfile] [-p] [Docker tag]

Options (all are optional):

  • -h, --help - Print this help and exit
  • -v, --verbose - Print script debug info
  • -df, --dockerfile - Use the specified Dockerfile
  • -p, --publish - Run the release-publish.bash script in the container (if it's present)
  • Docker tag - Override the guessed Docker tag (the current directory) with this value if present

Environment variables (all are optional):

  • BLD_DOCKER_IMAGE - name of Docker image, uses directory name by default
  • CR_HOST - hostname of the container registry, defaults Docker default (Docker Hub)
  • CR_OWNER - owner of the container registry
  • CR_PASSWORD - password to log into the container registry
  • CR_USER - username to log in to the container registry
  • DOCKER_LOCK_VERSION - a version of docker-lock to use (e.g. 0.8.10), can also be specified in docker-lock-version.txt
  • GHCR_OWNER - owner of the GitHub Container Registry (defaults to GHCR_USER)
  • GHCR_PAT - GitHub Container Registry Personal Access Token
  • GHCR_USER - username to log in to the GitHub Container Registry

Example configuration for continuous integration

Pre-configuration

  1. Get credentials for pushing containers into your desired registry or registries.

Set up your Dockerfile

  1. Use multi-stage builds and name your build stage build.
  2. Bring in metadata with the ARG instruction for BRANCH, IMAGE_CREATED, IMAGE_REVISION, and IMAGE_VERSION.
  3. Use those variables in your LABEL and ENV instructions.

See this sample Dockerfile for more details. This Dockerfile is based on the one provided when creating a Microsoft Visual Studio Web Application with the "Enable Docker Support" box checked so you can use it both for Visual Studio Docker support as well as performing your builds if that's your environment.

Set up CI

  • Configure secrets for your repository (GitHub, Azure).

    • BLD_DOCKER_IMAGE can be set to the name of the Docker image if you like, if not it will use the directory name of your project.
    • CR_HOST - hostname of the container registry, defaults to Docker Hub.
    • CR_OWNER - container registry repository (username or organization).
    • CR_PASSWORD - container registration password or Personal Access Token.
    • CR_USER - container registry username for authentication.
    • DOCKER_LOCK_VERSION - a version of docker-lock to use (e.g. 0.8.10), can also be specified in docker-lock-version.txt
    • GHCR_OWNER - GitHub Container Registry repository (username or organization name).
    • GHCR_PAT - GitHub Personal Access Token.
    • GHCR_USER - username associated with the GitHub Personal Access Token (for authentication).
  • Review sample CI configurations:

  • Push some branches and open and resolve some PRs to see if the build works successfully.

License

The build.bash script is licensed under the MIT License. A basis for the script is the MIT-licensed "Minimal safe Bash script template" by Maciej Radzikowski.

buildscript's People

Contributors

k7hpn avatar atomist-bot avatar

Stargazers

 avatar

Watchers

James Cloos avatar Dan Wilcox avatar  avatar  avatar

Forkers

k7hpn

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.