diff --git a/.dockerignore b/.dockerignore index a5af77eb5..30630852c 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,14 +1,21 @@ .bundle +.codex .env .env.* +.git +.github +.agents docker-compose.* docker/Dockerfile docker/dockerfiles log +spec storage +tests public/system tmp .codeclimate.yml +coverage public/packs node_modules vendor/bundle diff --git a/.github/workflows/publish_ee_docker.yml b/.github/workflows/publish_ee_docker.yml index 982054a18..caa040f89 100644 --- a/.github/workflows/publish_ee_docker.yml +++ b/.github/workflows/publish_ee_docker.yml @@ -78,6 +78,12 @@ jobs: platforms: ${{ matrix.platform }} push: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }} outputs: type=image,name=${{ env.DOCKER_REPO }},push-by-digest=true,name-canonical=true,push=true + build-args: | + GIT_SHA=${{ github.sha }} + cache-from: | + type=gha,scope=${{ matrix.platform }} + type=gha,scope=${{ matrix.platform }}-ee + cache-to: type=gha,mode=max,scope=${{ matrix.platform }}-ee - name: Export digest run: | @@ -125,7 +131,7 @@ jobs: else TAG="${DOCKER_REPO}:${SANITIZED_REF}" fi - + docker buildx imagetools create -t $TAG \ $(printf '${{ env.DOCKER_REPO }}@sha256:%s ' *) @@ -139,5 +145,5 @@ jobs: else TAG="${DOCKER_REPO}:${SANITIZED_REF}" fi - + docker buildx imagetools inspect $TAG diff --git a/.github/workflows/publish_foss_docker.yml b/.github/workflows/publish_foss_docker.yml index 994e5cef8..c207b32a6 100644 --- a/.github/workflows/publish_foss_docker.yml +++ b/.github/workflows/publish_foss_docker.yml @@ -83,6 +83,12 @@ jobs: platforms: ${{ matrix.platform }} push: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }} outputs: type=image,name=${{ env.DOCKER_REPO }},push-by-digest=true,name-canonical=true,push=true + build-args: | + GIT_SHA=${{ github.sha }} + cache-from: | + type=gha,scope=${{ matrix.platform }} + type=gha,scope=${{ matrix.platform }}-ce + cache-to: type=gha,mode=max,scope=${{ matrix.platform }}-ce - name: Export digest run: | @@ -130,7 +136,7 @@ jobs: else TAG="${DOCKER_REPO}:${SANITIZED_REF}-ce" fi - + docker buildx imagetools create -t $TAG \ $(printf '${{ env.DOCKER_REPO }}@sha256:%s ' *) @@ -144,5 +150,5 @@ jobs: else TAG="${DOCKER_REPO}:${SANITIZED_REF}-ce" fi - + docker buildx imagetools inspect $TAG diff --git a/.github/workflows/test_docker_build.yml b/.github/workflows/test_docker_build.yml index 96a6c69ac..e744dbe81 100644 --- a/.github/workflows/test_docker_build.yml +++ b/.github/workflows/test_docker_build.yml @@ -39,5 +39,9 @@ jobs: platforms: ${{ matrix.platform }} push: false load: false - cache-from: type=gha,scope=${{ matrix.platform }} - cache-to: type=gha,mode=max,scope=${{ matrix.platform }} + build-args: | + GIT_SHA=${{ github.sha }} + cache-from: | + type=gha,scope=${{ matrix.platform }} + type=gha,scope=${{ matrix.platform }}-ce + type=gha,scope=${{ matrix.platform }}-ee diff --git a/Makefile b/Makefile index 684adacc6..a0964782b 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ # Variables APP_NAME := chatwoot RAILS_ENV ?= development +GIT_SHA ?= $(shell git rev-parse HEAD 2>/dev/null || echo unknown) # Targets setup: @@ -61,6 +62,6 @@ debug_worker: overmind connect worker docker: - docker build -t $(APP_NAME) -f ./docker/Dockerfile . + docker build --build-arg GIT_SHA=$(GIT_SHA) -t $(APP_NAME) -f ./docker/Dockerfile . .PHONY: setup db_create db_migrate db_seed db_reset db console server burn docker run force_run force_run_tunnel debug debug_worker diff --git a/docker/Dockerfile b/docker/Dockerfile index 645a61a55..9303905b1 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -87,13 +87,13 @@ RUN if [ "$RAILS_ENV" = "production" ]; then \ fi # Generate .git_sha file with current commit hash -RUN git rev-parse HEAD > /app/.git_sha +ARG GIT_SHA="unknown" +RUN printf "%s\n" "$GIT_SHA" > /app/.git_sha # Remove unnecessary files RUN rm -rf /gems/ruby/3.4.0/cache/*.gem \ && find /gems/ruby/3.4.0/gems/ \( -name "*.c" -o -name "*.o" \) -delete \ - && rm -rf .git \ - && rm .gitignore + && rm -rf .git .gitignore # final build stage FROM ruby:3.4.4-alpine3.21