Deploy FTP server as a service

Hi I am currently trying to setup an FTP server for testing, but somehow the ftp server cannot be accessed.

So far I have tried two options:

.robot_test_linux:        
    image: some_images_containing_robotframework_test_env
    variables:
        FTP_USER: test1
        FTP_PASS: test1
        PASV_ADDRESS: 127.0.0.1
    services:
        - name: $CI_CONTAINER_LINUX_IMAGE
          alias: api_service
          
    before_script:
        - apt-get update
        - apt-get install -y vsftpd
        - apt-get install -y ftp
        - sed -i 's/#utf8_filesystem=YES/utf8_filesystem=YES/g' /etc/vsftpd.conf
        - sed -i 's/#write_enable=YES/write_enable=YES\n#local_root/g' /etc/vsftpd.conf
        - sed -i 's/#local_root/local_root=./g' /etc/vsftpd.conf
        - sed -i 's#local_root=.#local_root=/ftp/server#g' /etc/vsftpd.conf
        - mkdir /ftp
        - mkdir $FTP_CLIENT_PATH
        - mkdir $FTP_SERVER_PATH
        - touch $FTP_SERVER_PATH/$FTP_FILE_TO_DOWNLOAD
        - touch $FTP_SERVER_PATH/$FTP_FILE_TO_BE_DEL
        - touch $FTP_CLIENT_PATH/$FTP_FILE_TO_UPLOAD
        - sed -i "s#/bin/sh#/bin/sh\n/sbin/nologin#g" /etc/shells
        - useradd -d $FTP_CLIENT_PATH -s /sbin/nologin $FTP_USER
        - usermod --password $(echo $FTP_PASS | openssl passwd -1 -stdin) $FTP_USER
        - chown $FTP_USER:$FTP_PASS /
        - chmod o+w $FTP_SERVER_PATH
        - /etc/init.d/vsftpd start
        - echo -e 'user test1 test1\nls' | ftp -nv PASV_ADDRESS
        - curl ftp://test1:test1@127.0.0.1

    script:
        - echo "Run robot test cases under Linux environment"        
        # running tests
        - cd test
        - ls -al
        - python -m sail_test_runner

these approach will give me:


so, the ftp server is up, but api from $CI_CONTAINER_LINUX_IMAGE service cannot access it

another approach is to wrap-up the tfp server setup as a docker image, and run it as a service:
Dockerfile:

FROM ubuntu
RUN apt-get update
RUN apt-get install -y vsftpd
RUN apt-get install -y ftp
RUN sed -i 's/#utf8_filesystem=YES/utf8_filesystem=YES/g' /etc/vsftpd.conf
RUN sed -i 's/#write_enable=YES/write_enable=YES\n#local_root/g' /etc/vsftpd.conf
RUN sed -i 's/#local_root/local_root=./g' /etc/vsftpd.conf
RUN sed -i 's#local_root=.#local_root=/ftp/server#g' /etc/vsftpd.conf
RUN mkdir /ftp
RUN mkdir /ftp/client
RUN mkdir /ftp/server
RUN touch /ftp/server/ftpclientconf.json
RUN touch /ftp/server/deletes.txt
RUN touch /ftp/client/uploads.txt
RUN sed -i "s#/bin/sh#/bin/sh\n/sbin/nologin#g" /etc/shells
RUN useradd -d /ftp/client -s /sbin/nologin test1
RUN usermod --password $(echo test1 | openssl passwd -1 -stdin) test1
RUN chown test1:test1 /
RUN chmod o+w /ftp/server
EXPOSE 20 21 54400

CMD ["/etc/init.d/vsftpd", "start"]

and use it in .gitlab-ci.yml as $FTP_IMAGE

.robot_test_linux:        
    image: some_images_containing_robotframework_test_env
    variables:
        FTP_USER: test1
        FTP_PASS: test1
        PASV_ADDRESS: 127.0.0.1
    services:
        - name: $CI_CONTAINER_LINUX_IMAGE
          alias: api_service
        - name: $FTP_IMAGE
          alias: ftp_server
          
    before_script:
        - echo -e 'user test1 test1\nls' | ftp -nv PASV_ADDRESS
        - curl ftp://test1:test1@127.0.0.1
    script:
        - echo "Run robot test cases under Linux environment"        
        # running tests
        - cd test
        - ls -al
        - python -m sail_test_runner

In this case, the ftp service is up in the docker image


but the host cannot access it

I am new to the CICD, not quite sure if I set the docker images, and connections properly :rofl:

Thanks for taking time reading it, any help would be appreciated! :blush: