Skip to content

Commit

Permalink
Reconfigure and optimize docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
aldwin7894 committed Sep 29, 2022
1 parent 85ed388 commit 661452e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 22 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3.0.2

- id: docker-publish
name: Build image
uses: bitovi/github-actions-docker-publish@main
Expand All @@ -21,7 +21,7 @@ jobs:
image_tag: prod
org_name: aldwin7894
repo_name: aldwin7894
build_args: --build-arg OCCSON_ACCESS_TOKEN_ARG=${{ secrets.OCCSON_ACCESS_TOKEN }} --build-arg OCCSON_PASSPHRASE_ARG=${{ secrets.OCCSON_PASSPHRASE }} --build-arg RAILS_MASTER_KEY_ARG=${{ secrets.RAILS_MASTER_KEY }}
build_args: --build-arg TZ_ARG="Asia/Manila" --build-arg RAILS_ENV_ARG="production" --build-arg NODE_ENV_ARG="production" --build-arg OCCSON_ACCESS_TOKEN_ARG=${{ secrets.OCCSON_ACCESS_TOKEN }} --build-arg OCCSON_PASSPHRASE_ARG=${{ secrets.OCCSON_PASSPHRASE }} --build-arg RAILS_MASTER_KEY_ARG=${{ secrets.RAILS_MASTER_KEY }} --build-arg RAILS_ASSET_HOST_ARG=${{ secrets.RAILS_ASSET_HOST }}
working-directory: .
- run: |
echo "Image Created: ${{ env.image }}"
Expand Down
25 changes: 15 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
FROM ruby:3.1.2-slim-bullseye

ENV NODE_VERSION 14.20.0
ENV NPM_VERSION 8.16.0
ENV YARN_VERSION 1.22.0
ENV BUNDLE_PATH=/gems
ENV PATH="/node-v${NODE_VERSION}-linux-x64/bin:${PATH}"
ENV RAILS_ENV="production"
ENV NODE_ENV="production"
ENV RAILS_ASSET_HOST="https://cdn.aldwin7894.win"
ENV TZ="Asia/Manila"
ARG TZ_ARG
ARG RAILS_ENV_ARG
ARG NODE_ENV_ARG
ARG OCCSON_ACCESS_TOKEN_ARG
ARG OCCSON_PASSPHRASE_ARG
ARG RAILS_MASTER_KEY_ARG
ARG RAILS_ASSET_HOST_ARG

ENV TZ=$TZ_ARG
ENV RAILS_ENV=$RAILS_ENV_ARG
ENV NODE_ENV=$NODE_ENV_ARG
ENV OCCSON_ACCESS_TOKEN=$OCCSON_ACCESS_TOKEN_ARG
ENV OCCSON_PASSPHRASE=$OCCSON_PASSPHRASE_ARG
ENV RAILS_MASTER_KEY=$RAILS_MASTER_KEY_ARG
ENV RAILS_ASSET_HOST=$RAILS_ASSET_HOST_ARG

ENV NODE_VERSION 14.20.0
ENV NPM_VERSION 8.16.0
ENV YARN_VERSION 1.22.0
ENV BUNDLE_PATH=/gems
ENV PATH="/node-v${NODE_VERSION}-linux-x64/bin:${PATH}"

RUN apt-get update -yq \
&& apt-get install -yq --no-install-recommends \
Expand All @@ -23,7 +29,6 @@ RUN apt-get update -yq \
libpq-dev \
libjemalloc2 \
tar \
git \
tzdata \
&& curl "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.gz" -O \
&& tar xzf "node-v$NODE_VERSION-linux-x64.tar.gz" \
Expand Down
12 changes: 8 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ services:
context: .
dockerfile: Dockerfile
args:
- "OCCSON_ACCESS_TOKEN_ARG=${OCCSON_ACCESS_TOKEN}"
- "OCCSON_PASSPHRASE_ARG=${OCCSON_PASSPHRASE}"
- "RAILS_MASTER_KEY_ARG=${RAILS_MASTER_KEY_ARG}"
- TZ_ARG=${TZ}
- RAILS_ENV_ARG=${RAILS_ENV}
- NODE_ENV_ARG=${NODE_ENV}
- OCCSON_ACCESS_TOKEN_ARG=${OCCSON_ACCESS_TOKEN}
- OCCSON_PASSPHRASE_ARG=${OCCSON_PASSPHRASE}
- RAILS_MASTER_KEY_ARG=${RAILS_MASTER_KEY}
- RAILS_ASSET_HOST_ARG=${RAILS_ASSET_HOST}
container_name: aldwin7894-app
image: aldwin7894/aldwin7894:prod
restart: always
Expand All @@ -42,7 +46,7 @@ services:
ports:
- 3000:3000
environment:
- "DATABASE_URL=postgres://postgres:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB}"
- DATABASE_URL=postgres://postgres:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB}
- REDIS_URL=redis://redis:6379
- TZ=Asia/Manila
- RAILS_MASTER_KEY
Expand Down
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
},
"scripts": {
"anilist:schema:dump": "npx apollo schema:download --endpoint=https://graphql.anilist.co ./db/schema.json",
"vite:dev": "./bin/vite dev --debug",
"rails:dev": "RAILS_ENV=development NODE_ENV=development bundle exec rails s",
"rails:build": "RAILS_ENV=production NODE_ENV=production bash ./build.sh",
"rails:prod": "RAILS_ENV=production NODE_ENV=production bundle exec rails s",
"rails:prod:restart": "npx kill-port 3000 && yarn rails:prod"
"docker:build": ". ./.env && docker compose build web",
"docker:push": "docker compose push web",
"rails:dev": ". ./.env.dev && bundle exec rails s -b 0.0.0.0",
"vite:dev": "./bin/vite dev --debug"
},
"dependencies": {
"@hotwired/turbo-rails": "^7.2.0",
Expand Down
6 changes: 5 additions & 1 deletion vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import gzipPlugin from "rollup-plugin-gzip";
export default defineConfig({
plugins: [
RubyPlugin(),
FullReload(["config/routes.rb", "app/views/**/*"], { delay: 200 }),
...(
process.env.NODE_ENV === "production"
? [FullReload(["config/routes.rb", "app/views/**/*"], { delay: 200 })]
: []
),
gzipPlugin(),
gzipPlugin({
customCompression: (content) => brotliCompressSync(Buffer.from(content)),
Expand Down

0 comments on commit 661452e

Please sign in to comment.