Sign inSign up

zeacom/gitlab-docker-build

By zeacom

•Updated almost 2 years ago

A Docker image optimized for building and pushing Docker images in GitLab CI pipelines.

Image
Integration & delivery
0

465

zeacom/gitlab-docker-build repository overview

⁠zeacom/gitlab-docker-build

A Docker image optimized for building and pushing Docker images in GitLab CI pipelines. This image is designed to streamline the process of versioning, building, and pushing Docker images, as well as notifying build results via Telegram.

⁠Features

  • Built on docker:latest: Provides full Docker capabilities for managing builds within CI pipelines.
  • Integrated Bash and Curl: Includes tools such as bash and curl for enhanced scripting and notifications.
  • Pre-installed build and notification scripts:
    • docker_build_push.sh: Automates the Docker image build and push process, including handling version tagging.
    • notify_telegram.sh: Sends build success or failure notifications to Telegram, including deployment options.
    • define_version_tags.sh: Centralized version and image tag generation logic for consistent versioning across scripts.
  • Optimized for GitLab CI: Streamlines the process of using Docker-in-Docker (DinD) setups for building and pushing images in a CI/CD pipeline.

⁠Usage

This image is designed to be used in GitLab CI pipelines where building and pushing Docker images is required. Currently only Telegram is available for sending notifications, which are not required.

⁠Example GitLab CI Configuration (the after_script step is optional)
docker-build:
  stage: dockerize
  image: zeacom/gitlab-docker-build:v1.0.0
  services:
    - docker:dind
  script:
    - /usr/local/bin/docker_build_push.sh
  after_script:
    - /usr/local/bin/notify_telegram.sh
⁠Pre-installed Scripts

docker_build_push.sh

This script automates the Docker build and push process. It generates version tags based on GitLab CI environment variables and pushes the resulting image to the Docker registry.

notify_telegram.sh

Sends a notification to a specified Telegram chat with information about the build status. It uses Telegram's Bot API to send success or error messages, including deployment options if the build is successful.

define_version_tags.sh

Generates Docker image version tags based on the GitLab CI commit reference or tag. It ensures consistent versioning across builds.

⁠Environment Variables

To use this image effectively, certain environment variables are required:

CI_COMMIT_REF_NAME: GitLab commit reference, used for versioning.
CI_PIPELINE_URL: The URL to the current pipeline for notifications.
TELEGRAM_CHAT_ID: The Telegram chat ID where notifications will be sent.
TELEGRAM_CHAT_TOKEN: Token for the Telegram bot used for notifications.
⁠How to Build and Push

You can customize the behavior of the build and push process by modifying the pre-installed scripts or adding new ones to the image.

To use this image for building Docker images, the docker_build_push.sh script must be executed. It handles the Docker login, build, and push steps automatically, using versioning logic from define_version_tags.sh.

⁠License

This Docker image is licensed under the MIT License.

Tag summary

Content type

Image

Digest

sha256:ab321e6b4…

Size

222.1 MB

Last updated

almost 2 years ago

docker pull zeacom/gitlab-docker-build:v1.0.3