Attemping to setup Gitlab credentials block and ha...
# ask-community
m
Attemping to setup Gitlab credentials block and having issues. Using an ECS pull work pool , private Gitlab repo as the source. I'm running a
deploy
script from my local machine, with a worker running locally that then launches task in AWS hosted ECS infrastructure. All of this is working, however I'm trying to improve the way I provide my credentials.
Copy code
from prefect import flow                               
from prefect.runner.storage import GitRepository
import os
from prefect_gitlab import GitLabCredentials
gitlab_credentials_block = GitLabCredentials.load("gitlab-creds")

# WORKS, however I would like my token to be sourced from the gitlab-creds block
source = GitRepository(
url="<https://myname>:{}@gitlab.com/myorg/myproject/myrepo.git".format(os.getenv("GITLAB_TOKEN")),
branch="mybranch",
)

# DOES NOT WORK - get 128 errors running this deploy script as URL is missing credentials I believe.
source = GitRepository(
url="<https://gitlab.com/myorg/myproject/myrepo.git>",
branch="mybranch",
credentials=GitLabCredentials.load("gitlab-creds")
)

if __name__ == "__main__":
    flow.from_source(
        source=source,
        entrypoint="demo/prefect/flows.py:my_flow"
    ).deploy(
        name="private-gitlab-deploy",
        work_pool_name="ecs-hybrid-micro-dev",
        )
b
Hi Matt! That's odd that you're getting a 128 error despite using the same block. Do you see any difference when using a Secret block to save your access token (instead of a GitLabCredentials block)? Something like:
Copy code
from prefect import flow
from prefect.runner.storage import GitRepository
from prefect.blocks.system import Secret


if __name__ == "__main__":
    gitlab_repo = GitRepository(
        url="<https://gitlab.com/org/my-private-repo.git>",
        credentials={
            "access_token": Secret.load("my-secret-block-with-my-gl-credentials")
        },
    )

    flow.from_source(   
        source=gitlab_repo,
        entrypoint="gl_secret_block.py:my_flow",
    ).deploy(
        name="private-gitlab-deploy",
        work_pool_name="my_pool",
    )
🙌 1
m
Thanks for the reply @Bianca Hoch - that works. I then went to try the GitLabCredentials block again and it works with no changes. Gotta love those moments 🤦
b
It's like that sometimes, ain't it?
Glad you got it working!