리셋 되지 말자

gitlab runner shell executor 본문

GitLab

gitlab runner shell executor

kyeongjun-dev 2022. 6. 16. 18:52

dind에서 shell로 변경

기존 .gitlab-ci.yml 스크립트

stages:          # List of stages for jobs, and their order of execution
  - build
  - test
  - deploy

variables:
  DOCKER_HOST: tcp://docker:2375
  DOCKER_TLS_CERTDIR: ""

build-job:       # This job runs in the build stage, which runs first.
  stage: build
  image: docker:20.10.13
  services:
    - docker:20.10.13-dind
  script:
    - echo "Start build"
    - export AWS_ACCESS_KEY_ID="$AWS_ACCESS_KEY_ID"
    - export AWS_SECRET_ACCESS_KEY="$AWS_SECRET_ACCESS_KEY"
    - export AWS_DEFAULT_REGION="$AWS_DEFAULT_REGION"
    - export ECR_URL="$ECR_URL"
    - date "+%Y-%m-%d %I:%M:%S %p"
    - apk add --no-cache python3 py3-pip
    - pip3 install --upgrade pip
    - pip3 install awscli
    - aws --version
    - aws ecr get-login-password --region ${AWS_DEFAULT_REGION} | docker login --username AWS --password-stdin ${ECR_URL}
    - date "+%Y-%m-%d %I:%M:%S %p"
    - python3 get_max_swap_size.py &
    - export GET_SWAP_PID=$!
    - time docker build --build-arg AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID --build-arg AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY --build-arg AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION --build-arg ECR_URL=$ECR_URL -t ${ECR_URL}/csapi/celery:latest celery/
    - echo "Used Max Swap Size of Build"
    - cat swap_size
    - echo "Start Unit Test"
    - time docker run -i --rm ${ECR_URL}/csapi/celery:latest python -m unittest csapi/unit_test.py
    - echo "Used Max Swap Size of Unit Test"
    - cat swap_size
    - echo "After script"
    - aws s3api delete-object --bucket csapi-bucket --key images/separated-images/test_output.png
    - echo "Deploy docker image"
    - time docker push ${ECR_URL}/csapi/celery:latest
    - echo $GET_SWAP_PID
    - ps -ef | grep get_max_swap_size
    - kill $GET_SWAP_PID
    - ls
    - cat swap_size

unit-test-job:   # This job runs in the test stage.
  stage: test    # It only starts when the job in the build stage completes successfully.
  script:
    - echo "Running unit tests... This will take about 60 seconds."
    - echo "Code coverage is 90%"

lint-test-job:   # This job also runs in the test stage.
  stage: test    # It can run at the same time as unit-test-job (in parallel).
  script:
    - echo "Linting code... This will take about 10 seconds."
    - echo "No lint issues found."

deploy-job:      # This job runs in the deploy stage.
  stage: deploy  # It only runs when *both* jobs in the test stage complete successfully.
  script:
    - echo "Deploying application..."
    - echo "Application successfully deployed."
  # tags:
  #   - "gitlab-org-docker"

 

변경 후 스크립트

사전작업 - python3.8 설치, alias 설정

sudo amazon-linux-extras install python3.8
alias python=python3.8

 

Comments