diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ec5ba81..4e60117 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -38,6 +38,9 @@ jobs: - test runs-on: ubuntu-latest steps: + - id: time + run: | + echo "time=$(TZ=UTC date +%Y%m%d%H%M%S)" >> $GITHUB_OUTPUT - id: meta name: Docker meta uses: docker/metadata-action@v5 @@ -45,7 +48,15 @@ jobs: images: | ghcr.io/${{ github.repository_owner }}/guildbook tags: | - type=raw,value={{sha}}-{{date 'YYYYMMDDHHmmss'}} + type=raw,value={{sha}}-${{ steps.time.outputs.time }} + - id: meta-assets + name: Docker meta for assets + uses: docker/metadata-action@v5 + with: + images: | + ghcr.io/${{ github.repository_owner }}/guildbook-assets + tags: | + type=raw,value={{sha}}-${{ steps.time.outputs.time }} - uses: docker/setup-buildx-action@v3 - uses: docker/login-action@v2 with: @@ -54,6 +65,17 @@ jobs: password: ${{ github.token }} - uses: docker/build-push-action@v5 with: + target: app push: ${{ github.ref == 'refs/heads/master' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + - uses: docker/build-push-action@v5 + with: + target: assets + push: ${{ github.ref == 'refs/heads/master' }} + tags: ${{ steps.meta-assets.outputs.tags }} + labels: ${{ steps.meta-assets.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/Dockerfile b/Dockerfile index d120c45..69c6b95 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,7 @@ ARG RUBY=public.ecr.aws/sorah/ruby:3.2-bookworm ARG RUBYDEV=public.ecr.aws/sorah/ruby:3.2-dev-bookworm ARG NODE=public.ecr.aws/docker/library/node:lts-bookworm-slim +ARG NGINX=public.ecr.aws/docker/library/nginx:1.24 ### FROM $RUBYDEV as bundle @@ -26,7 +27,12 @@ COPY . . RUN npm run build ### -FROM $RUBY +FROM $NGINX as assets + +COPY --from=webpack /app/public/ /usr/share/nginx/html/ + +### +FROM $RUBY as app RUN apt-get update -qq && \ apt-get install -y dumb-init && \ @@ -35,8 +41,8 @@ RUN apt-get update -qq && \ WORKDIR /app COPY . . -COPY --from=bundle /app/vendor /app/vendor -COPY --from=bundle /app/.bundle /app/.bundle -COPY --from=webpack /app/node_modules /app/node_modules +COPY --from=bundle /app/vendor/ /app/vendor/ +COPY --from=bundle /app/.bundle/ /app/.bundle/ +COPY --from=webpack /app/public/assets/assets-manifest.json /app/public/assets/assets-manifest.json ENTRYPOINT ["/app/docker/entrypoint.sh"]