Skip to content

Commit

Permalink
hotfix: ditch docker build acrobatics
Browse files Browse the repository at this point in the history
  • Loading branch information
FilipHarald committed Oct 11, 2024
1 parent 0f3bfe4 commit f13f712
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 96 deletions.
24 changes: 11 additions & 13 deletions k8s/production/skaffold.production.full.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ kind: Config
metadata:
name: chicmoz-prod
build:
local:
push: false
artifacts:
- image: chicmoz-base
- image: registry.digitalocean.com/aztlan-containers/chicmoz-base
context: .
docker:
dockerfile: Dockerfile
- image: explorer-ui
- image: registry.digitalocean.com/aztlan-containers/explorer-ui
context: services/explorer-ui
docker:
dockerfile: Dockerfile
Expand All @@ -19,35 +17,35 @@ build:
VITE_API_URL: "https://api.chicmoz.info/v1/d1e2083a-660c-4314-a6f2-1d42f4b944f4" # TODO: change the api key
VITE_WS_URL: "wss://ws.chicmoz.info"
requires:
- image: chicmoz-base
- image: registry.digitalocean.com/aztlan-containers/chicmoz-base
alias: BASE
- image: auth
- image: registry.digitalocean.com/aztlan-containers/auth
context: services/auth
docker:
dockerfile: Dockerfile
requires:
- image: chicmoz-base
- image: registry.digitalocean.com/aztlan-containers/chicmoz-base
alias: BASE
- image: aztec-listener
- image: registry.digitalocean.com/aztlan-containers/aztec-listener
context: services/aztec-listener
docker:
dockerfile: Dockerfile
requires:
- image: chicmoz-base
- image: registry.digitalocean.com/aztlan-containers/chicmoz-base
alias: BASE
- image: explorer-api
- image: registry.digitalocean.com/aztlan-containers/explorer-api
context: services/explorer-api
docker:
dockerfile: Dockerfile
requires:
- image: chicmoz-base
- image: registry.digitalocean.com/aztlan-containers/chicmoz-base
alias: BASE
- image: websocket-event-publisher
- image: registry.digitalocean.com/aztlan-containers/websocket-event-publisher
context: services/websocket-event-publisher
docker:
dockerfile: Dockerfile
requires:
- image: chicmoz-base
- image: registry.digitalocean.com/aztlan-containers/chicmoz-base
alias: BASE
manifests:
rawYaml:
Expand Down
24 changes: 11 additions & 13 deletions k8s/production/skaffold.production.light.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ kind: Config
metadata:
name: chicmoz-prod
build:
local:
push: false
artifacts:
- image: chicmoz-base
- image: registry.digitalocean.com/aztlan-containers/chicmoz-base
context: .
docker:
dockerfile: Dockerfile
- image: explorer-ui
- image: registry.digitalocean.com/aztlan-containers/explorer-ui
context: services/explorer-ui
docker:
dockerfile: Dockerfile
Expand All @@ -19,35 +17,35 @@ build:
VITE_API_URL: "https://api.chicmoz.info/v1/d1e2083a-660c-4314-a6f2-1d42f4b944f4" # TODO: change the api key
VITE_WS_URL: "wss://ws.chicmoz.info"
requires:
- image: chicmoz-base
- image: registry.digitalocean.com/aztlan-containers/chicmoz-base
alias: BASE
- image: auth
- image: registry.digitalocean.com/aztlan-containers/auth
context: services/auth
docker:
dockerfile: Dockerfile
requires:
- image: chicmoz-base
- image: registry.digitalocean.com/aztlan-containers/chicmoz-base
alias: BASE
- image: aztec-listener
- image: registry.digitalocean.com/aztlan-containers/aztec-listener
context: services/aztec-listener
docker:
dockerfile: Dockerfile
requires:
- image: chicmoz-base
- image: registry.digitalocean.com/aztlan-containers/chicmoz-base
alias: BASE
- image: explorer-api
- image: registry.digitalocean.com/aztlan-containers/explorer-api
context: services/explorer-api
docker:
dockerfile: Dockerfile
requires:
- image: chicmoz-base
- image: registry.digitalocean.com/aztlan-containers/chicmoz-base
alias: BASE
- image: websocket-event-publisher
- image: registry.digitalocean.com/aztlan-containers/websocket-event-publisher
context: services/websocket-event-publisher
docker:
dockerfile: Dockerfile
requires:
- image: chicmoz-base
- image: registry.digitalocean.com/aztlan-containers/chicmoz-base
alias: BASE
manifests:
rawYaml:
Expand Down
71 changes: 1 addition & 70 deletions scripts/production/deploy.sh
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,74 +1,5 @@
#!/bin/bash

# NOTE: all this hassle just to *only* use 5 images on the registry...

set -e

# List of images to push
IMAGES_TO_PUSH=(
"explorer-ui"
"auth"
"aztec-listener"
"explorer-api"
"websocket-event-publisher"
)

echo "⚠ Building images - this may take a while..."
# Build images and get the build output
BUILD_OUTPUT=$(skaffold build --filename "k8s/production/skaffold.production.light.yaml" --quiet)

# Function to extract tag for a specific image
get_tag() {
local image=$1
echo "$BUILD_OUTPUT" | grep "$image" | sed -E 's/.*:([^}]+)\}.*/\1/' | tr -d '"'
}

# Function to find the latest image
find_latest_image() {
local image=$1
docker images --format "{{.Repository}}:{{.Tag}}" | grep "^$image:" | head -n 1
}

# Tag and push each image
for image in "${IMAGES_TO_PUSH[@]}"
do
TAG=$(get_tag "$image")
if [ -n "$TAG" ]; then
LATEST_IMAGE=$(find_latest_image "$image")
if [ -n "$LATEST_IMAGE" ]; then
echo "Tagging and pushing $LATEST_IMAGE as registry.digitalocean.com/aztlan-containers/$image:$TAG"
docker tag "$LATEST_IMAGE" "registry.digitalocean.com/aztlan-containers/$image:$TAG"
echo "Tagging and pushing $LATEST_IMAGE as registry.digitalocean.com/aztlan-containers/$image:latest"
docker tag "$LATEST_IMAGE" "registry.digitalocean.com/aztlan-containers/$image:latest"
docker push "registry.digitalocean.com/aztlan-containers/$image:$TAG"
docker push "registry.digitalocean.com/aztlan-containers/$image:latest"
else
echo "Failed to find latest image for $image"
exit 1
fi
else
echo "Failed to get tag for $image"
exit 1
fi
done

# Get the tag for chicmoz-base
CHICMOZ_BASE_TAG=$(get_tag "chicmoz-base")

# Prepare the --images argument for skaffold deploy
DEPLOY_IMAGES_ARG="chicmoz-base=chicmoz-base:$CHICMOZ_BASE_TAG,"
for image in "${IMAGES_TO_PUSH[@]}"
do
TAG=$(get_tag "$image")
if [ -n "$TAG" ]; then
DEPLOY_IMAGES_ARG+="$image=registry.digitalocean.com/aztlan-containers/$image:$TAG,"
else
echo "Failed to get tag for $image"
exit 1
fi
done
DEPLOY_IMAGES_ARG=${DEPLOY_IMAGES_ARG%,} # Remove trailing comma

# Deploy using Skaffold
echo "Deploying with images: $DEPLOY_IMAGES_ARG"
skaffold deploy --filename "k8s/production/skaffold.production.light.yaml" --images "$DEPLOY_IMAGES_ARG"
skaffold run --filename "k8s/production/skaffold.production.light.yaml" --default-repo=registry.digitalocean.com/aztlan-containers

0 comments on commit f13f712

Please sign in to comment.