diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index aac0e85..803895a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,12 +2,14 @@ name: Build and Deploy on: push: - branches: - - main + branches: [ main, staging ] + +env: + DEPLOYMENT_ENV: ${{ github.ref == 'refs/heads/main' && 'production' || 'staging' }} jobs: build: - runs-on: self-hosted + runs-on: ${{ github.ref == 'refs/heads/main' && 'self-hosted' || 'gcidp' }} steps: - name: Checkout repo uses: actions/checkout@v3 @@ -15,7 +17,8 @@ jobs: - name: Build env: POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }} - run: docker compose up --build -d + COMMIT_SHA: ${{ github.sha }} + run: docker compose -f docker-compose.${{ env.DEPLOYMENT_ENV }}.yml up -d --build - name: Cleanup run: docker system prune -f diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 003064b..57a07fd 100755 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -11,4 +11,4 @@ jobs: uses: actions/checkout@v3 - name: Build - run: docker compose build + run: docker compose -f docker-compose.production.yml build diff --git a/Dockerfile b/Dockerfile new file mode 100755 index 0000000..0fcbe41 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,4 @@ +FROM nginx:1.21.6 AS nginx +COPY nginx/default.conf /etc/nginx/conf.d/default.conf +COPY nginx/nginx.conf /etc/nginx/nginx.conf +CMD ["nginx", "-g", "daemon off;"] diff --git a/app/Dockerfile b/app/Dockerfile index 88e301f..ff4c796 100755 --- a/app/Dockerfile +++ b/app/Dockerfile @@ -1,4 +1,4 @@ -FROM node:20-alpine as build-stage +FROM node:20-alpine AS build-stage WORKDIR /app RUN npm install -g pnpm@8.15.2 @@ -6,12 +6,9 @@ COPY package.json pnpm-lock.yaml .npmrc ./ RUN pnpm i --frozen-lockfile COPY . . -FROM build-stage as prod +FROM build-stage AS prod +ARG NUXT_PUBLIC_API_URL +ENV NUXT_PUBLIC_API_URL=$NUXT_PUBLIC_API_URL RUN pnpm build CMD pnpm start:prod -FROM nginx:1.21.6 as nginx -COPY nginx/default.conf /etc/nginx/conf.d/default.conf -COPY nginx/nginx.conf /etc/nginx/nginx.conf -COPY --from=node /app/.output/public /usr/share/nginx/html -CMD ["nginx", "-g", "daemon off;"] diff --git a/app/pages/positions/import.vue b/app/pages/positions/import.vue index 301a7c5..94f6e93 100644 --- a/app/pages/positions/import.vue +++ b/app/pages/positions/import.vue @@ -74,7 +74,8 @@ async function upload() { loading.value = true; try { const {error} = await rpcService.create({ - method: 'UploadPositionsFromExcel', params: { + method: 'UploadPositionsFromExcel', + params: { fileId: fileId.value } }).exec(); diff --git a/back/config/config.json b/back/config/config.json index d9ae0de..4eab080 100644 --- a/back/config/config.json +++ b/back/config/config.json @@ -6,7 +6,7 @@ "password": "postgres", "username": "postgres" }, - "gcidp": { + "staging": { "database": "elxolding", "dialect": "postgres", "host": "elxolding_db", diff --git a/back/config/gcidp.json b/back/config/gcidp.json deleted file mode 100644 index f3b8cd9..0000000 --- a/back/config/gcidp.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "host": "staging-elxolding.apollos.studio", - "port": 3030, - "images_url": "https://api-staging-elxolding.apollos.studio/media/", - "postgres": "postgres://postgres:postgres@elxolding_db/elxolding" -} diff --git a/back/config/staging.json b/back/config/staging.json new file mode 100644 index 0000000..b897bba --- /dev/null +++ b/back/config/staging.json @@ -0,0 +1,6 @@ +{ + "host": "api-elxolding.ci.iota.uz", + "port": 3030, + "images_url": "https://api-elxolding.ci.iota.uz/media/", + "postgres": "postgres://postgres:postgres@elxolding_db/elxolding" +} diff --git a/docker-compose.yml b/docker-compose.production.yml similarity index 75% rename from docker-compose.yml rename to docker-compose.production.yml index be1cfd6..2a3fda3 100644 --- a/docker-compose.yml +++ b/docker-compose.production.yml @@ -6,10 +6,22 @@ services: build: context: ./app target: prod + args: + - NUXT_PUBLIC_API_URL=/api + + nginx: + restart: always + image: nginx:1.21.3 + build: + context: ./ + target: nginx volumes: + - ./nginx/nginx.conf:/etc/nginx/nginx.conf - ~/volumes/elxolding/uploads:/www/media ports: - "80:80" + depends_on: + - back back: restart: always diff --git a/docker-compose.staging.yml b/docker-compose.staging.yml new file mode 100644 index 0000000..d37c04c --- /dev/null +++ b/docker-compose.staging.yml @@ -0,0 +1,67 @@ +version: '3.8' + +services: + front: + restart: always + build: + context: ./app + target: prod + args: + - NUXT_PUBLIC_API_URL=https://api-elxolding.ci.iota.uz + environment: + - NUXT_PUBLIC_API_URL=https://api-elxolding.ci.iota.uz + labels: + - "traefik.enable=true" + - "traefik.docker.network=app" + - "traefik.http.routers.${COMMIT_SHA}-front.rule=Host(`elxolding.ci.iota.uz`)" + - "traefik.http.routers.${COMMIT_SHA}-front.tls=true" + - "traefik.http.routers.${COMMIT_SHA}-front.tls.certresolver=letsencrypt" + - "traefik.http.routers.${COMMIT_SHA}-front.tls.domains[0].main=iota.uz" + - "traefik.http.routers.${COMMIT_SHA}-front.tls.domains[0].sans=*.ci.iota.uz" + - "traefik.http.services.${COMMIT_SHA}-front.loadbalancer.server.port=80" + volumes: + - ~/volumes/elxolding/uploads:/www/media + networks: + - app + + back: + restart: always + build: + context: ./back + target: prod + environment: + NODE_ENV: staging + labels: + - "traefik.enable=true" + - "traefik.docker.network=app" + - "traefik.http.routers.${COMMIT_SHA}-back.rule=Host(`api-elxolding.ci.iota.uz`)" + - "traefik.http.routers.${COMMIT_SHA}-back.tls=true" + - "traefik.http.routers.${COMMIT_SHA}-back.tls.certresolver=letsencrypt" + - "traefik.http.routers.${COMMIT_SHA}-back.tls.domains[0].main=iota.uz" + - "traefik.http.routers.${COMMIT_SHA}-back.tls.domains[0].sans=*.ci.iota.uz" + - "traefik.http.services.${COMMIT_SHA}-back.loadbalancer.server.port=3030" + volumes: + - ~/volumes/elxolding/postgres:/app/uploads + depends_on: + - db + networks: + - app + + db: + restart: always + image: postgres:15.1 + hostname: elxolding_db + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: elxolding + ports: + - "17565:5432" + volumes: + - ~/volumes/elxolding/postgres:/var/lib/postgresql/data + networks: + - app + +networks: + app: + external: true diff --git a/app/nginx/default.conf b/nginx/default.conf similarity index 56% rename from app/nginx/default.conf rename to nginx/default.conf index fa01a14..d13d3fa 100644 --- a/app/nginx/default.conf +++ b/nginx/default.conf @@ -2,9 +2,12 @@ server { listen 80; listen [::]:80; + location /api/ { + proxy_pass http://back:3030/; + } + location / { - alias /usr/share/nginx/html; - try_files $uri @node; + proxy_pass http://front:80; } location /uploads/media/ { diff --git a/app/nginx/nginx.conf b/nginx/nginx.conf similarity index 100% rename from app/nginx/nginx.conf rename to nginx/nginx.conf