Skip to content

Commit 7b2462d

Browse files
committed
Fix inconsistent image digest
1 parent 27278c2 commit 7b2462d

File tree

2 files changed

+61
-50
lines changed

2 files changed

+61
-50
lines changed

.github/workflows/build-publish.yml

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,9 @@ jobs:
7070
VERSION=$(echo $VERSION | sed -e 's/^v//')
7171
# [ "$VERSION" == "master" ] && VERSION=latest
7272
73-
IMAGE_REPOSITORY=st8ed/aws-cost-exporter
74-
7573
echo "VERSION=$VERSION" >>$GITHUB_ENV
7674
echo "VERSION=$VERSION"
7775
78-
echo "IMAGE_REPOSITORY=$IMAGE_REPOSITORY" >>$GITHUB_ENV
79-
echo "IMAGE_REPOSITORY=$IMAGE_REPOSITORY"
80-
8176
- name: Package release
8277
run: |
8378
tar cf ./dist/aws-cost-exporter-$VERSION.linux-amd64.tar.gz \
@@ -87,11 +82,6 @@ jobs:
8782
echo "chart=$chart"
8883
mv -v ./dist/chart/*.tgz ./dist/$chart
8984
90-
- name: Load image
91-
run: |
92-
docker load -i ./dist/image/*.tar.gz
93-
docker tag $IMAGE_REPOSITORY:$VERSION $IMAGE_REPOSITORY:latest
94-
9585
- name: Log in to Docker Hub
9686
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
9787
with:
@@ -100,11 +90,15 @@ jobs:
10090

10191
- name: Push image
10292
run: |
103-
docker push $IMAGE_REPOSITORY:$VERSION
104-
docker push $IMAGE_REPOSITORY:latest
93+
# --preserve-digests \
94+
skopeo copy \
95+
--digestfile /dev/stdout \
96+
dir:./dist/image \
97+
docker://index.docker.io/st8ed/aws-cost-exporter:$VERSION
10598
10699
- name: Create release
107100
uses: softprops/action-gh-release@1e07f4398721186383de40550babbdf2b84acfc5
101+
if: ${{ !endsWith(github.ref, '-rc') }}
108102
with:
109103
name: Release ${{ env.VERSION }}
110104
files: |

flake.nix

Lines changed: 55 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -56,49 +56,65 @@
5656
};
5757
};
5858

59-
dockerPackage = { aws-cost-exporter, dockerTools, cacert, runCommandNoCC }: dockerTools.buildLayeredImage {
60-
name = "st8ed/aws-cost-exporter";
61-
tag = "${version}";
62-
63-
contents = [
64-
aws-cost-exporter
65-
];
66-
67-
fakeRootCommands = ''
68-
install -dm750 -o 1000 -g 1000 \
69-
./etc/aws-cost-exporter \
70-
./var/lib/aws-cost-exporter
71-
72-
cp -r \
73-
${aws-cost-exporter}/share/aws-cost-exporter/* \
74-
./etc/aws-cost-exporter
75-
'';
76-
77-
config = {
78-
Entrypoint = [ "/bin/aws-cost-exporter" ];
79-
Cmd = [ ];
80-
User = "1000:1000";
81-
WorkingDir = "/var/lib/aws-cost-exporter";
82-
83-
Env = [
84-
"SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt"
59+
dockerPackage = { pkgs, aws-cost-exporter, dockerTools, cacert, skopeo, moreutils, runCommandNoCC }:
60+
let
61+
# We compress image layers so the digest
62+
# will be reproducible when pushing to registry
63+
buildCompressedImage = stream: runCommandNoCC "aws-cost-exporter-dockerImage"
64+
{
65+
buildInputs = [ skopeo moreutils ];
66+
} ''
67+
# Piping archive stream to skopeo isn't working correctly
68+
${stream} > archive.tar
69+
70+
skopeo --insecure-policy copy docker-archive:./archive.tar dir:$out \
71+
--format v2s2 \
72+
--dest-compress
73+
'';
74+
75+
in
76+
buildCompressedImage (dockerTools.streamLayeredImage {
77+
name = "st8ed/aws-cost-exporter";
78+
tag = "${version}";
79+
80+
contents = [
81+
aws-cost-exporter
8582
];
8683

87-
ExposedPorts = {
88-
"9100/tcp" = { };
89-
};
90-
91-
Volumes = {
92-
"/var/lib/aws-cost-exporter" = { };
84+
fakeRootCommands = ''
85+
install -dm750 -o 1000 -g 1000 \
86+
./etc/aws-cost-exporter \
87+
./var/lib/aws-cost-exporter
88+
89+
cp -r \
90+
${aws-cost-exporter}/share/aws-cost-exporter/* \
91+
./etc/aws-cost-exporter
92+
'';
93+
94+
config = {
95+
Entrypoint = [ "/bin/aws-cost-exporter" ];
96+
Cmd = [ ];
97+
User = "1000:1000";
98+
WorkingDir = "/var/lib/aws-cost-exporter";
99+
100+
Env = [
101+
"SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt"
102+
];
103+
104+
ExposedPorts = {
105+
"9100/tcp" = { };
106+
};
107+
108+
Volumes = {
109+
"/var/lib/aws-cost-exporter" = { };
110+
};
93111
};
94-
};
95-
};
96-
112+
});
97113

98-
helmChart = { pkgs, aws-cost-exporter-dockerImage, kubernetes-helm, skopeo, jq, gnused }: pkgs.runCommand "aws-cost-exporter-chart-${chartVersion}.tgz"
114+
helmChart = { pkgs, aws-cost-exporter-dockerImage, kubernetes-helm, jq, gnused }: pkgs.runCommand "aws-cost-exporter-chart-${chartVersion}.tgz"
99115
{
100116
src = src-chart;
101-
buildInputs = [ kubernetes-helm skopeo jq gnused ];
117+
buildInputs = [ kubernetes-helm jq gnused ];
102118
} ''
103119
cp -r $src ./chart
104120
chmod -R a+w ./chart
@@ -108,7 +124,8 @@
108124
-e 's/^appVersion: "0\.0\.0"$/appVersion: "${version}"/' \
109125
./chart/Chart.yaml
110126
111-
digest=$(skopeo --tmpdir=. inspect docker-archive:${aws-cost-exporter-dockerImage} | jq -r '.Digest')
127+
digest="sha256:$(sha256sum "${aws-cost-exporter-dockerImage}/manifest.json" | cut -d' ' -f1)"
128+
echo "Digest: $digest"
112129
113130
sed -i \
114131
-e 's|^image:.*$|image: "${dockerPackageTag}@'$digest'"|' \

0 commit comments

Comments
 (0)