GithubHelp home page GithubHelp logo

macbre / push-to-ghcr Goto Github PK

View Code? Open in Web Editor NEW
23.0 4.0 11.0 102 KB

This action simplifies pushes of Docker images to ghcr.io repository and the Docker Hub

License: MIT License

Dockerfile 100.00%
ghcr actions-docker containers github-actions-docker opencontainers continuous-delivery docker github-actions

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

Additionally, this action will also automatically lowercase the repository name to be able to push an image to Docker.

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 }}  # it will be lowercased internally
          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
          # customize the username to be used when pushing to the Docker Hub
          # docker_io_user: foobar  # see https://github.com/macbre/push-to-ghcr/issues/14

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 ;).

Input parameters

  • github_token (required): Your secrets.GITHUB_TOKEN
  • image_name (required): Image name, e.g. my-user-name/my-repo (will be lowercased internally)
  • dockerfile (defaults to ./Dockerfile): A path to the Dockerfile (if it's not in the repository's root directory)
  • context (defaults to .): A path to the context in which the build will happen, see https://docs.docker.com/engine/reference/commandline/build/
  • repository (defaults to ghcr.io): Docker repository to push an image to
  • docker_io_user: A username to use when pushing an image to docker.io (defaults to the github.actor)
  • docker_io_token: Your docker.io token created via https://hub.docker.com/settings/security
  • image_tag: Image tag, e.g. latest. Will overwrite the tag latest tag on a push, and have no effect on a release

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 tobiasc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

push-to-ghcr's Issues

Feature request: multiple tags

It would be nice to be able to apply multiple tags to the built image.

For example, I want to tag my images with the name of the branch they were built from to make it easier to deploy to different environments. It would also be convenient to have them tagged with the git commit SHA, while still keeping the latest tag.

Superfluous Docker Hub warning

Every time I use this action I get a warning that the image wasn't uploaded to Docker Hub. Since I don't want to upload the image to Docker Hub and I like to treat warnings as errors, it would be nice if there was a way to silence this warning.

Job fails if repo name includes UPPER CASE leters

Build Job fails if repo includes a upper case letters as my one.

Building the Docker image: ghcr.io/TheHolm/meraki-dashboard-promethus-exporter:latest ...
  invalid argument "ghcr.io/TheHolm/meraki-dashboard-promethus-exporter:latest" for "-t, --tag" flag: invalid reference format: repository name must be lowercase
  See 'docker build --help'.
  Error: Process completed with exit code 125.

Problem lays in line 71 of action.yaml
--tag ${{ inputs.repository }}/${{ inputs.image_name }}:${COMMIT_TAG}

I'm not sure how to fix it. Is it possible to use something like ${{ inputs.repository | lower }} in action syntax.

Image Tag

Can you not set a Image Tag as a Param?

Exit With Error If Push Fails

Currently, the jobs shows as successfully ran even if the push actually failed. This makes taking a quick look to see if a push succeeded impossible.

For instance, if the image does not exist yet:

denied: permission_denied: The requested installation does not exist.

or if the action cannot push to the specific package:

denied: permission_denied: write_package

both of these are failures, but the run exits as if everything went just fine
image

Error when using Github Actions and building with Docker 23

We encountered a build error when running Github Actions and building the Dockerfile with Docker 23.0.6, whereas it worked on Docker 20.10.25.
The error message read: ERROR: failed to get console: provided file is not a console

We didn't upgrade on purpose, as I'm not even sure where the Docker config is located, so this probably happened due to some other upgrade or rebuilt of upstream dependencies.

I wasn't able to find much/anything on this error specifically, but the Docker build flag TTY was mentioned in a few Stack Overflow posts that seemed vaguely related, eg. https://stackoverflow.com/questions/70855915/fix-panic-provided-file-is-not-a-console-from-docker-compose-in-github-action

I noticed that the TTY flag was used in this line: https://github.com/macbre/push-to-ghcr/blob/master/action.yml#L93

I forked the repo and tried removing that line and it worked. master...tobiasc:push-to-ghcr:master

Working (Docker 20)
Docker_20

Broken (Docker 23 + original repo)
Docker_23

Fixed (Docker 23 + forked with fix repo)
Docker_23_fixed

Error when using Github Actions and building with Docker 23 persists

In #29 @tobiasc laid out screenshots and information demonstrating an error when running the action in Docker 23. #30 was intended to fix this and has since been merged to master, however, when using master per the README I continue to experience this error.

I tried using v13, the tag associated with @tobiasc 's fix just in case but found that did not work either.

  docker_publish:
    runs-on: "ubuntu-20.04"
    steps:
      - name: Build and publish a Docker image for ${{ github.repository }}
        uses: macbre/push-to-ghcr@v13
        with:
          image_name: ${{ github.repository }}
          image_tag: $(date +%s)
          github_token: ${{ secrets.GITHUB_TOKEN }}

push-to-ghcr-fail

Feature Request: add NODE_AUTH_TOKEN build arg

Hello and thanks for the work.

I am currently building docker images that need to perform npm install with authentication (scoped npm packages on github). The clean way to achieve this is to pass an environment variable called NODE_AUTH_TOKEN, and it should be passed through a --build-arg.

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.