Skip to content

Commit 1f9baa6

Browse files
committed
Fix cache for dockers during master build
1 parent 24dcb5d commit 1f9baa6

9 files changed

Lines changed: 45 additions & 24 deletions

File tree

.github/workflows/master.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,15 @@ jobs:
122122
username: vtm9
123123
password: ${{ secrets.GH_REGISTRY_TOKEN }}
124124

125+
- name: Setup Docker Buildx
126+
uses: docker/setup-buildx-action@v3
127+
125128
- name: Build and push codebattle image
126129
run: |
127130
make GIT_HASH=${{ github.sha }} build-codebattle
128131
make push-codebattle
129132
130133
- name: Build and push runner image
131134
run: |
132-
make build-runner
135+
make GIT_HASH=${{ github.sha }} build-runner
133136
make push-runner

Makefile

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,29 +74,39 @@ build-codebattle:
7474
docker pull ghcr.io/hexlet-codebattle/codebattle:assets-image || true
7575
docker pull ghcr.io/hexlet-codebattle/codebattle:compile-image || true
7676
docker pull ghcr.io/hexlet-codebattle/codebattle:latest || true
77-
DOCKER_BUILDKIT=1 docker build --target assets-image \
77+
DOCKER_BUILDKIT=1 docker buildx build --load --target assets-image \
7878
--file services/app/Containerfile.codebattle \
79-
--build-arg GIT_HASH=$(GIT_HASH) \
79+
--cache-from type=registry,ref=ghcr.io/hexlet-codebattle/codebattle:assets-cache \
80+
--cache-to type=registry,ref=ghcr.io/hexlet-codebattle/codebattle:assets-cache,mode=max \
8081
--cache-from ghcr.io/hexlet-codebattle/codebattle:assets-image \
8182
--build-arg BUILDKIT_INLINE_CACHE=1 \
8283
--tag ghcr.io/hexlet-codebattle/codebattle:assets-image services/app
83-
DOCKER_BUILDKIT=1 docker build --target compile-image \
84+
DOCKER_BUILDKIT=1 docker buildx build --load --target compile-image \
8485
--file services/app/Containerfile.codebattle \
85-
--build-arg GIT_HASH=$(GIT_HASH) \
86+
--cache-from type=registry,ref=ghcr.io/hexlet-codebattle/codebattle:assets-cache \
87+
--cache-from type=registry,ref=ghcr.io/hexlet-codebattle/codebattle:compile-cache \
88+
--cache-to type=registry,ref=ghcr.io/hexlet-codebattle/codebattle:compile-cache,mode=max \
8689
--cache-from ghcr.io/hexlet-codebattle/codebattle:assets-image \
8790
--cache-from ghcr.io/hexlet-codebattle/codebattle:compile-image \
8891
--build-arg BUILDKIT_INLINE_CACHE=1 \
8992
--tag ghcr.io/hexlet-codebattle/codebattle:compile-image services/app
90-
DOCKER_BUILDKIT=1 docker build --target nginx-assets \
93+
DOCKER_BUILDKIT=1 docker buildx build --load --target nginx-assets \
9194
--file services/app/Containerfile.codebattle \
95+
--cache-from type=registry,ref=ghcr.io/hexlet-codebattle/codebattle:assets-cache \
96+
--cache-from type=registry,ref=ghcr.io/hexlet-codebattle/codebattle:compile-cache \
97+
--cache-from type=registry,ref=ghcr.io/hexlet-codebattle/nginx-assets:buildcache \
98+
--cache-to type=registry,ref=ghcr.io/hexlet-codebattle/nginx-assets:buildcache,mode=max \
9299
--cache-from ghcr.io/hexlet-codebattle/codebattle:assets-image \
93100
--cache-from ghcr.io/hexlet-codebattle/codebattle:compile-image \
94101
--cache-from ghcr.io/hexlet-codebattle/nginx-assets:latest \
95102
--build-arg BUILDKIT_INLINE_CACHE=1 \
96103
--tag ghcr.io/hexlet-codebattle/nginx-assets:latest services/app
97-
DOCKER_BUILDKIT=1 docker build --target runtime-image \
104+
DOCKER_BUILDKIT=1 docker buildx build --load --target runtime-image \
98105
--file services/app/Containerfile.codebattle \
99106
--build-arg GIT_HASH=$(GIT_HASH) \
107+
--cache-from type=registry,ref=ghcr.io/hexlet-codebattle/codebattle:compile-cache \
108+
--cache-from type=registry,ref=ghcr.io/hexlet-codebattle/codebattle:runtime-cache \
109+
--cache-to type=registry,ref=ghcr.io/hexlet-codebattle/codebattle:runtime-cache,mode=max \
100110
--cache-from ghcr.io/hexlet-codebattle/codebattle:compile-image \
101111
--cache-from ghcr.io/hexlet-codebattle/codebattle:latest \
102112
--build-arg BUILDKIT_INLINE_CACHE=1 \
@@ -150,13 +160,19 @@ push-codebattle:
150160
build-runner:
151161
docker pull ghcr.io/hexlet-codebattle/runner:compile-image || true
152162
docker pull ghcr.io/hexlet-codebattle/runner:latest || true
153-
DOCKER_BUILDKIT=1 docker build --target compile-image \
163+
DOCKER_BUILDKIT=1 docker buildx build --load --target compile-image \
154164
--file services/app/Containerfile.runner \
165+
--cache-from type=registry,ref=ghcr.io/hexlet-codebattle/runner:compile-cache \
166+
--cache-to type=registry,ref=ghcr.io/hexlet-codebattle/runner:compile-cache,mode=max \
155167
--cache-from ghcr.io/hexlet-codebattle/runner:compile-image \
156168
--build-arg BUILDKIT_INLINE_CACHE=1 \
157169
--tag ghcr.io/hexlet-codebattle/runner:compile-image services/app
158-
DOCKER_BUILDKIT=1 docker build --target runtime-image \
170+
DOCKER_BUILDKIT=1 docker buildx build --load --target runtime-image \
159171
--file services/app/Containerfile.runner \
172+
--build-arg GIT_HASH=$(GIT_HASH) \
173+
--cache-from type=registry,ref=ghcr.io/hexlet-codebattle/runner:compile-cache \
174+
--cache-from type=registry,ref=ghcr.io/hexlet-codebattle/runner:runtime-cache \
175+
--cache-to type=registry,ref=ghcr.io/hexlet-codebattle/runner:runtime-cache,mode=max \
160176
--cache-from ghcr.io/hexlet-codebattle/runner:compile-image \
161177
--cache-from ghcr.io/hexlet-codebattle/runner:latest \
162178
--build-arg BUILDKIT_INLINE_CACHE=1 \

