caprover / caprover-cli

Command Line Interface for https://github.com/caprover/caprover
72 stars 39 forks source link

Positional parameter not supported: test #85

Closed dankore closed 3 years ago

dankore commented 3 years ago

test is the name of my Caprover app

Dockerfile:

FROM node:14-alpine

RUN apk update && apk upgrade && \
    apk add --no-cache git
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY ./package.json /usr/src/app/
RUN npm install --production && npm cache clean --force
COPY ./ /usr/src/app

ENV NODE_ENV production
ENV PORT 80
EXPOSE 80

RUN npm run build

CMD [ "npm", "start" ]

.gitlab-ci.yml

build-docker-master:
  image: docker:19.03.1
  stage: build
  services:
    - docker:19.03.1-dind
  before_script:
    - export DOCKER_REGISTRY_USER=$CI_REGISTRY_USER # built-in GitLab Registry User
    - export DOCKER_REGISTRY_PASSWORD=$CI_REGISTRY_PASSWORD # built-in GitLab Registry Password
    - export DOCKER_REGISTRY_URL=$CI_REGISTRY # built-in GitLab Registry URL
    - export COMMIT_HASH=$CI_COMMIT_SHA # Your current commit sha
    - export IMAGE_NAME_WITH_REGISTRY_PREFIX=$CI_REGISTRY_IMAGE # Your repository prefixed with GitLab Registry URL
    - docker login -u "$DOCKER_REGISTRY_USER" -p "$DOCKER_REGISTRY_PASSWORD" $DOCKER_REGISTRY_URL # Instructs GitLab to login to its registry

  script:
    - echo "Building..." # MAKE SURE NO SPACE ON EITHER SIDE OF = IN THE FOLLOWING LINE
    - export CONTAINER_FULL_IMAGE_NAME_WITH_TAG=$IMAGE_NAME_WITH_REGISTRY_PREFIX/my-build-image:$COMMIT_HASH
    - docker build -f ./Dockerfile --pull -t built-image-name .
    - docker tag built-image-name "$CONTAINER_FULL_IMAGE_NAME_WITH_TAG"
    - docker push "$CONTAINER_FULL_IMAGE_NAME_WITH_TAG"
    - echo $CONTAINER_FULL_IMAGE_NAME_WITH_TAG
    - echo "Deploying on CapRover..."
    - docker run caprover/cli-caprover:v2.1.1 caprover deploy --caproverUrl $CAPROVER_URL --caproverPassword $CAPROVER_PASSWORD --caproverApp $CAPROVER_APP --imageName $CONTAINER_FULL_IMAGE_NAME_WITH_TAG
  only:
    - master

image

githubsaturn commented 3 years ago

You probably have a space somewhere in your vars. Double check: CAPROVER_URL , CAPROVER_PASSWORD , CAPROVER_APP

dankore commented 3 years ago

@githubsaturn, thank you.

I had CAPROVER_PASS instead of CAPROVER_PASSWORD.

Worked like a charm!

dankore commented 3 years ago

Now i'm having this error:

Error: (HTTP code 500) server error - Head https://registry.gitlab.com/v2/ds-templates/nextjs-mongodb/my-build-image/manifests/dfcde68d6519503c19793b9f102d9de8160c2aff: denied: access forbidden

{"errors":[{"code":"UNAUTHORIZED","message":"authentication required","detail":[{"Type":"repository","Class":"","Name":"ds-templates/nextjs-mongodb/my-build-image","Action":"pull"}]}]}

image

Any help would be greatly appreciated!

githubsaturn commented 3 years ago

Make sure you follow steps 4 and 5 here: https://caprover.com/docs/ci-cd-integration.html#4--create-an-access-token-for-caprover

dankore commented 3 years ago

Make sure you follow steps 4 and 5 here: https://caprover.com/docs/ci-cd-integration.html#4--create-an-access-token-for-caprover

I did. In fact, I created another access token. The previous one was never used.

But also, the CI/CD won't run if I don't enable the shared runners or register mine. No mention of that in the tutorial link you shared. Maybe I missed something?

githubsaturn commented 3 years ago

The tutorial is for an individual account. Shared runners are for orgs and group I imagine (?)

There is also another similar issue here: https://github.com/caprover/caprover-cli/issues/84 They ended up creating a new account and it worked... Now they are trying to find out what is the difference between the old and new account that caused the old account to break.

dankore commented 3 years ago

I confirmed your suspicion @githubsaturn, I was getting 500 HTTPS server error because the repo belonged in a group in Gitlab.

I created a new project (repo) that does not belong to a group and it worked!

Same solution for issue #84

If anyone has a solution for a grouped projects please post.

githubsaturn commented 3 years ago

You can follow up with gilab folks on what the difference is between group and individual projects. But from CapRover side, there is no distinction as long as you define the image prefix and username correctly.

genox commented 3 years ago

Just as an FYI in case someone ends up here via google:

I ran into this error on GitLab CI/CD due to the fact that Group variables are, by default, set to be only available in protected branches. "master" is protected by default, which is why every other branch will cause failed build since group env vars are empty. You can make group variables available in unprotected branches:

Screenshot 2021-08-15 at 12 37 55