Skip to content

Commit f8ed83c

Browse files
committed
🚧 Work in progress: Define docker-image;
1 parent ab847a6 commit f8ed83c

File tree

8 files changed

+149
-186
lines changed

8 files changed

+149
-186
lines changed

.github/workflows/image.yaml

+48-11
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,55 @@ on:
55
paths:
66
- 'ci/dockerfiles/**'
77
- '.github/workflows/image.yml'
8+
- '.tool-versions'
89
pull_request:
910
paths:
1011
- 'ci/dockerfiles/**'
1112
- '.github/workflows/image.yml'
13+
- '.tool-versions'
1214
workflow_dispatch:
1315

1416
env:
1517
REGISTRY: ghcr.io
16-
IMAGE_NAME: ${{ github.repository }}
17-
1818
jobs:
19+
build-and-push-devbox-image:
20+
runs-on: ubuntu-latest
21+
permissions:
22+
contents: read
23+
packages: write
24+
name: Build and Push app-autoscaler-release-devbox
25+
env:
26+
IMAGE_NAME: ${{ github.repository }}-devbox
27+
steps:
28+
- name: Checkout repository
29+
uses: actions/checkout@v4
30+
31+
- name: Log in to the Container registry
32+
uses: docker/login-action@v3
33+
with:
34+
registry: ${{ env.REGISTRY }}
35+
username: ${{ github.actor }}
36+
password: ${{ secrets.GITHUB_TOKEN }}
37+
38+
- name: Extract metadata (tags, labels) for Docker
39+
id: meta
40+
uses: docker/metadata-action@v5
41+
with:
42+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
43+
44+
- name: Build and push
45+
id: build-and-push
46+
uses: docker/build-push-action@v5
47+
with:
48+
context: .
49+
file: ci/dockerfiles/autoscaler-devbox/Dockerfile
50+
push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
51+
tags: ${{ steps.meta.outputs.tags }}
52+
labels: ${{ steps.meta.outputs.labels }}
53+
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:main
54+
1955
build-and-push-image:
2056
runs-on: ubuntu-latest
21-
container: jetpackio/devbox:latest@sha256:3d164648f5ca0fa66cd080ee7c895af54e0a3ec19e19b232a2fea21628e82cfb
2257
permissions:
2358
contents: read
2459
packages: write
@@ -29,40 +64,42 @@ jobs:
2964
matrix:
3065
image_suffix: ["tools"]
3166
name: Build and Push app-autoscaler-release-${{ matrix.image_suffix }}
67+
env:
68+
IMAGE_NAME: ${{ github.repository }}
3269
steps:
3370
- name: Checkout repository
34-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
71+
uses: actions/checkout@v4
3572

3673
- name: Log in to the Container registry
37-
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3
74+
uses: docker/login-action@v3
3875
with:
3976
registry: ${{ env.REGISTRY }}
4077
username: ${{ github.actor }}
4178
password: ${{ secrets.GITHUB_TOKEN }}
4279

4380
- name: Extract metadata (tags, labels) for Docker
4481
id: meta
45-
uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5
82+
uses: docker/metadata-action@v5
4683
with:
4784
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-${{ matrix.image_suffix }}
4885

4986
- name: Get ginkgo version from autoscaler-release
5087
id: ginkgo
5188
run: |
52-
version=$(devbox info ginkgo | head --lines=1 | cut --field=2 --delimiter=" ")
53-
echo "GINKGO version from devbox: '${version}'"
89+
version=$(grep "ginkgo " .tool-versions| cut -f 2 -d " ")
90+
echo "GINKGO version from .tool-versions: \'${version}\'"
5491
echo "version=${version}" >> "$GITHUB_OUTPUT"
5592
5693
- id: get-golang-version
5794
shell: bash
5895
run: |
59-
version=$(devbox info go | head --lines=1 | cut --field=2 --delimiter=" ")
60-
echo "Go version from devbox: '${version}'"
96+
version=$(grep "golang " .tool-versions| cut -f 2 -d " ")
97+
echo "Go version from .tool-versions: \'${version}\'"
6198
echo "version=${version}" >> "$GITHUB_OUTPUT"
6299
63100
- name: Build and push
64101
id: build-and-push
65-
uses: docker/build-push-action@14487ce63c7a62a4a324b0bfb37086795e31c6c1 # v6
102+
uses: docker/build-push-action@v5
66103
with:
67104
context: ci/dockerfiles/autoscaler-${{ matrix.image_suffix }}
68105
push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}

.gitignore

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# # Edit: Please use global git-ignore for this, see official hints in the description of gitignore
2+
# # on <https://git-scm.com/docs/gitignore>.
3+
#
4+
# # macOS system file that stores folder metadata (safe to ignore)
5+
# .DS_Store
6+
7+
8+
# ================================================================================
9+
# 🤖 Generated files
10+
# ================================================================================
11+
112
config/dev.yml
213
config/private.yml
314
releases/*.tgz
@@ -66,16 +77,11 @@ keys/
6677
.trunk
6778

6879

69-
# ==================== 📦 Devbox ====================
80+
# ==================== 📦 Devbox, ❄ Nix, direnv ====================
7081
.devbox
7182

72-
# ==================== ❄ Nix ====================
73-
7483
# Ignore links to build-output:
7584
/result
7685
/result-*
7786

7887
.direnv
79-
80-
# # macOS system file that stores folder metadata (safe to ignore)
81-
.DS_Store

Makefile

+1-5
Original file line numberDiff line numberDiff line change
@@ -490,11 +490,7 @@ alerts-silence:
490490
${CI_DIR}/autoscaler/scripts/silence_prometheus_alert.sh BOSHJobEphemeralDiskPredictWillFill ;\
491491
${CI_DIR}/autoscaler/scripts/silence_prometheus_alert.sh BOSHJobUnhealthy ;
492492

493-
.PHONY: docker-login docker docker-image
494-
docker-login: target/docker-login
495-
target/docker-login:
496-
docker login ghcr.io
497-
@touch $@
493+
.PHONY: docker-image
498494
docker-image: docker-login
499495
docker build -t ghcr.io/cloudfoundry/app-autoscaler-release-tools:latest ci/dockerfiles/autoscaler-tools
500496
docker push ghcr.io/cloudfoundry/app-autoscaler-release-tools:latest

ci/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# ================================================================================
2+
# 🤖 Generated files
3+
# ================================================================================

ci/Dockerfile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM jetpackio/devbox:latest
2+
3+
# Installing your devbox project
4+
WORKDIR /code
5+
USER root:root
6+
RUN mkdir -p /code && chown ${DEVBOX_USER}:${DEVBOX_USER} /code
7+
USER ${DEVBOX_USER}:${DEVBOX_USER}
8+
COPY --chown=${DEVBOX_USER}:${DEVBOX_USER} devbox.json devbox.json
9+
COPY --chown=${DEVBOX_USER}:${DEVBOX_USER} devbox.lock devbox.lock
10+
11+
12+
# Step 6: Copying local flakes directories
13+
COPY ./.devbox/virtenv/mysql/flake ./.devbox/virtenv/mysql/flake
14+
COPY ./nix ./nix
15+
16+
RUN devbox run -- echo "Installed Packages."
17+
18+
# 🚧 To-do: Check if “ENTRYPOINT” is not the better alternative, see:
19+
# <https://www.bmc.com/blogs/docker-cmd-vs-entrypoint>
20+
CMD ["devbox", "shell"]

ci/Dockerfile.dockerignore

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# ==================== Ignore everything by default ====================
2+
*
3+
4+
5+
6+
# ==================== What we actually need ====================
7+
!./nix
8+
!/flake.nix
9+
!/flake.lock
10+
11+
!./.devbox/virtenv/mysql/flake
12+
!/devbox.json
13+
!/devbox.lock

ci/Makefile

+52
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,55 @@
1+
.ONESHELL:
2+
SHELL := /bin/bash
3+
.SHELLFLAGS := -eu -o pipefail -c
4+
5+
repository-root := $(shell git rev-parse --show-toplevel)
6+
7+
# All files that together define the development-environment:
8+
development-environment-definition := \
9+
${repository-root}/devbox.json ${repository-root}/devbox.lock \
10+
${repository-root}/flake.nix ${repository-root}/flake.lock \
11+
${repository-root}/.devbox/virtenv/mysql/flake/flake.nix \
12+
${repository-root}/.devbox/virtenv/mysql/flake/flake.lock
13+
# 🚸 Please be aware that devbox automatically creates
14+
# '${repository-root}/.devbox/virtenv/mysql/flake' when it loads the development-environment.
15+
16+
# The generated Dockerfile just depends on the content of the used “devbox.json” and its lockfile.
17+
# It is marked secondary to not auto-clean it.
18+
.SECONDARY: Dockerfile
19+
Dockerfile: ./Makefile ${repository-root}/devbox.json ${repository-root}/devbox.lock
20+
devbox generate dockerfile --config='${repository-root}'
21+
mv '${repository-root}/Dockerfile' .
22+
23+
# 🚸 Overwrite the following parameters to work with a different repository on a different registry:
24+
DOCKER_REGISTRY ?= ghcr.io
25+
DOCKER_REPOSITORY ?= cloudfoundry/app-autoscaler-release-tools
26+
27+
.PHONY: docker-login
28+
docker-login:
29+
@logged_in=$$(jq '.auths | has("${DOCKER_REGISTRY}")' ~/.docker/config.json)
30+
readonly logged_in
31+
if [[ "$${logged_in}" != 'true' ]]
32+
then
33+
docker login '${DOCKER_REGISTRY}'
34+
else
35+
echo 'Already logged in into ${DOCKER_REGISTRY}, skipping login.'
36+
fi
37+
38+
# 🚧 To-do: Come with appropriate Dockerignore!
39+
.PHONY: docker-image
40+
docker-image: ./Makefile Dockerfile ${development-environment-definition}
41+
docker build --file='./Dockerfile' '${repository-root}' \
42+
--tag='${DOCKER_REGISTRY}/${DOCKER_REPOSITORY}:latest'
43+
44+
# 🚧 To-do: Include workflow to produce the image and push it from the CI/CD-pipeline, see:
45+
# <https://github.com/cloudfoundry/app-autoscaler-release/pull/2943/files#diff-b4df0a4f0d80f73138c476afbd7aefdac9df339642ddfba323d27c8cbabb92e2>
46+
docker-image-push: docker-login docker-image
47+
@ARTIFACT='${DOCKER_REGISTRY}/${DOCKER_REPOSITORY}:$*'
48+
echo "Uploading image" "$${ARTIFACT}"
49+
docker push "$${ARTIFACT}"
50+
51+
52+
153
.PHONY: set-autoscaler-pipeline
254
set-autoscaler-pipeline:
355
@./autoscaler/set-pipeline.sh

0 commit comments

Comments
 (0)