Commit 0605a8fc authored by Price, Zach's avatar Price, Zach
Browse files

Initial commit

parents
Loading
Loading
Loading
Loading
Loading

.dockerignore

0 → 100644
+4 −0
Original line number Diff line number Diff line
*.py[oc]
Dockefile
helm
.git

.gitignore

0 → 100644
+3 −0
Original line number Diff line number Diff line
__pycache__
*.py[co]
*.egg-info

.gitlab-ci.yml

0 → 100644
+140 −0
Original line number Diff line number Diff line
workflow:
  rules:
  - if: $CI_MERGE_REQUEST_IID
  - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH

stages:
- test-chart
- build
- deploy


variables:
  IMAGE_REPO: camden.ornl.gov/arm/adl
  PROJECT_NAME: adl
  FF_GITLAB_REGISTRY_HELPER_IMAGE: 'true'

chart_lint:
  stage: test-chart
  image: camden.ornl.gov/hub_proxy/alpine/helm:latest
  tags:
    - arm-k8s
  script:
    - helm lint helm/adl

build-image:
  stage: build
  image:
    name: gcr.io/kaniko-project/executor:debug
    entrypoint: [""]
  tags:
    - arm-k8s
  script:
  - echo "{\"auths\":{\"camden.ornl.gov\":{\"username\":\"$REPO_ROBOT\",\"password\":\"$REPO_TOKEN\"}}}" > /kaniko/.docker/config.json
  - >
    /kaniko/executor
    --cache=true
    --context "$CI_PROJECT_DIR"
    --dockerfile Dockerfile
    --destination "$IMAGE_REPO:$CI_COMMIT_SHORT_SHA"
    --destination "$IMAGE_REPO:latest"

build_chart:
  stage: build
  image: camden.ornl.gov/hub_proxy/alpine/helm:latest
  tags:
    - arm-k8s
  needs:
  - job: chart_lint
  artifacts:
    reports:
      dotenv: chart-build.env
  before_script:
    - apk add --update --no-cache git
  script:
  - |
    CHART_VERSION=$(helm show chart helm/adl | sed -n 's/^version: \(.*\)$/\1/p')
    echo "Repo chart version is ${CHART_VERSION}"
    CHART_VERSION="${CHART_VERSION}-snapshot+${CI_COMMIT_SHORT_SHA}"
    echo "Augmented chart version is ${CHART_VERSION}"
    echo "CHART_VERSION=${CHART_VERSION}" >> chart-build.env
    helm plugin install https://github.com/chartmuseum/helm-push
    helm push helm/adl --username "${REPO_ROBOT}" --password "${REPO_TOKEN}" --version="${CHART_VERSION}" https://camden.ornl.gov/chartrepo/arm --debug

deploy:
  stage: deploy
  environment:
    name: review/$CI_BUILD_REF_NAME
    url: https://api-$PROJECT_NAME-$CI_BUILD_REF_SLUG.k8s.arm.gov/docs
    on_stop: stop_review
  image: camden.ornl.gov/hub_proxy/alpine/helm:latest
  tags:
    - arm-k8s
  needs:
  - job: build_chart
    artifacts: true
  - job: build-image
  rules:
  - if: $CI_MERGE_REQUEST_IID
  before_script:
    - apk add --update --no-cache git
  script:
  - >
    helm upgrade $PROJECT_NAME-$CI_BUILD_REF_SLUG adl
    --install
    --username "$REPO_ROBOT"
    --password "$REPO_TOKEN"
    --repo https://camden.ornl.gov/chartrepo/arm
    --version ${CHART_VERSION}
    --namespace adl-review
    --debug
    --atomic
    --set config.db.username=$PGDB_USER
    --set config.db.password=$PGDB_PASS
    --set ingress.url=api-$CI_BUILD_REF_SLUG.k8s.arm.gov

stop_review:
  stage: deploy
  environment:
    name: review/$CI_BUILD_REF_NAME
    url: https://$PROJECT_NAME-$CI_BUILD_REF_SLUG.k8s.arm.gov/docs
    action: stop
  image: camden.ornl.gov/hub_proxy/alpine/helm:latest
  when: manual
  only:
  - pipelines
  tags:
    - arm-k8s
  script: helm delete $PROJECT_NAME-$CI_BUILD_REF_SLUG -n adl-review

deploy:prod:
  stage: deploy
  environment:
    name: production
    url: https://api.k8s.arm.gov
  image: camden.ornl.gov/hub_proxy/alpine/helm:latest
  tags:
    - arm-k8s
  needs:
  - job: build_chart
    artifacts: true
  - job: build-image
  rules:
  - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
  before_script:
    - apk add --update --no-cache git
  script:
  - >
    helm upgrade $PROJECT_NAME adl
    --install
    --username "$REPO_ROBOT"
    --password "$REPO_TOKEN"
    --repo https://camden.ornl.gov/chartrepo/arm
    --version ${CHART_VERSION}
    --namespace adl
    --debug
    --atomic
    --set config.db.username=$PGDB_USER
    --set config.db.password=$PGDB_PASS
    --set ingress.url=api.k8s.arm.gov
    # --set ingress.className=external

Dockerfile

0 → 100644
+4 −0
Original line number Diff line number Diff line
FROM camden.ornl.gov/hub_proxy/centos/python-38-centos7:latest
COPY app app
RUN pip install --no-cache-dir ./app
CMD ["uvicorn", "ADL.api.app:app", "--host", "0.0.0.0"]

app/ADL/__init__.py

0 → 100644
+1 −0
Original line number Diff line number Diff line