Coder Social home page Coder Social logo

push-to-ghcr's Introduction

push-to-ghcr

This action simplifies pushes of Docker images to the GitHub Containers Registry at ghcr.io.

Dockerfile from your repository is build and published on:

  • release event (releases named vx.y.z) your image will be tagged with x.y.z
  • push event your image will be tagged with latest

Private containers

Images built for private repositories will be published as private containers to ghcr.io. Please refer to GitHub's documentation on how to set up access to them via personal access token (also known as PAT). PAT can be created in "Developer settings" panel.

How to use it?

Create a new GitHub Actions workflow as follows:

name: Build and publish a Docker image to ghcr.io
on:

  # publish on releases, e.g. v2.1.13 (image tagged as "2.1.13" - "v" prefix is removed)
  release:
    types: [ published ]

  # publish on pushes to the main branch (image tagged as "latest")
  push:
    branches:
      - master

jobs:
  docker_publish:
    runs-on: "ubuntu-20.04"

    steps:
      - uses: actions/checkout@v2

      # https://github.com/marketplace/actions/push-to-ghcr
      - name: Build and publish a Docker image for ${{ github.repository }}
        uses: macbre/push-to-ghcr@master
        with:
          image_name: ${{ github.repository }}
          github_token: ${{ secrets.GITHUB_TOKEN }}
          # optionally push to the Docker Hub (docker.io)
          # docker_io_token: ${{ secrets.DOCKER_IO_ACCESS_TOKEN }}  # see https://hub.docker.com/settings/security

This action assumes that your Dockerfile is in the root directory of your repository.

However, you can use dockerfile input to specify a different path (relative to the root directory of your repository). Additionaly, context input can also be provided. Docker docs should provide more context on context ;).

Labels and build args

The image that is pushed is labelled with org.label-schema and org.opencontainers schema. For instance:

{
  "org.label-schema.build-date": "2021-07-01T14:28:46Z",
  "org.label-schema.vcs-ref": "6f51d3d7bb7d46959a26594cb2b807573e34c546",
  "org.label-schema.vcs-url": "https://github.com/macbre/push-to-ghcr.git",
  "org.opencontainers.image.created": "2021-07-01T14:28:46Z",
  "org.opencontainers.image.revision": "6f51d3d7bb7d46959a26594cb2b807573e34c546",
  "org.opencontainers.image.source": "https://github.com/macbre/push-to-ghcr.git"
}

Additonally, BUILD_DATE and GITHUB_SHA build args are passed. They can be used to set env variables:

# these two are passed as build args
ARG BUILD_DATE
ARG GITHUB_SHA

ENV BUILD_DATE=$BUILD_DATE
ENV GITHUB_SHA=$GITHUB_SHA

For instance:

BUILD_DATE=2021-07-01T12:52:03Z
GITHUB_SHA=26b095f37cdf56a632aa2235345d4174b26e1d66

Optional pushes to Docker Hub (docker.io)

On 18th June 2021 Docker Hub discontinued Autobuilds on the free tier. However, you can use this action to additionally push to docker.io repository.

  1. You will need an access tokens created via https://hub.docker.com/settings/security.
  2. Store it in your GitHub repository secrets, e.g. as DOCKER_IO_ACCESS_TOKEN.
  3. Provide additional option in with section in action invocation:
      # (...)
      - name: Build and publish a Docker image for ${{ github.repository }}
        uses: macbre/push-to-ghcr@master
        with:
          image_name: ${{ github.repository }}
          github_token: ${{ secrets.GITHUB_TOKEN }}
          docker_io_token: ${{ secrets.DOCKER_IO_ACCESS_TOKEN }}  # optionally push to the Docker Hub (docker.io)\

Your image will be pushed to both ghcr.io and docker.io repositories using the name provided as image_name.

push-to-ghcr's People

Contributors

dependabot[bot] avatar macbre avatar rfranks-securenet avatar

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.