larshei

larshei

Fetch private GitHub dependency in GitHub Action with Access Token

My projects are built/pushed as docker containers (for uniform deployment/handling with apps written in other languages). Everything worked fine, until I added a private repository from our organisation as a dependency.

After having done this in a previous job, I cannot get it to work now :sweat_smile:

User + Access Token

Previously, we simply had a “machine user” (normal user account created for the organization) and we then used their username + personal access token.

In our Dockerfile, we’d just replace any access to GitHub with basic auth using the service users credentials, something like this:

# Dockerfile

[container setup / install dependencies]

ARG GITHUB_USERNAME
ARG GITHUB_TOKEN
RUN git config --global url."https://$GITHUB_USERNAME:$GITHUB_TOKEN@github.com".insteadOf "https://github.com"

[mix commands]

Now, when passing the GITHUB_USERNAME and GITHUB_TOKEN as arguments to the docker build container, I get the following error:

1.215 remote: Support for password authentication was removed on August 13, 2021.

I am pretty sure I have used this method til summer 23, so I am bit confused.

GitHub Action Parameter

We use the GitHub - docker/build-push-action: GitHub Action to build and push Docker images with Buildx action to build the container. It has a parameter “GIT_AUTH_TOKEN” which states:

If you want to authenticate against another private repository, you have to use a secret named GIT_AUTH_TOKEN to be able to authenticate against it with Buildx:

however, this lead to:

fatal: could not read Username for ‘https://github.com’: No such device or address

which then lead me to fatal: could not read Username for 'https://github.com': No such device or address · Issue #1112 · docker/build-push-action · GitHub which brought me back to

1.304 remote: Support for password authentication was removed on August 13, 2021.

How?

How do you authorize for private repositories in docker during mix deps.get?

Marked As Solved

larshei

larshei

Got it.

For anyone wondering how to pull private repositories during mix.compile using the docker-build-push GitHub action:

Create Access Token

Create a Personal Access Token (Sign in to GitHub · GitHub ; Navigation: Profile > Settings > Developer Settings > Personal Access Tokens > Fine Grained Tokens). It should be able to read repositories you have access to.

Consider using a “machine user”, as in a normal user account that was created just for the purpose of holding your tokens, if you are an organisation.

Add token as Secret

Create a secret in your organisation or repository, e.g. CI_ACCESS_TOKEN. (Repo: Settings > Secrets and Variables > Actions). Put in your previously created token. I made the mistake of adding it to an “environment” by accident at first and wondered why it was not working as intended.

Set up workflow file

In your github workflow file:

   - name: Build and push
     uses: docker/build-push-action@v5
     with:
       context: .
       file: ./Dockerfile
       push: true
       tags: ...
       secrets: |
         GIT_AUTH_TOKEN=${{ secrets.CI_ACCESS_TOKEN }}

Dockerfile

in your Dockefile, grab the secret, configure git, get the deps:

RUN --mount=type=secret,id=GIT_AUTH_TOKEN \
 GIT_AUTH_TOKEN=$(cat /run/secrets/GIT_AUTH_TOKEN) \
 && git config --global "url.https://${GIT_AUTH_TOKEN}@github.com.insteadof" "https://github.com" \
 && mix deps.get --only $MIX_ENV

Where Next?

Popular in Questions Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
dokuzbir
Hello, I am trying to convert my lists to string without losing brackets.For start i have 3 map. They look like these buyer = %{ id: ...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
Codball
Mix format works fine if run from the cmd. I’ve followed this to facilitate the implementation into VSC which involves downloading an ext...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

Other popular topics Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

We're in Beta

About us Mission Statement