Skip to content

Commit

Permalink
Add base_image end-point
Browse files Browse the repository at this point in the history
  • Loading branch information
JonJagger committed Jan 21, 2025
1 parent fbadb11 commit 49d4ddd
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 15 deletions.
8 changes: 7 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
FROM cyberdojo/sinatra-base:db948c1
ARG BASE_IMAGE
FROM ${BASE_IMAGE}
LABEL [email protected]

WORKDIR /dashboard

COPY source/server .

# ARGs are reset after FROM See https://github.com/moby/moby/issues/34129
ARG BASE_IMAGE
ENV BASE_IMAGE=${BASE_IMAGE}

ARG COMMIT_SHA
ENV SHA=${COMMIT_SHA}

Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2024, [CyberDojo Foundation](http://blog.cyber-dojo.org/2015/08/cyber-dojo-foundation.html)
Copyright (c) 2025, [CyberDojo Foundation](http://blog.cyber-dojo.org/2015/08/cyber-dojo-foundation.html)
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
14 changes: 4 additions & 10 deletions bin/build_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ show_help()
Use: ${MY_NAME} {server|client}
Options:
server - build the server image (local only)
client - build the client image (local and CI workflow)
server - build the server image
client - build the client image
EOF
}
Expand Down Expand Up @@ -43,21 +43,14 @@ check_args()
build_image()
{
check_args "$@"

local -r type="${1}"

if [ -n "${CI:-}" ] && [ "${type}" == 'server' ] ; then
stderr "In CI workflow - use previous docker/build-push-action@v6 GitHub Action"
exit 42
fi

exit_non_zero_unless_installed docker
export $(echo_versioner_env_vars)

containers_down
remove_old_images

docker compose build --build-arg COMMIT_SHA="${COMMIT_SHA}" server
docker compose build server
#if [ "${type}" == 'client' ]; then
# docker compose build --build-arg COMMIT_SHA="${COMMIT_SHA}" client
#fi
Expand All @@ -76,6 +69,7 @@ build_image()
docker tag "${image_name}" "cyberdojo/dashboard:${CYBER_DOJO_DASHBOARD_TAG}"
echo "CYBER_DOJO_DASHBOARD_SHA=${CYBER_DOJO_DASHBOARD_SHA}"
echo "CYBER_DOJO_DASHBOARD_TAG=${CYBER_DOJO_DASHBOARD_TAG}"
echo cyberdojo/dashboard:${CYBER_DOJO_DASHBOARD_TAG}
fi
}

Expand Down
1 change: 1 addition & 0 deletions bin/demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ curl_smoke_test()
curl_json_body_200 alive
curl_json_body_200 ready
curl_json_body_200 sha
curl_json_body_200 base_image

curl_plain_200 assets/app.css 'content-type: text/css'
curl_plain_200 assets/app.js 'content-type: application/javascript'
Expand Down
4 changes: 4 additions & 0 deletions bin/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ echo_versioner_env_vars()
local -r AWS_ACCOUNT_ID=244531986313
local -r AWS_REGION=eu-central-1
echo CYBER_DOJO_DASHBOARD_IMAGE="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/dashboard"

if [[ ! -v CYBER_DOJO_DASHBOARD_BASE_IMAGE ]] ; then
echo CYBER_DOJO_DASHBOARD_BASE_IMAGE=cyberdojo/sinatra-base:db948c1
fi
}

containers_down()
Expand Down
8 changes: 6 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ services:
image: ${CYBER_DOJO_DASHBOARD_CLIENT_IMAGE}:${CYBER_DOJO_DASHBOARD_TAG}
user: ${CYBER_DOJO_DASHBOARD_CLIENT_USER}
build:
args: [ COMMIT_SHA ]
args:
- COMMIT_SHA
- BASE_IMAGE=${CYBER_DOJO_DASHBOARD_BASE_IMAGE}
context: source/client
container_name: ${CYBER_DOJO_DASHBOARD_CLIENT_CONTAINER_NAME}
depends_on:
Expand All @@ -36,7 +38,9 @@ services:
image: ${CYBER_DOJO_DASHBOARD_IMAGE}:${CYBER_DOJO_DASHBOARD_TAG}
user: ${CYBER_DOJO_DASHBOARD_SERVER_USER}
build:
args: [ COMMIT_SHA ]
args:
- COMMIT_SHA
- BASE_IMAGE=${CYBER_DOJO_DASHBOARD_BASE_IMAGE}
context: .
container_name: ${CYBER_DOJO_DASHBOARD_SERVER_CONTAINER_NAME}
depends_on:
Expand Down
9 changes: 8 additions & 1 deletion source/client/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
FROM cyberdojo/sinatra-base:db948c1
#FROM cyberdojo/sinatra-base:db948c1
ARG BASE_IMAGE
FROM ${BASE_IMAGE}
LABEL [email protected]

WORKDIR /app

COPY . .

# ARGs are reset after FROM See https://github.com/moby/moby/issues/34129
ARG BASE_IMAGE
ENV BASE_IMAGE=${BASE_IMAGE}

ARG COMMIT_SHA
ENV SHA=${COMMIT_SHA}

Expand Down
1 change: 1 addition & 0 deletions source/server/app/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def initialize(externals)
get_delegate(Prober, :alive?)
get_delegate(Prober, :ready?)
get_delegate(Prober, :sha)
get_delegate(Prober, :base_image)

get '/show/:id', provides: [:html] do
@id = params[:id]
Expand Down
4 changes: 4 additions & 0 deletions source/server/app/prober.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ def sha(_args)
ENV.fetch('SHA', nil)
end

def base_image(_args)
ENV.fetch('BASE_IMAGE', nil)
end

private

def saver
Expand Down

0 comments on commit 49d4ddd

Please sign in to comment.