# Self Hosted

First you need to obtain token allows you to access Adapptio repository. For this, please, contact us.

### Building image with GitLab CI/CD pipeline

#### Create new repositry

Once you have created a new repository, you also need to add several variables to your pipeline. Go to the CI/CD Gitlab settings (Settings -> CI/CD -> Variables) and add:

1. ARTIFACTS\_LOGIN = \<your-app-id>
2. ARTIFACTS\_TOKEN = \<obtained-token>

#### Dockerfile

Add to your repository this dockerfile.

{% code title="prod.Dockerfile" lineNumbers="true" %}

```docker
ARG BASE_TAG

FROM ${BASE_IMAGE}:${BASE_TAG} as runtime

ARG BLUEPRINTS_DIR

# add blueprints
RUN rm -rf ./repo
ADD ${BLUEPRINTS_DIR} ./repo

```

{% endcode %}

#### CI/CD pipeline

And finaly add the CI/CD files and fill all the variables in the `.param.yaml` and `.gitlab-ci.yaml` file (section between lines 16 and 24).

{% code title=".params.yaml" lineNumbers="true" %}

```yaml
variables:
  # Change this to update Adapptio runtime image
  # Example "v9597de1b-master"
  BASE_TAG: "<adapptio-image-version>"
  # Change this to update application version
  # Example: "v3"
  BLUEPRINT_TAG: "<application-version>"
```

{% endcode %}

{% code title=".gitlab-ci.yml" lineNumbers="true" %}

```yaml
 include: ".params.yaml"
 
 services:
   - docker:20.10.2-dind

stages:
  - download-blueprints
  - build-image

variables:
  IMAGE_NAME: ${CI_REGISTRY}/${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}
  IMAGE_TAG: v${CI_COMMIT_SHORT_SHA}-${CI_COMMIT_REF_SLUG}
  BASE_IMAGE: "artifacts.adapptio.app:5000/adapptio/hae/app"
  REPO_BASE_URL: "https://artifacts.adapptio.app:5001/artifacts"
  
  # ---
  # SETUP THIS VARIABLES
  # Set UUID of your organization
  # Example: "b9fbdcb2-fe44-45a6-836e-585715b3457a"
  REPO_ORG_ID: "<your-org-id>"
  # Set UUID of your application
  # Example: "83110cc7-ea98-4a8f-a2ef-68f9d6fe1b27"
  REPO_APP_ID: "<your-app-id>"
  # ---
  
download-blueprints:
  stage: download-blueprints
  image:
    name: ubuntu:latest
  script:
    - apt-get update && apt-get -y install wget
    - |
      wget \
        --user="${ARTIFACTS_LOGIN}" \
        --password="${ARTIFACTS_TOKEN}" \
        -O ./blueprints.tar.gz \
        ${REPO_BASE_URL}/${REPO_ORG_ID}/${REPO_APP_ID}/${BLUEPRINT_TAG}.tar.gz
    - tar -xf ./blueprints.tar.gz
  artifacts:
    paths:
      - ./${REPO_APP_ID}
    expire_in: 1 hour

build-image:
  stage: build-image
  image:
    name: gcr.io/kaniko-project/executor:v1.9.0-debug
    entrypoint: [""]
  before_script:
    - echo "Building ${IMAGE_NAME}:${IMAGE_TAG}"
    - echo -n ${IMAGE_TAG} > version
    - mkdir -p /kaniko/.docker
    - |
      echo "{ \"auths\": { \"$CI_REGISTRY\": { \"username\": \"${CI_REGISTRY_USER}\", \"password\": \"${CI_REGISTRY_PASSWORD}\" }, \"artifacts.adapptio.app:5000\": { \"username\": \"${ARTIFACTS_LOGIN}\", \"password\": \"${ARTIFACTS_TOKEN}\" }} }" > /kaniko/.docker/config.json
  script:
    - |
      /kaniko/executor  --context ${CI_PROJECT_DIR} \
                        --dockerfile ${CI_PROJECT_DIR}/prod.Dockerfile \
                        --destination ${IMAGE_NAME}:${IMAGE_TAG} \
                        --build-arg BASE_IMAGE="${BASE_IMAGE}" \
                        --build-arg BASE_TAG="${BASE_TAG}" \
                        --build-arg BLUEPRINTS_DIR="./${REPO_APP_ID}"
```

{% endcode %}

### Testing deployment using Docker compose

Create docker compose file in a workspace on your computer.

{% code title="docker-compose.yaml" lineNumbers="true" %}

```yaml
services:
  adapptio:
    image: "registry.gitlab.com/<your-gitlab-project>:<app-image-version>"
    ports:
      - "8080:8080"
    environment:
      - NODE_ENV=production
      - APP_MANIFEST_PATH=/app/hae-bld-app/repo
      - APP_ID=<your-application-id>
      - APP_ENV_ID=<your-application-environment-id>
      - APP_NAME=<application-name>
      - APP_URL=localhost:8080
      - APP_URL_PROTOCOL=<http|https>
      - SESSION_SECRET=<session-secret>
      - ...<YOUR_OWN_ENV_VARS>
```

{% endcode %}

Run docker and type:

```
cd <your-workspace-folder>
docker-compose up
```

The application should be available at URL:

```
https://localhost:8080
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.adapptio.com/deployment/self-hosted.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
