Skip to content

Commit

Permalink
chore: simplify Dockerfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
alecthomas committed Nov 28, 2024
1 parent 547598c commit c2c3afd
Show file tree
Hide file tree
Showing 23 changed files with 164 additions and 535 deletions.
62 changes: 15 additions & 47 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -218,62 +218,30 @@ jobs:
- uses: actions/checkout@v4
- uses: cashapp/[email protected]
- run: go-arch-lint check || true
docker-build-controller:
name: Build Controller Docker Image
# if: github.event_name != 'pull_request' || github.event.action == 'enqueued' || contains( github.event.pull_request.labels.*.name, 'run-all')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: cashapp/[email protected]
- uses: ./.github/actions/build-cache
- run: just build-docker controller
docker-build-provisioner:
name: Build Provisioner Docker Image
# if: github.event_name != 'pull_request' || github.event.action == 'enqueued' || contains( github.event.pull_request.labels.*.name, 'run-all')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: cashapp/[email protected]
- uses: ./.github/actions/build-cache
- run: just build-docker provisioner
docker-build-cron:
name: Build Cron Docker Image
# if: github.event_name != 'pull_request' || github.event.action == 'enqueued' || contains( github.event.pull_request.labels.*.name, 'run-all')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: cashapp/[email protected]
- uses: ./.github/actions/build-cache
- run: just build-docker cron
docker-build-http-ingress:
name: Build HTTP Ingress Docker Image
# if: github.event_name != 'pull_request' || github.event.action == 'enqueued' || contains( github.event.pull_request.labels.*.name, 'run-all')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: cashapp/[email protected]
- uses: ./.github/actions/build-cache
- run: just build-docker http-ingress
docker-build-runner:
name: Build Runner Docker Images
# if: github.event_name != 'pull_request' || github.event.action == 'enqueued' || contains( github.event.pull_request.labels.*.name, 'run-all')
docker-shard:
name: Shard Docker Builds
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- uses: cashapp/[email protected]
- uses: ./.github/actions/build-cache
- name: Build Runner Docker Image
run: just build-docker runner
docker-build-jvm-runners:
name: Build JVM Runner Docker Images
# if: github.event_name != 'pull_request' || github.event.action == 'enqueued' || contains( github.event.pull_request.labels.*.name, 'run-all')
- id: set-matrix
run: echo "matrix=$(just list-docker-images | tr -d '\n' | jq -R -s -c 'split(" ")')" >> "$GITHUB_OUTPUT"
docker-build:
name: Build ${{ matrix.service }} Docker Image
needs: docker-shard
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
service: ${{ fromJson(needs.docker-shard.outputs.matrix) }}
steps:
- uses: actions/checkout@v4
- uses: cashapp/[email protected]
- uses: ./.github/actions/build-cache
- name: Build JVM Docker Imag
run: just build-docker runner-jvm
- name: Build Docker Image
run: just build-docker ${{ matrix.service }}
console-e2e:
name: Console e2e
# if: github.event_name != 'pull_request' || github.event.action == 'enqueued' || contains( github.event.pull_request.labels.*.name, 'run-all')
Expand Down
199 changes: 40 additions & 159 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,195 +4,76 @@ on:
- "v[0-9]+.[0-9]+.[0-9]+"
name: Automatically Build Release
jobs:
build-runners:
name: Build Runner Docker Images
docker-shard:
name: Shard Docker Builds
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Init Hermit
uses: cashapp/[email protected]
- name: Build Runner
run: |
just build-docker runner
mkdir -p artifacts/ftl-runner
docker save -o artifacts/ftl-runner/ftl-runner.tar ftl0/ftl-runner:latest
- name: Temporarily save Docker image
uses: actions/upload-artifact@v4
with:
name: docker-runner-artifact
path: artifacts/ftl-runner/ftl-runner.tar
retention-days: 1
- name: Build JVM Runner
run: |
just build-docker runner-jvm
mkdir -p artifacts/ftl-runner-jvm
docker save -o artifacts/ftl-runner-jvm/ftl-runner-jvm.tar ftl0/ftl-runner-jvm:latest
- name: Temporarily save JVM Docker image
uses: actions/upload-artifact@v4
with:
name: docker-runner-jvm-artifact
path: artifacts/ftl-runner-jvm/ftl-runner-jvm.tar
retention-days: 1
build-controller:
name: Build Controller Docker Image
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Init Hermit
uses: cashapp/[email protected]
- name: Build
run: |
just build-docker controller
mkdir -p artifacts/ftl-controller
docker save -o artifacts/ftl-controller/ftl-controller.tar ftl0/ftl-controller:latest
- name: Temporarily save Docker image
uses: actions/upload-artifact@v4
with:
name: docker-controller-artifact
path: artifacts/ftl-controller
retention-days: 1
build-provisioner:
name: Build Provisioner Docker Image
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Init Hermit
uses: cashapp/[email protected]
- name: Build
run: |
just build-docker provisioner
mkdir -p artifacts/ftl-provisioner
docker save -o artifacts/ftl-provisioner/ftl-provisioner.tar ftl0/ftl-provisioner:latest
- name: Temporarily save Docker image
uses: actions/upload-artifact@v4
with:
name: docker-provisioner-artifact
path: artifacts/ftl-provisioner
retention-days: 1
build-cron:
name: Build Cron Docker Image
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Init Hermit
uses: cashapp/[email protected]
- name: Build
run: |
just build-docker cron
mkdir -p artifacts/ftl-cron
docker save -o artifacts/ftl-cron/ftl-cron.tar ftl0/ftl-cron:latest
- name: Temporarily save Docker image
uses: actions/upload-artifact@v4
with:
name: docker-cron-artifact
path: artifacts/ftl-cron
retention-days: 1
build-http-ingress:
name: Build HTTP Ingress Docker Image
- uses: actions/checkout@v4
- uses: cashapp/[email protected]
- id: set-matrix
run: echo "matrix=$(just list-docker-images | tr -d '\n' | jq -R -s -c 'split(" ")')" >> "$GITHUB_OUTPUT"
build-docker-images:
name: Build ${{ matrix.service }} Docker Image
needs: docker-shard
runs-on: ubuntu-latest
strategy:
matrix:
service: ${{ fromJson(needs.docker-shard.outputs.matrix) }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Init Hermit
uses: cashapp/[email protected]
- name: Build
- name: Build Docker Image
run: |
just build-docker http-ingress
mkdir -p artifacts/ftl-http-ingress
docker save -o artifacts/ftl-http-ingress/ftl-http-ingress.tar ftl0/ftl-http-ingress:latest
just build-docker ${{ matrix.service }}
mkdir -p artifacts/ftl-${{ matrix.service }}
docker save -o artifacts/ftl-${{ matrix.service }}/ftl-${{ matrix.service }}.tar ftl0/ftl-${{ matrix.service }}:latest
- name: Temporarily save Docker image
uses: actions/upload-artifact@v4
with:
name: docker-http-ingress-artifact
path: artifacts/ftl-http-ingress
name: docker-${{ matrix.service }}-artifact
path: artifacts/ftl-${{ matrix.service }}
retention-days: 1
release-docker:
name: Release Assets
name: Release Docker Images
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
needs: [build-runners, build-controller, build-provisioner, build-cron, build-http-ingress]
needs: build-docker-images
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Init Hermit
uses: cashapp/[email protected]
- name: Retrieve Runner Docker image
uses: actions/download-artifact@v4
with:
name: docker-runner-artifact
path: artifacts/ftl-runner
- name: Retrieve JVM Runner Docker image
uses: actions/download-artifact@v4
with:
name: docker-runner-jvm-artifact
path: artifacts/ftl-runner-jvm
- name: Retrieve Controller Docker image
uses: actions/download-artifact@v4
with:
name: docker-controller-artifact
path: artifacts/ftl-controller
- name: Retrieve Provisioner Docker image
uses: actions/download-artifact@v4
with:
name: docker-provisioner-artifact
path: artifacts/ftl-provisioner
- name: Retrieve Cron Docker image
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
name: docker-cron-artifact
path: artifacts/ftl-cron
- name: Retrieve HTTP Ingress Docker image
uses: actions/download-artifact@v4
with:
name: docker-http-ingress-artifact
path: artifacts/ftl-http-ingress
- name: Load Runner Docker image
run: docker load -i artifacts/ftl-runner/ftl-runner.tar
- name: Load JVM Runner Docker image
run: docker load -i artifacts/ftl-runner-jvm/ftl-runner-jvm.tar
- name: Load Controller Docker image
run: docker load -i artifacts/ftl-controller/ftl-controller.tar
- name: Load Provisioner Docker image
run: docker load -i artifacts/ftl-provisioner/ftl-provisioner.tar
- name: Load Cron Docker image
run: docker load -i artifacts/ftl-cron/ftl-cron.tar
- name: Load HTTP Ingress Docker image
run: docker load -i artifacts/ftl-http-ingress/ftl-http-ingress.tar
- name: Log in to the Container registry
path: artifacts
pattern: docker-*-artifact
- name: Load Docker images
run: |
for tar in artifacts/ftl-*/ftl-*.tar; do
docker load -i "$tar"
done
- name: Log in to Container registry
uses: docker/login-action@v3
with:
username: ftl0
password: ${{ secrets.FTL_DOCKER_PUSH_TOKEN }}
- name: Push Docker Images
run: |
version="$(git describe --tags --abbrev=0)"
docker tag ftl0/ftl-runner:latest ftl0/ftl-runner:"$GITHUB_SHA"
docker tag ftl0/ftl-runner:latest ftl0/ftl-runner:"$version"
docker push -a ftl0/ftl-runner
docker tag ftl0/ftl-runner-jvm:latest ftl0/ftl-runner-jvm:"$GITHUB_SHA"
docker tag ftl0/ftl-runner-jvm:latest ftl0/ftl-runner-jvm:"$version"
docker push -a ftl0/ftl-runner-jvm
docker tag ftl0/ftl-controller:latest ftl0/ftl-controller:"$GITHUB_SHA"
docker tag ftl0/ftl-controller:latest ftl0/ftl-controller:"$version"
docker push -a ftl0/ftl-controller
docker tag ftl0/ftl-provisioner:latest ftl0/ftl-provisioner:"$GITHUB_SHA"
docker tag ftl0/ftl-provisioner:latest ftl0/ftl-provisioner:"$version"
docker push -a ftl0/ftl-provisioner
docker tag ftl0/ftl-cron:latest ftl0/ftl-cron:"$GITHUB_SHA"
docker tag ftl0/ftl-cron:latest ftl0/ftl-cron:"$version"
docker push -a ftl0/ftl-cron
docker tag ftl0/ftl-http-ingress:latest ftl0/ftl-http-ingress:"$GITHUB_SHA"
docker tag ftl0/ftl-http-ingress:latest ftl0/ftl-http-ingress:"$version"
docker push -a ftl0/ftl-http-ingress
for image in $(just list-docker-images); do
docker tag "ftl0/ftl-${image}:latest" "ftl0/ftl-${image}:${GITHUB_SHA}"
docker tag "ftl0/ftl-${image}:latest" "ftl0/ftl-${image}:${version}"
docker push -a "ftl0/ftl-${image}"
done
create-go-release:
name: Release Go Binaries
runs-on: ubuntu-latest
Expand Down Expand Up @@ -305,8 +186,8 @@ jobs:
- uses: actions/checkout@v4
name: "Checkout Charts Repository"
with:
repository: '${{ github.repository_owner }}/ftl-charts'
token: '${{ secrets.FTL_CHARTS_TOKEN }}'
repository: "${{ github.repository_owner }}/ftl-charts"
token: "${{ secrets.FTL_CHARTS_TOKEN }}"
fetch-depth: 0
- name: Checkout FTL
uses: actions/checkout@v4
Expand All @@ -316,7 +197,7 @@ jobs:
- name: Init Hermit
uses: cashapp/[email protected]
with:
working-directory: '.ftl'
working-directory: ".ftl"
- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
Expand All @@ -332,4 +213,4 @@ jobs:
cp -r .ftl/charts/ charts/
git add charts
git commit -a -m "Update charts"
git push
git push
47 changes: 47 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Declare build arguments at the very top
ARG RUNTIME=scratch-runtime
ARG SERVICE

# Get certificates from Alpine (smaller than Ubuntu)
FROM alpine:latest AS certs
RUN apk --update add ca-certificates

# Runtime stage
FROM scratch AS scratch-runtime
ARG SERVICE
COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
WORKDIR /service/
COPY ftl-${SERVICE} .

FROM ubuntu:24.04 AS ubuntu-runtime
ARG SERVICE
RUN apt-get update && apt-get install -y ca-certificates
WORKDIR /root/
COPY ftl-${SERVICE} .
RUN mkdir -p deployments

# Final stage selection
FROM ${RUNTIME}
ARG SERVICE

# Common environment variables
ENV PATH="$PATH:/plugins/"

# Service-specific configurations
EXPOSE 8891
EXPOSE 8892

# Environment variables for all (most) services
ENV FTL_ENDPOINT="http://host.docker.internal:8892"
ENV FTL_BIND=http://0.0.0.0:8892
ENV FTL_ADVERTISE=http://127.0.0.1:8892

# Controller-specific configurations
ENV FTL_CONTROLLER_CONSOLE_URL="*"
ENV FTL_CONTROLLER_DSN="postgres://host.docker.internal/ftl?sslmode=disable&user=postgres&password=secret"

# Provisioner-specific configurations
ENV FTL_PROVISIONER_PLUGIN_CONFIG_FILE="/config/config.toml"

# Default command
CMD ["/service/ftl-${SERVICE}"]
Loading

0 comments on commit c2c3afd

Please sign in to comment.