Better understanding Composer registry

How gitlab create composer package to registry ?

I’m currently working on building several “module” to be usable throuhg “composer” cli.
In some of this module i have to build “assets” with node/npm and webpack.

For those tasks I used gitlab CI to :

  1. Create a build stage with node image. I can see “assets” built.
  2. Create a task to generate composer package.

I though, by using artifacts, i could create a package with freshly built assets.
But it seems that the package never embed thoses statics/built assets.
My question is :

How gitlab create composer package ?
Does he only git pull and “zip” the repository via composer.json ?
Is there any “guidelines” to setup a CI with build and publish package ?
Is there any manual “curl post” with already zipped package command to upload to gitlab package registry ?

My first idea is to build, then push to the repository and finally trigger the “curl” command to create the composer package has a workaround.

Thanks in advance !

PS: English is not my native language. Be kind :slight_smile: with me :smiley:

4 Likes

Have you been able to resolve this problem by now?
I’m also having this problem and I did not quite get what I could do to get it solved.
One idea that I am investigating:

  1. CI job to build a ZIP
  2. Upload it as generic package to the package registry
  3. Somehow integrate it in my target project as composer artifact (which seems to only work locally)

I will post it here when I find a solution.

Hi @haynzz.
I did not find a “good” solution for the moment. I hope there might be a solution from Gitlab.
But !

The only “way” i could make it work is to setup a step which built all the artefacts. Then push it to the repository (With a tag) then launch a build from this “new” tag.

But i would find a more “dynamic” solution.

1 Like

Hi @valentin-ed.
thanks for getting back.
What you mention is actually my backup plan.
I am also looking into post-install-scripts via composer. But it does not feel like an elegant solution. Since the target machine would need npm installed.
I also think gitlab should find a solution.
Do you think it makes sense that we open an issue for it?

3 Likes

Hey there,
almost two years later I’m looking for a solution to the same issue.
Did you manage to find an elegant way to do this?

Same use-case and same question: Embedding JS assets built with the CI as part of the composer package

1 Like

So I’ve found an incredibly ugly solution to this, but unless Gitlab implements this soon I’ll be switching to another registry. Annoyingly, many have the same shortcoming with not being able to upload artifacts/zip-files…

Basically you extract the zip file and upload it as a branch, create the composer package, then delete the branch again.

Excuse the formatting, Gitlab Composer Artifacts · GitHub

Technically, when a package is created, it creates a link to a git-tag, which then leverages the git export feature. So there is no way of adding files to the package on-the-fly.

Due to this, you can add your assets to your project. So everything in the repo is “the package” only
files/folder ignored using a .gitattributes file are excluded.
https://git-scm.com/docs/gitattributes

On top of this, you can create a job for building the assets. If changes in git are detected, let it fail.

1 Like