gitlab-runner - 将 docker 图像部署到服务器

gitlab-runner - deploy docker image to a server

我可以使用 docker 图像设置一个 gitlab-runner,如下所示:-

stages:
  - build
  - test
  - deploy

image: laravel/laravel:v1

build:
  stage: build
  script: 
    - npm install
    - composer install
    - cp .env.example .env
    - php artisan key:generate
    - php artisan storage:link

test:
  stage: test
  script: echo "Running tests"    

deploy_staging:
  stage: deploy
  script:
    - echo "What shall I do?"
  environment:
    name: staging
    url: https://staging.example.com
  only:
  - master

它可以通过构建阶段和测试阶段,我相信 docker image/container 可以部署了。从 Google,我观察到它可能会使用 "docker push" 进行下一步,例如推送到 AWS ECS,或 Gitlab 的某个地方。其实我想明白,如果我可以直接将它推送到另一个远程服务器(例如通过scp)?

docker 图像是使用 docker build 命令时构建的不同图层的组合。它重用现有图层并为 combination of layers 命名,即您的图像名称。它们通常存储在 /var/lib/docker.

中的某处

一般来说,所有必要的数据都存储在您的系统上,是的。但是不建议直接将这些层复制到不同的机器上,我不太确定这是否能正常工作。 Docker 建议您使用 "docker registry". Installing an own registry on your remote server is very simple, because the registry can also be run as a container (see the docs).

我建议您坚持使用 docker 团队提出的解决方案,如果您有敏感数据,请使用 public DockerHub 注册表或自己的注册表。

您正在使用 GitLab。 GitLab provides its own registry. You can push your images to your own Gitlab registry and pull it from your remote server. Your remote server only needs to authenticate against your registry and you're done. GitLab's CI can directly build and push your images to your own registry on each push to the master-branch, for example. You can find many examples in the docs.