From e3d5fc8984178f494f8d3a8c38434e47cd664d4e Mon Sep 17 00:00:00 2001 From: Nikita Elfimov Date: Wed, 29 Oct 2025 18:10:23 +0300 Subject: [PATCH] feat(common): dockerfile, compose and publish action --- .env.example | 1 + .github/workflows/publish.yaml | 25 ++++++++++++++++++ Dockerfile | 48 ++++++++++++++++++++++++---------- config/nginx.conf | 8 ++++++ docker-compose.yaml | 32 +++++++++++++++++++++++ 5 files changed, 100 insertions(+), 14 deletions(-) create mode 100644 .env.example create mode 100644 .github/workflows/publish.yaml create mode 100644 config/nginx.conf create mode 100644 docker-compose.yaml diff --git a/.env.example b/.env.example new file mode 100644 index 00000000..9165ad5f --- /dev/null +++ b/.env.example @@ -0,0 +1 @@ +CLIENT=rees46 diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 00000000..9eeb92ac --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,25 @@ +name: Publish + +on: + pull_request: + types: + - closed + branches: + - master + paths-ignore: + - .github + workflow_dispatch: + +jobs: + docker: + if: | + github.event_name == 'workflow_dispatch' || + ( + github.event.pull_request.merged == true && + !startsWith(github.head_ref, 'release/') + ) + name: Build Docker image and push + uses: rees46/workflow/.github/workflows/docker-publish.yaml@master + permissions: write-all + with: + packageName: api-docs diff --git a/Dockerfile b/Dockerfile index 5777f8e2..e1e36042 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,40 @@ -FROM ruby:2.7-slim +FROM ruby:2.7.5-slim AS base -WORKDIR /srv/slate +ARG BUNDLE_WITHOUT="test:development" +ENV BUNDLE_WITHOUT="${BUNDLE_WITHOUT}" -VOLUME /srv/slate/source -EXPOSE 4567 +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + build-essential \ + nodejs && \ + apt-get autoremove -y && \ + rm -rf /var/lib/apt/lists/* -COPY . /srv/slate +WORKDIR /app -RUN apt-get update \ - && apt-get install -y --no-install-recommends \ - build-essential \ - nodejs \ - && gem install bundler -v 2.4.22\ - && bundle install \ - && apt-get remove -y build-essential \ - && apt-get autoremove -y \ - && rm -rf /var/lib/apt/lists/* +COPY Gemfile Gemfile.lock ./ + +RUN BUNDLER_VERSION=$(grep -A 1 "BUNDLED WITH" Gemfile.lock | tail -1 | tr -d ' ') && \ + gem install bundler -v "$BUNDLER_VERSION" + +RUN bundle install + +COPY . . CMD ["bundle", "exec", "middleman", "server", "--watcher-force-polling"] + +FROM base AS build + +ARG BUNDLE_WITHOUT="test:development" +ENV BUNDLE_WITHOUT="${BUNDLE_WITHOUT}" + +RUN ./configure.sh r46 && bundle exec middleman build && mv build /opt/rees46 +RUN ./configure.sh kameleoon && bundle exec middleman build && mv build /opt/kameleoon +RUN ./configure.sh pc && bundle exec middleman build && mv build /opt/personaclick + +FROM nginx:1 AS prod + +ENV CLIENT=rees46 + +COPY --from=build /opt /usr/share/nginx/html +COPY ./config/nginx.conf /etc/nginx/templates/default.conf.template diff --git a/config/nginx.conf b/config/nginx.conf new file mode 100644 index 00000000..1f99ae78 --- /dev/null +++ b/config/nginx.conf @@ -0,0 +1,8 @@ +server { + listen 80; + + location / { + root /usr/share/nginx/html/${CLIENT}; + try_files $uri $uri/ =404; + } +} diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 00000000..7b80d859 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,32 @@ +x-environment: &environment + env_file: + - path: ./.env.example + required: true + - path: ./.env + required: false + +networks: + rees46: + name: rees46 + driver: bridge + +services: + api-docs: + <<: *environment + image: ghcr.io/rees46/api-docs:latest + build: + context: . + target: base + args: + BUNDLE_WITHOUT: '' + ports: + - '${PORT_PUBLIC:-8080}:80' + networks: + - rees46 + develop: + watch: + - action: sync + path: . + target: /app + - action: rebuild + path: ./Gemfile.lock