Score:0

Keep GitLab environment running in Docker container

cn flag

I'm aiming to deploy an environment for testing. It's a PHP application, and I could simply serve the PHP files using the embedded server.

My .gitlab-ci.yml is plain simple:

docker_test:
  stage: deploy
  image: php:7.2
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
  environment:
    name: development/$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
    url: $CI_SERVER_PROTOCOL://$CI_SERVER_HOST:8000/$CI_PROJECT_PATH_SLUG/$CI_ENVIRONMENT_SLUG:8000
    auto_stop_in: 1 hour
  script:
    - php -S 0.0.0.0:8000 -t /builds/$CI_PROJECT_PATH

What I want is: When pipeline runs, the environment will be live, the container should be up and running, and a tester should be able to access it using the URL. After one hour, or if Stop button is pressed, environment shoud stop and Docker container stopped and removed. However, I don't figure out yet, how to keep the container running in the background. When pipeline is executed, it freezes on the script, and when it's cancelled, Docker container is stopped.

Any idea on how to achieve this?

Score:0
cn flag

Seems docker runners won't allow this easily. I just changed to a shell executor that runs the required docker commands for start and stop:

docker_test:
  stage: deploy
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
  environment:
    name: development/$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
    url: $CI_SERVER_PROTOCOL://$CI_SERVER_HOST:8000/$CI_PROJECT_NAME/$CI_ENVIRONMENT_SLUG:8000
    auto_stop_in: 1 hour
  script: docker run --name $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME --rm -dt -v $CI_PROJECT_DIR:/app:Z -p 8000:8000 php:7.2 php -S 0.0.0.0:8000 -t /app

stop_docker_test:
  stage: deploy
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
  environment:
    name: development/$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
    action: stop
  when: manual
  script: docker stop $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.