diff --git a/.github/workflows/build-deploy-on-release.yaml b/.github/workflows/build-deploy-on-release.yaml index 66e2035..56ada3c 100644 --- a/.github/workflows/build-deploy-on-release.yaml +++ b/.github/workflows/build-deploy-on-release.yaml @@ -11,7 +11,7 @@ jobs: with: image_name: ${{ vars.IMAGE_NAME }} tag: ${{ github.event.release.tag_name }} - dockerfile: Dockerfile.prod + dockerfile: Dockerfile secrets: inherit deploy-production: diff --git a/.github/workflows/build-main.yml b/.github/workflows/build-main.yml index 21c2dfb..936f241 100644 --- a/.github/workflows/build-main.yml +++ b/.github/workflows/build-main.yml @@ -13,7 +13,7 @@ jobs: with: image_name: ${{ vars.IMAGE_NAME }} tag: ${{ github.sha }} - dockerfile: Dockerfile.prod + dockerfile: Dockerfile secrets: inherit deploy-testing: diff --git a/.github/workflows/deploy-production.yaml b/.github/workflows/deploy-production.yaml index 5100018..98e9128 100644 --- a/.github/workflows/deploy-production.yaml +++ b/.github/workflows/deploy-production.yaml @@ -14,7 +14,7 @@ jobs: with: image_name: ${{ vars.IMAGE_NAME }} tag: ${{ github.event.inputs.tag }} - dockerfile: Dockerfile.prod + dockerfile: Dockerfile secrets: inherit deploy-production: diff --git a/.github/workflows/manual-deploy-unstable.yaml b/.github/workflows/manual-deploy-unstable.yaml index 87f0234..8eff746 100644 --- a/.github/workflows/manual-deploy-unstable.yaml +++ b/.github/workflows/manual-deploy-unstable.yaml @@ -22,7 +22,7 @@ jobs: with: image_name: ${{ vars.IMAGE_NAME }} tag: ${{ github.event.inputs.tag }} - dockerfile: Dockerfile.prod + dockerfile: Dockerfile secrets: inherit deploy: diff --git a/Dockerfile b/Dockerfile index 5e47db5..98d9204 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,9 @@ -ARG RUBY_VERSION=3.2 -FROM ruby:${RUBY_VERSION} +FROM ruby:3.2 AS development ARG UNAME=app ARG UID=1000 ARG GID=1000 -LABEL maintainer="mrio@umich.edu" - RUN apt-get update -yqq && apt-get install -yqq --no-install-recommends \ apt-transport-https @@ -28,3 +25,19 @@ USER $UNAME ENV BUNDLE_PATH /gems WORKDIR /app + +FROM development AS production + +COPY --chown=${UID}:${GID} . /app +ENV BUNDLE_WITHOUT development:test + +RUN --mount=type=secret,id=gh_package_read_token,uid=1000 \ + read_token="$(cat /run/secrets/gh_package_read_token)" \ + && BUNDLE_RUBYGEMS__PKG__GITHUB__COM=${read_token} bundle install + +RUN npm ci + +RUN npm run build +RUN cp js/* public/bundles/ + +CMD ["bundle", "exec", "rackup", "-p", "4567", "--host", "0.0.0.0"] diff --git a/Dockerfile.prod b/Dockerfile.prod deleted file mode 100644 index 086300c..0000000 --- a/Dockerfile.prod +++ /dev/null @@ -1,44 +0,0 @@ -ARG RUBY_VERSION=3.2 -FROM ruby:${RUBY_VERSION} - -ARG UNAME=app -ARG UID=1000 -ARG GID=1000 - -LABEL maintainer="mrio@umich.edu" - -RUN apt-get update -yqq && apt-get install -yqq --no-install-recommends \ - apt-transport-https - -RUN curl -sL https://deb.nodesource.com/setup_18.x | bash - - -RUN apt-get update -yqq && apt-get install -yqq --no-install-recommends \ - nodejs \ - vim-tiny - -RUN gem install bundler -RUN npm install -g npm - -RUN groupadd -g ${GID} -o ${UNAME} -RUN useradd -m -d /app -u ${UID} -g ${GID} -o -s /bin/bash ${UNAME} -RUN mkdir -p /gems && chown ${UID}:${GID} /gems - -COPY --chown=${UID}:${GID} . /app - -ENV BUNDLE_PATH /gems -ENV BUNDLE_WITHOUT development:test - -WORKDIR /app - -RUN --mount=type=secret,id=gh_package_read_token \ - read_token="$(cat /run/secrets/gh_package_read_token)" \ - && BUNDLE_RUBYGEMS__PKG__GITHUB__COM=${read_token} bundle install - -USER $UNAME - -RUN npm ci - -RUN npm run build -RUN cp js/* public/bundles/ - -CMD ["bundle", "exec", "rackup", "-p", "4567", "--host", "0.0.0.0"] diff --git a/docker-compose.yml b/docker-compose.yml index 557173a..f1747c7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,8 +1,10 @@ -version: '3' +version: '3.8' services: web: - build: . + build: + context: . + target: development ports: - "4567:4567" - "9394:9394" @@ -22,14 +24,18 @@ services: - 0.0.0.0 css: - build: . + build: + context: . + target: development volumes: - .:/app - gem_cache:/gems command: bundle exec ruby ./config/css-listener.rb js: - build: . + build: + context: . + target: development volumes: - .:/app - gem_cache:/gems