services/app/Containerfile.codebattle

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ COPY apps/codebattle/priv/gettext ./priv/gettext
1616
RUN pnpm run build
1717

1818
FROM elixir:1.19.1-otp-28-alpine AS compile-image
19-
ARG GIT_HASH
20-
21-
ENV APP_VERSION=$GIT_HASH
2219
ENV MIX_ENV=prod
2320

2421
WORKDIR /opt/app

services/app/Containerfile.runner

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
FROM elixir:1.19-otp-28-alpine AS compile-image
2-
ARG GIT_HASH
3-
4-
ENV APP_VERSION=$GIT_HASH
52
ENV MIX_ENV=prod
63

74
WORKDIR /opt/app
@@ -43,6 +40,9 @@ RUN apk update && apk add --no-cache \
4340
RUN curl -fsSL "https://github.com/alco/goon/releases/download/${GOON_VERSION}/goon_linux_amd64.tar.gz" \
4441
| tar -xzC /usr/local/bin
4542

43+
ARG GIT_HASH
44+
45+
ENV APP_VERSION=$GIT_HASH
4646
ENV PORT=4001
4747
EXPOSE ${PORT}
4848
WORKDIR /opt/app

services/app/apps/codebattle/lib/codebattle_web/views/layout_view.ex

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ defmodule CodebattleWeb.LayoutView do
44
import CodebattleWeb.Router.Helpers
55
import PhoenixGon.View
66

7-
@app_version Application.compile_env(:codebattle, :app_version)
87
@colors [
98
"2AE881",
109
"73CCFE",
@@ -33,14 +32,14 @@ defmodule CodebattleWeb.LayoutView do
3332
end
3433

3534
def app_short_version do
36-
case @app_version do
35+
case app_version() do
3736
"" -> "undefined"
3837
version -> String.slice(version, 0, 7)
3938
end
4039
end
4140

4241
def github_commit_link do
43-
case @app_version do
42+
case app_version() do
4443
"" -> "/"
4544
version -> "https://github.com/hexlet-codebattle/codebattle/commit/#{version}"
4645
end
@@ -86,4 +85,8 @@ defmodule CodebattleWeb.LayoutView do
8685
defp get_background_color(user) do
8786
Enum.at(@colors, rem(String.length(user.name), length(@colors)))
8887
end
88+
89+
defp app_version do
90+
Application.get_env(:codebattle, :app_version, "")
91+
end
8992
end

services/app/apps/codebattle/lib/codebattle_web/views/root_view.ex

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ defmodule CodebattleWeb.RootView do
55

66
alias Codebattle.Feedback
77

8-
@app_version Application.compile_env(:codebattle, :app_version)
9-
108
@doc """
119
Returns the path for a static asset with cache busting support.
1210
In dev, returns the original path. In prod, returns the hashed path from manifest.
@@ -31,19 +29,23 @@ defmodule CodebattleWeb.RootView do
3129
end
3230

3331
def app_short_version do
34-
case @app_version do
32+
case app_version() do
3533
"" -> "undefined"
3634
version -> String.slice(version, 0, 7)
3735
end
3836
end
3937

4038
def github_commit_link do
41-
case @app_version do
39+
case app_version() do
4240
"" -> "/"
4341
version -> "https://github.com/hexlet-codebattle/codebattle/commit/#{version}"
4442
end
4543
end
4644

45+
defp app_version do
46+
Application.get_env(:codebattle, :app_version, "")
47+
end
48+
4749
defp item(%{title: title, description: description, pubDate: pub_date, link: link, guid: guid}) do
4850
"""
4951
<item>

services/app/config/config.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ config :codebattle, :oauth,
7070

7171
config :codebattle, :start_create_bot_timeout, to_timeout(second: 3)
7272
config :codebattle, :tournament_run_upcoming, false
73-
config :codebattle, app_version: System.get_env("APP_VERSION", "dev")
73+
config :codebattle, app_version: "dev"
7474
# config :codebattle, checker_executor: Codebattle.CodeCheck.Executor.RemoteZig
7575
config :codebattle, asserts_executor: Codebattle.AssertsService.Executor.Remote
7676
config :codebattle, chat_bot_token: System.get_env("CODEBATTLE_CHAT_BOT_TOKEN", "chat_bot")

services/app/config/prod.exs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ config :codebattle, CodebattleWeb.Endpoint,
1919
check_origin: false
2020

2121
config :codebattle, :tournament_run_upcoming, true
22-
config :codebattle, app_version: System.get_env("APP_VERSION", "")
2322
config :codebattle, dev_sign_in: false
2423
config :codebattle, env: :prod
2524
config :codebattle, html_debug_mode: false

services/app/config/releases.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ config :codebattle, :oauth,
105105
external_avatar_url_template: System.get_env("EXTERNAL_AVATAR_URL_TEMPLATE", "ASFD")
106106

107107
config :codebattle, :tournament_run_upcoming, true
108+
config :codebattle, app_version: System.get_env("APP_VERSION", "")
108109
config :codebattle, asserts_executor: Codebattle.AssertsService.Executor.Remote
109110
config :codebattle, checker_executor: checker_executor
110111
config :codebattle, collab_logo: System.get_env("CODEBATTLE_COLLAB_LOGO")

0 commit comments

Comments
 (0)