Giter Site home page Giter Site logo

acksell / ci-cd-example Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 10 KB

A example application with a CI/CD workflow using github actions to deploy images to github container registry. Watchtower is used for updating any running containers.

Dockerfile 15.96% Python 13.46% Shell 70.57%
ci cd github-actions watchtower github-container-registry ghcr docker docker-registry

ci-cd-example's Introduction

CI/CD Example

Introduction

This repository contains a hello world python server along with a Github Actions pipeline/workflow that tests the application, builds a docker image, and publishes the image to Github Container Registry. There is also a startup script for watchtower, a tool for detecting remote changes to currently running docker containers and promptly restarting any container with the latest image, used for deployment.

Configuration

Github Container Registry

Because Github Container Registry is currently in beta one has to enable the feature manually, either for an organisation or individual account. For instructions on how to do so, see "Enabling improved container support.".

From https://docs.github.com/en/free-pro-team@latest/packages/guides/about-github-container-registry:

Note: GitHub Container Registry is currently in public beta and subject to change. During the beta, storage and bandwidth are free. To use GitHub Container Registry, you must enable the feature for your account. For more information, see "Enabling improved container support."

In order for this repository's workflow to work you also need to set a secret in your project repository for the github actions workflow to work: GHCR_PAT, a personalized access token. This is currently the only way to access the Github Container Registry via Github Actions. Read more about how to issue one and what privileges to give it.

If the repository resides under an organization you might want to create a new user solely for the purpose of issuing this PAT. You also have to change the workflow to use that username since ${{ github.repository_owner }} will otherwise refer to the organization in the following stage of the deploy job:

      - 
        name: Login to Github Registry
        uses: docker/login-action@v1
        with:
          registry: ghcr.io
          # Change this if under an organization
          username: ${{ github.repository_owner }}
          # Github Container Registry, Personal Access Token.
          # Currently in the GHCR beta, a PAT is the only way to access GHCR through actions. 
          password: ${{ secrets.GHCR_PAT }}

Watchtower

Setup

Watchtower also needs to be able to access Github Container Registry. To set this up simply run the following with your PAT and corresponding username instead:

export GHCR_PAT=YOUR_PAT_GOES_HERE
echo $GHCR_PAT | docker login ghcr.io -u USERNAME --password-stdin

This will generate a ~/.docker/config.json file that is later mounted as a volume to the watchtower container when ran.

Running

Simply run the provided ./start_watchtower.sh script to start the watchtower container! It is set to poll for new images every 5 minutes, you can change this (and more) in the script itself, where you can find more documentation about different arguments and watchtower.

Note: One might want to create a symlink to the config file instead of mounting the config file directly in order for changes to propagate properly to the watchtower container. Read more: https://containrrr.dev/watchtower/usage-overview/.

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.