larshei

larshei

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 · GitHub 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?

Showing Posts 1 to 2

larshei

larshei OP

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
larshei

larshei OP

There is an alternate solution if you prefer SSH over HTTPS.

Check out the following action for instructions on how to set it up.

https://github.com/webfactory/ssh-agent

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews