-
Notifications
You must be signed in to change notification settings - Fork 0
Docker #364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v0.5.0
Are you sure you want to change the base?
Docker #364
Changes from all commits
8d3fcae
5cd14f8
cb9fb35
68fa8c6
ae695e8
cff933c
8b9d3ba
8e101da
ea139bd
d5204cd
7ace97f
2bd10ff
d449766
7ce5ee5
d74af0e
a583ab7
b7bbf55
ee1ba11
1fdd2aa
cee9b54
31fcd55
33ed636
2025111
ce2a602
820de5b
67ae676
02f439b
191d8ce
611d01d
c0fef42
9b527cd
3b08dca
05fa3e8
db197b3
3aa8d4f
9fad22b
6cdd712
9c7dd1a
ce12313
18c792f
0f98da7
a8c0fb0
5141c25
a56bb79
2a37844
b7c5699
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| version: 2 | ||
| updates: | ||
| - package-ecosystem: "github-actions" | ||
| directory: "/" | ||
| schedule: | ||
| interval: "weekly" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| name: Weekly Image Cleanup | ||
|
|
||
| on: | ||
| schedule: | ||
| - cron: "0 0 * * 0" # run every sunday at midnight | ||
| workflow_dispatch: | ||
|
|
||
| # don't cancel in-progress runs, since this is a weekly cleanup job | ||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: false | ||
|
|
||
| jobs: | ||
| clean-registry: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| packages: write | ||
|
|
||
| steps: | ||
| - name: Clean up Plancake Frontend images | ||
| uses: snok/container-retention-policy@d3bdcf5ce9b05f685154e4a16c39233b245e3d53 # v3.1.0 | ||
| with: | ||
| account: plan-cake | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
| image-names: plancake-frontend | ||
| cut-off: 1w | ||
| timestamp-to-use: updated_at | ||
| keep-n-most-recent: 3 | ||
| skip-tags: v*.*.* | ||
| dry-run: false | ||
|
mirmirmirr marked this conversation as resolved.
|
||
|
|
||
| - name: Clean up Plancake Backend images | ||
| uses: snok/container-retention-policy@d3bdcf5ce9b05f685154e4a16c39233b245e3d53 # v3.1.0 | ||
| with: | ||
| account: plan-cake | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
| image-names: plancake-backend | ||
| cut-off: 1w | ||
| timestamp-to-use: updated_at | ||
| keep-n-most-recent: 3 | ||
| skip-tags: v*.*.* | ||
| dry-run: false | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| name: Build and Publish Docker Images | ||
|
|
||
| on: | ||
| push: | ||
| branches: ["main", "v*.*.*"] | ||
|
|
||
| # Cancel any in-progress builds if a new commit is pushed to the same branch | ||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. | ||
| permissions: | ||
| contents: read | ||
| packages: write | ||
|
|
||
| jobs: | ||
| build-and-push: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Check out the repo | ||
| uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 | ||
|
|
||
| - name: Set up QEMU | ||
| uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0 | ||
|
|
||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0 | ||
|
|
||
| - name: Log in to GitHub Container Registry | ||
| uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0 | ||
| with: | ||
| registry: ghcr.io | ||
| username: ${{ github.actor }} | ||
| password: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| # --- BACKEND --- | ||
| - name: Extract metadata for Backend | ||
| id: meta-backend | ||
| uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5.10.0 | ||
| with: | ||
| images: ghcr.io/plan-cake/plancake-backend | ||
| tags: | | ||
| type=ref,event=branch | ||
| type=raw,value=latest,enable={{is_default_branch}} | ||
|
|
||
| - name: Build and push Backend | ||
| uses: docker/build-push-action@ca052bb54ab0790a636c9b5f226502c73d547a25 # v5.4.0 | ||
| with: | ||
| context: ./backend | ||
| file: ./backend/Dockerfile.dev | ||
| push: true | ||
|
mirmirmirr marked this conversation as resolved.
mirmirmirr marked this conversation as resolved.
|
||
| tags: ${{ steps.meta-backend.outputs.tags }} | ||
| labels: ${{ steps.meta-backend.outputs.labels }} | ||
| platforms: linux/amd64,linux/arm64 | ||
| cache-from: | | ||
| type=gha,scope=backend-${{ github.ref_name }} | ||
| type=gha,scope=backend-main | ||
| cache-to: type=gha,mode=max,scope=backend-${{ github.ref_name }} | ||
|
|
||
| # --- FRONTEND --- | ||
| - name: Extract metadata for Frontend | ||
| id: meta-frontend | ||
| uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5.10.0 | ||
| with: | ||
| images: ghcr.io/plan-cake/plancake-frontend | ||
| tags: | | ||
| type=ref,event=branch | ||
| type=raw,value=latest,enable={{is_default_branch}} | ||
|
|
||
| - name: Build and push Frontend | ||
| uses: docker/build-push-action@ca052bb54ab0790a636c9b5f226502c73d547a25 # v5.4.0 | ||
| with: | ||
| context: ./frontend | ||
| file: ./frontend/Dockerfile.dev | ||
| push: true | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| tags: ${{ steps.meta-frontend.outputs.tags }} | ||
| labels: ${{ steps.meta-frontend.outputs.labels }} | ||
| platforms: linux/amd64,linux/arm64 | ||
| cache-from: | | ||
| type=gha,scope=frontend-${{ github.ref_name }} | ||
| type=gha,scope=frontend-main | ||
| cache-to: type=gha,mode=max,scope=frontend-${{ github.ref_name }} | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,95 @@ | ||||||
|
|
||||||
| .PHONY: help up down restart logs-api logs-web shell-api shell-web migrate makemigrations | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== Makefile relevant lines =="
if [ -f Makefile ]; then
nl -ba Makefile | sed -n '1,110p'
else
echo "Makefile not found"
fi
echo
echo "== Makefile phony and target declarations =="
python3 - <<'PY'
from pathlib import Path
p = Path("Makefile")
if not p.exists():
raise SystemExit
lines = p.read_text().splitlines()
for i, line in enumerate(lines, 1):
if line.startswith(".PHONY"):
print(f"{i}: {line}")
for i, line in enumerate(lines, 1):
if line.startswith("build:") or line.startswith("url:") or line.startswith("help:") or line.startswith("up:"):
print(f"{i}: {line}")
PY
echo
echo "== Check if make is available =="
command -v make || trueRepository: plan-cake/plancake Length of output: 226 🏁 Script executed: #!/bin/bash
set -u
echo "== Makefile existence and size =="
if [ -f Makefile ]; then
wc -l Makefile
else
echo "Makefile not found"
fi
echo
echo "== Makefile relevant lines =="
if [ -f Makefile ]; then
cat -n Makefile | sed -n '1,110p'
fi
echo
echo "== Makefile phony and target declarations =="
if [ -f Makefile ]; then
awk 'NR==FNR{for(i=1;i<=NF;i++) if($i=="\\") $(i+1)=$0} {print NR": "$0}' Makefile | \
grep -E '^\s*[0-9]+: (\.PHONY|build:|url:|\s*build\s*:|\s*url\s*:)+'
awk '{line=$0} NR==FNR{if(/\\[[:space:]]*$/){getline; line=line$0} else if(line~/^(\.PHONY|build:|url:|\s*build\s*:|\s*url\s*:)/ || $0~ /^(\.PHONY|build:|url:|\s*build\s*:|\s*url\s*:)/) print FNR": "$0}' Makefile Makefile
fi
echo
echo "== Check if make is available =="
command -v make || true
echo
echo "== Deterministic Makefile behavior probe with system make, if available =="
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT
cat > "$tmp/Makefile" <<'EOF'
.PHONY: phony-only one-two
one-two: app
`@echo` TARGET_RAN
phony-only:
`@echo` PHONY_ONLY_RAN
EOF
touch "$tmp/app"
{
echo "== with app present, target not marked .PHONY =="
(cd "$tmp" && make --no-print-directory one-two || true)
echo
echo "== with app absent =="
rm "$tmp/app"
(cd "$tmp" && make --no-print-directory one-two || true)
} 2>&1 || trueRepository: plan-cake/plancake Length of output: 4892 🌐 Web query:
💡 Result: In GNU make, the.PHONY special target is used to explicitly declare that a target does not correspond to an actual file on the filesystem [1][2][3]. When a target is marked as.PHONY, make ignores the existence or modification time of any file with the same name and executes the associated recipe unconditionally every time that target is requested [4][1][5][3]. Key behaviors include: 1. Unconditional Execution: If you do not declare a target as.PHONY and a file with that same name happens to exist in the directory, make will treat it as a real file target [1][2]. If that file is up to date relative to its prerequisites, make will consider it "up to date" and skip the recipe [1][2][3]. Declaring it.PHONY forces execution regardless of the file's presence or age [4][2][3]. 2. Performance Optimization: Because make knows that a.PHONY target does not represent an actual file, it skips the implicit rule search for that target [2][6][3]. This provides a minor performance benefit by avoiding unnecessary filesystem lookups [1][2][3]. 3. Proper Usage: You should use.PHONY for targets that perform actions rather than building files (e.g., clean, all, install) [1][2]. Conversely, you should avoid using.PHONY for real file targets (like object files or executables), as doing so will cause them to be rebuilt unnecessarily every time you run make [7]. 4. Interaction with Directories: If a directory exists with the same name as your target, it is still treated as a real file/directory by make [8]. If you want a rule to build a directory (e.g., creating it with mkdir), do not mark it as.PHONY; instead, consider using order-only prerequisites if you only want the directory to exist before other files are created [8]. Citations:
Declare Both targets define Docker/printing actions rather than files, but they are only referenced from Proposed fix-.PHONY: help up down restart logs-api logs-web shell-api shell-web migrate makemigrations
+.PHONY: help up build down restart logs-api logs-web shell-api shell-web migrate makemigrations url📝 Committable suggestion
Suggested change
mirmirmirr marked this conversation as resolved.
|
||||||
|
|
||||||
| # Determine the Docker image tag based on the current Git branch. If the branch is not | ||||||
| # "main", use the version from the frontend package.json to identify the Docker image. | ||||||
| # Otherwise, default to latest. | ||||||
| CURRENT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD) | ||||||
| IMAGE_TAG := latest | ||||||
| ifneq ($(CURRENT_BRANCH),main) | ||||||
| # Get the version from the frontend package.json for identifying the Docker image. | ||||||
| PKG_VERSION := $(shell node -p "require('./frontend/package.json').version") | ||||||
| IMAGE_TAG := v$(PKG_VERSION) | ||||||
|
Comment on lines
+9
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: make -n helpRepository: plan-cake/plancake Length of output: 198 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf 'Makefile lines 1-40:\n'
sed -n '1,45p' Makefile | cat -n
printf '\nMakefile indentation around conditional:\n'
python3 - <<'PY'
from pathlib import Path
p = Path("Makefile")
text = p.read_text(errors="replace").splitlines()
for i, line in enumerate(text[max(0,6):min(len(text),15)], start=max(0,6)+1):
print(f"{i}: {line!r} chars before content: {len(line)-len(line.lstrip(chr(9)))} {'tab'*(len(line)-len(line.lstrip(chr(9)))>0) else 'spaces'}")
PYRepository: plan-cake/plancake Length of output: 2834 Remove the leading tabs from the conditional Makefile assignments.
|
||||||
| endif | ||||||
|
Comment on lines
+4
to
+13
|
||||||
|
|
||||||
| # --- COMMANDS --- | ||||||
|
|
||||||
| help: | ||||||
| @echo "Usage: make <target>" | ||||||
| @echo "" | ||||||
| @echo "Targets:" | ||||||
| @echo " up Starts the environment in the background and prints out the URLs for local and network access." | ||||||
| @echo " build Creates a full local rebuild from scratch (bypasses the registry) and prints out the URLs for local and network access." | ||||||
| @echo " down Stops the environment completely and removes the connected containers and networks." | ||||||
| @echo " restart Restarts the containers without rebuilding them. Use this for things like env changes." | ||||||
| @echo " logs-api Stream the Django backend logs." | ||||||
| @echo " logs-web Stream the Next.js frontend logs." | ||||||
| @echo " shell-api Open a terminal inside the backend container." | ||||||
| @echo " shell-web Open a terminal inside the frontend container." | ||||||
| @echo " migrate Run Django migrations inside the running container." | ||||||
| @echo " makemigrations Generate new Django migrations inside the running container." | ||||||
|
|
||||||
| # Pulls the image from the registry and starts the containers in the background. | ||||||
| up: | ||||||
| @IMAGE_TAG=$(IMAGE_TAG) docker compose pull | ||||||
| @IMAGE_TAG=$(IMAGE_TAG) docker compose up -d && \ | ||||||
| echo "" && \ | ||||||
| echo "Using image tag $(IMAGE_TAG)" && \ | ||||||
| echo "" && \ | ||||||
| echo "Plancake Industries" && \ | ||||||
| echo " - Local: http://localhost:3000" && \ | ||||||
| echo " - Network: $$(node scripts/print-ip.js)" && \ | ||||||
| echo "" | ||||||
|
|
||||||
| # Creates a full local rebuild from scratch (bypasses the registry) | ||||||
| build: | ||||||
| @IMAGE_TAG=$(IMAGE_TAG) docker compose up -d --build && \ | ||||||
| echo "" && \ | ||||||
| echo "Plancake Industries" && \ | ||||||
| echo " - Local: http://localhost:3000" && \ | ||||||
| echo " - Network: $$(node scripts/print-ip.js)" && \ | ||||||
| echo "" | ||||||
|
|
||||||
| # Stops the environment completely and removes the connected containers and networks. | ||||||
| down: | ||||||
| docker compose down | ||||||
|
|
||||||
| # Restarts the containers without rebuilding them. Use this for things like env changes. | ||||||
| restart: | ||||||
| docker compose restart | ||||||
|
Comment on lines
+57
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== Makefile around restart target =="
nl -ba Makefile | sed -n '45,68p'
echo
echo "== Search for restart target / docker compose usage =="
rg -n "restart:|docker compose|FORCE|env changes" Makefile .github -S || true
echo
echo "== Local repository version files if any =="
git ls-files | rg '(^|/)(Makefile|compose.*\.ya?ml|\.env|docker-compose\.ya?ml)$' || trueRepository: plan-cake/plancake Length of output: 233 🌐 Web query:
💡 Result: When using the docker compose up command, the --force-recreate flag instructs Docker Compose to stop and recreate all containers, even if their configuration or image has not changed [1][2]. This is particularly useful when you need to ensure that environment variable changes or other configuration updates are applied to the containers [3]. Regarding environment variables and the.env file: 1. Behavior with --force-recreate: By default, Docker Compose compares the current configuration (including environment variables) of running containers with the desired configuration in your compose.yaml [1]. If it detects a difference, it automatically recreates them [1][3]. However, using --force-recreate guarantees that the containers are replaced regardless of whether Compose detects a change, ensuring that the environment defined by your current.env file or other environment settings is applied [1][2]. 2..env File Precedence: Docker Compose automatically loads a default.env file from the project directory [4][5]. If you need to use a different file, you can specify it using the --env-file option [4][6]. 3. Precedence Rules: Environment variables are resolved based on a specific order of precedence [5][7]. Generally, variables defined in the environment attribute of your compose.yaml file take precedence over those loaded from an env_file [5][8]. If you are changing environment variables and the container does not seem to update, ensure you are running the command in the same directory as your compose.yaml or specify the path to your configuration file correctly [4]. If the container persists old state (e.g., due to anonymous volumes), you may also need to consider flags like --renew-anon-volumes to fully refresh the container's state [9]. Citations:
🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== Files matching relevant names =="
git ls-files 2>/dev/null || true \
| grep -E '(^|/)(Makefile|compose.*\.ya?ml|docker-compose\.ya?ml|\.env(_[^/]+)?)$' || true
echo
echo "== Makefile around restart target =="
awk 'NR>=45 && NR<=70 { printf "%6d\t%s\n", NR, $0 }' Makefile 2>/dev/null || true
echo
echo "== Search restart / docker compose / env changes =="
grep -n -- "restart:|docker compose|env changes" Makefile Makefile.lock 2>/dev/null | head -50 || trueRepository: plan-cake/plancake Length of output: 16153 Recreate containers when applying environment changes.
|
||||||
|
|
||||||
| # --- LOGS --- | ||||||
|
|
||||||
| # Stream the Django backend logs | ||||||
| logs-api: | ||||||
| docker compose logs -f backend | ||||||
|
|
||||||
| # Stream the Next.js frontend logs | ||||||
| logs-web: | ||||||
| docker compose logs -f frontend | ||||||
|
|
||||||
| # --- SHELLS & COMMANDS --- | ||||||
|
|
||||||
| # Print out the URLs for the local and network access. | ||||||
| url: | ||||||
| @echo "" && \ | ||||||
| echo "Plancake Industries" && \ | ||||||
| echo " - Local: http://localhost:3000" && \ | ||||||
| echo " - Network: $$(node scripts/print-ip.js)" && \ | ||||||
| echo "" | ||||||
|
|
||||||
| # Open a terminal inside the frontend container | ||||||
| shell-web: | ||||||
| docker compose exec -it frontend /bin/sh | ||||||
|
|
||||||
| # Open a terminal inside the backend container | ||||||
| shell-api: | ||||||
| docker compose exec -it backend /bin/bash | ||||||
|
Comment on lines
+86
to
+87
|
||||||
|
|
||||||
| # Run Django migrations inside the running container | ||||||
| migrate: | ||||||
| docker compose exec backend python manage.py migrate | ||||||
|
|
||||||
| # Generate new Django migrations inside the running container | ||||||
| makemigrations: | ||||||
| docker compose exec backend python manage.py makemigrations api | ||||||
Uh oh!
There was an error while loading. Please reload this page.