Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e5e5e3e8 authored by Joshua Eje's avatar Joshua Eje
Browse files

Create a unified pipeline for both app and infra repo

parent e4d4a135
Loading
Loading
Loading
Loading

.env.example

0 → 100644
+11 −0
Original line number Diff line number Diff line
# Environment variables for docker-compose.yml
# All variables have defaults for local development

# Docker image tag (default: latest)
TAG=latest

# Wireguard IP for port binding (default: 127.0.0.1 for local)
WIREGUARD_IP=127.0.0.1

# Use external wireguarded network (default: false for local, true for staging/prod)
WIREGUARD_NETWORK_EXTERNAL=false
+3 −0
Original line number Diff line number Diff line
@@ -8,6 +8,9 @@ node_modules/
dist/
app/src/static/assets/sources/*/

# Environment files
.env

# Compiled Java class files
*.class

+104 −43
Original line number Diff line number Diff line
@@ -8,71 +8,132 @@
  before_script:
    - echo $CI_JOB_TOKEN | docker login -u gitlab-ci-token --password-stdin $CI_REGISTRY

docker:
  extends: .docker
.docker-compose-base:
  image: alpine:latest
  before_script:
    - mkdir $HOME/.ssh
    - chmod 700 $HOME/.ssh
    - echo "$SSH_PRIVATE_KEY_ED" > $HOME/.ssh/id_ed25519
    - echo "$SSH_PUBKEY_ED" > $HOME/.ssh/id_ed25519.pub
    - echo "$SSH_KNOWN_HOSTS" > $HOME/.ssh/known_hosts
    - chmod 600 $HOME/.ssh/id_ed25519
    - chmod 644 $HOME/.ssh/known_hosts $HOME/.ssh/id_ed25519.pub
    - apk add --update --no-cache openssh rsync

.docker-compose-deploy:
  extends: .docker-compose-base
  script:
    - echo "Deploying $CI_PROJECT_NAME to $CI_ENVIRONMENT_NAME"
    - |
      ssh $SSH_USER@$DEPLOYMENT_HOST /bin/bash -s << EOT
      set -eu
      mkdir -p $DEPLOYMENT_PATH
      cd $DEPLOYMENT_PATH
      if [ ! -d .git ]; then
        git init
        git remote add origin git@${CI_SERVER_HOST}:${CI_PROJECT_PATH}.git
      else
        git remote set-url origin git@${CI_SERVER_HOST}:${CI_PROJECT_PATH}.git
      fi
      git fetch origin
      git checkout ${CI_COMMIT_TAG:-${CI_COMMIT_REF_NAME}}
      EOT
    - |
      if [ -z "$ENV_FILE" ]; then
        echo "ERROR: ENV_FILE is not provided. Deployment cannot proceed."
        exit 1
      fi
      sed "s/TAG=latest/TAG=${CI_COMMIT_TAG:-${CI_COMMIT_REF_NAME}}/g" $ENV_FILE > deploy.env
    - rsync deploy.env $SSH_USER@$DEPLOYMENT_HOST:$DEPLOYMENT_PATH/.env
    - echo "Deploy docker compose stack on $DEPLOYMENT_HOST"
    - |
      ssh $SSH_USER@$DEPLOYMENT_HOST /bin/bash -s << EOT
      set -eu
      cd $DEPLOYMENT_PATH
      docker compose up -d --pull=always --remove-orphans
      EOT

.docker-compose-recreate:
  extends: .docker-compose-base
  script:
    - echo "Recreating stack on $DEPLOYMENT_HOST"
    - |
      ssh $SSH_USER@$DEPLOYMENT_HOST /bin/bash -s << EOT
      set -eu
      cd $DEPLOYMENT_PATH
      docker compose up -d --force-recreate
      EOT

check:
  stage: build
  image: node:23-alpine
  script:
    - docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG -f app/Dockerfile app
    - cd app
    - npm install
    - npm run check
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'

docker-build-image-latest:
  extends: .docker
  script:
    - docker build -t $CI_REGISTRY_IMAGE:latest -f app/Dockerfile app
    - docker push $CI_REGISTRY_IMAGE:latest
  when: manual
  rules:
    - if: '$CI_COMMIT_REF_NAME == "main" && $CI_PIPELINE_SOURCE != "schedule"'
    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
    - if: '$CI_COMMIT_REF_NAME == "main"'

docker-build-image-tag:
  extends: .docker
  script:
    - docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG -f app/Dockerfile app
    - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
    - docker build -t $CI_REGISTRY_IMAGE:${CI_COMMIT_TAG:-${CI_COMMIT_REF_NAME}} -f app/Dockerfile app
    - docker push $CI_REGISTRY_IMAGE:${CI_COMMIT_TAG:-${CI_COMMIT_REF_NAME}}
  rules:
    - if: '$CI_COMMIT_TAG'
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
    - if: '$CI_COMMIT_BRANCH == "main"' 

check:
  stage: build
  image: node:23-alpine
  script:
    - cd app
    - npm install
    - npm run check
deploy-stack:staging:
  stage: deploy
  extends: .docker-compose-deploy
  needs: ["docker-build-image-tag"]
  when: manual
  rules:
    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
    - if: '$CI_COMMIT_BRANCH == "main" && $CI_PIPELINE_SOURCE != "merge_request_event"'
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
  environment:
    name: staging
    url: $URL

deploy_staging:
recreate-stack:staging:
  stage: deploy
  needs: ["docker-build-image-latest"]
  rules:
    - if: '$CI_COMMIT_REF_NAME == "main" && $CI_PIPELINE_SOURCE != "schedule"'
    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
  trigger:
    inputs:
      environment: staging
    project: e/online-services/infra/web/eos-installer
    branch: main
    strategy: depend
    forward:
      pipeline_variables: true
  variables:
    DOCKER_TAG: latest
  extends: .docker-compose-recreate
  needs: ["deploy-stack:staging"]
  when: manual
  rules:
    - if: '$CI_COMMIT_BRANCH == "main" && $CI_PIPELINE_SOURCE != "merge_request_event"'
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
  environment:
    name: staging
    url: $URL

deploy_production:
deploy-stack:production:
  stage: deploy
  extends: .docker-compose-deploy
  needs: ["docker-build-image-tag"]
  when: manual
  rules:
    - if: '$CI_COMMIT_TAG'
  environment:
    name: production
    url: $URL

recreate-stack:production:
  stage: deploy
  extends: .docker-compose-recreate
  needs: ["deploy-stack:production"]
  when: manual
  rules:
    - if: '$CI_COMMIT_TAG'
  trigger:
    inputs:
      environment: production
    project: e/online-services/infra/web/eos-installer
    branch: main
    strategy: depend
    forward:
      pipeline_variables: true
  variables:
    DOCKER_TAG: $CI_COMMIT_TAG
  environment:
    name: production
    url: $URL
+25 −6
Original line number Diff line number Diff line
@@ -21,15 +21,34 @@ Install /e/OS on a device from a chromium-based browser.

## Run the project

1. Get the docker image
### Local Development

The Docker Compose setup is environment-agnostic. It reads values from `.env`, so the same `docker-compose.yml` can be used locally and in other environments with different variable values.

To run the project locally:

1. Create a local `.env` file for development:
   ```bash
   cp .env.example .env
   ```
   docker pull registry.gitlab.e.foundation/e/devices/eos-installer:latest

2. Pull the published image and start the application:
   ```bash
   docker compose up -d
   ```
2. Run a docker container

3. The app is available at http://localhost:3000

To stop it again:
```bash
docker compose down
```
    docker run -p 3000:80 eos-installer

**Alternative - Direct Docker Run:**
```bash
docker pull registry.gitlab.e.foundation/e/devices/eos-installer:latest
docker run -p 3000:80 registry.gitlab.e.foundation/e/devices/eos-installer:latest
```
3. The app is available at http://localhost:3000

## Local ZIP mode (debug)

+12 −7
Original line number Diff line number Diff line
services:
  installer:
    image: registry.gitlab.e.foundation/e/devices/eos-installer:latest
    build:
      context: app/
  eos-installer:
    image: registry.gitlab.e.foundation/e/devices/eos-installer:${TAG:-latest}
    restart: always
    ports:
      - '3000:80'
      - "${WIREGUARD_IP:-127.0.0.1}:3000:80"
    networks:
      - wireguarded

networks:
  wireguarded:
    external: ${WIREGUARD_NETWORK_EXTERNAL:-false}