Skip to content

Commit f900088

Browse files
committed
Implement a Cassandra tarball cache
This patch adds a GitHub Actions cache for storing Cassandra tarball downloads.
1 parent caf2db3 commit f900088

File tree

4 files changed

+83
-9
lines changed

4 files changed

+83
-9
lines changed

.github/workflows/ci.yaml

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,62 @@ jobs:
7272
with:
7373
path: /home/runner/work/management-api-for-apache-cassandra/management-api-for-apache-cassandra/management-api-server/.cassandra-bin
7474
key: cassandra-download-${{ github.sha }}
75-
75+
76+
cassandra-tarball-cache:
77+
name: Setup Cassandra tarball cache
78+
runs-on: ubuntu-latest
79+
needs: run-unit-tests
80+
outputs:
81+
cassandraversion: ${{ steps.extract-cass-version.outputs.cassandraversion }}
82+
strategy:
83+
fail-fast: false
84+
max-parallel: 4
85+
matrix:
86+
cassandra-version: ['4.0', '4.1', '5.0']
87+
base-platform: ['ubi']
88+
steps:
89+
- name: Checkout repo
90+
uses: actions/checkout@v3
91+
- name: Restore build workspace
92+
uses: actions/cache/restore@v4
93+
with:
94+
path: /home/runner/work/management-api-for-apache-cassandra/management-api-for-apache-cassandra
95+
key: ${{ runner.os }}-workspace-${{ github.sha }}-${{ hashFiles('**/pom.xml') }}
96+
- name: Extract Version from Dockerfile
97+
id: extract-cass-version
98+
run: |
99+
CASSVER=$(grep -E '^ARG[[:space:]]+CASSANDRA_VERSION=' cassandra/Dockerfile-${{ matrix.cassandra-version }}.${{ matrix.base-platform }} | sed 's/^ARG[[:space:]]\+CASSANDRA_VERSION=//')
100+
echo "CASSANDRA_VERSION=$CASSVER" >> $GITHUB_ENV
101+
echo "cassandraversion=$CASSVER" >> $GITHUB_OUTPUT
102+
- name: Create Cassandra tarball cache directory
103+
run: |
104+
mkdir -p /home/runner/cassandra-tarball-cache
105+
- name: Restore Cassandra tarball cache
106+
uses: actions/cache/restore@v4
107+
with:
108+
path: /home/runner/cassandra-tarball-cache
109+
key: cassandra-tarball-cache-${{ matrix.cassandra-version }}
110+
- name: Download Cassandra Tarball ${{ matrix.cassandra-version }}
111+
run: |
112+
echo "Checking for Cassandra tarball version: $CASSANDRA_VERSION"
113+
TARBALL="/home/runner/cassandra-tarball-cache/apache-cassandra-${CASSANDRA_VERSION}-bin.tar.gz"
114+
if [ ! -f "$TARBALL" ]; then
115+
echo "Cassandra tarball not present. Downloading tarball: $TARBALL"
116+
curl -L "https://archive.apache.org/dist/cassandra/${CASSANDRA_VERSION}/apache-cassandra-${CASSANDRA_VERSION}-bin.tar.gz" -o "$TARBALL"
117+
else
118+
echo "Cassandra tarball already present in cache: $TARBALL"
119+
ls -l "$TARBALL"
120+
fi
121+
- name: Save Cassandra ${{ matrix.cassandra-version }} tarball cache
122+
uses: actions/cache/save@v4
123+
with:
124+
path: /home/runner/cassandra-tarball-cache
125+
key: cassandra-tarball-cache-${{ matrix.cassandra-version }}
76126

77127
build-oss-docker-images:
78128
name: Build Cassandra images
79129
runs-on: ubuntu-latest
80-
needs: run-unit-tests
130+
needs: cassandra-tarball-cache
81131
strategy:
82132
fail-fast: false
83133
max-parallel: 8
@@ -93,6 +143,18 @@ jobs:
93143
with:
94144
path: /home/runner/work/management-api-for-apache-cassandra/management-api-for-apache-cassandra
95145
key: ${{ runner.os }}-workspace-${{ github.sha }}-${{ hashFiles('**/pom.xml') }}
146+
- name: Restore Cassandra tarball cache
147+
if: ${{ matrix.base-platform == 'ubi' }}
148+
uses: actions/cache/restore@v4
149+
with:
150+
path: /home/runner/cassandra-tarball-cache
151+
key: cassandra-tarball-cache-${{ matrix.cassandra-version }}
152+
- name: Copy Cassandra tarball
153+
if: ${{ matrix.base-platform == 'ubi' }}
154+
run: |
155+
echo "Copying Cassandra ${{ needs.cassandra-tarball-cache.outputs.cassandraversion }} tarball"
156+
cp /home/runner/cassandra-tarball-cache/apache-cassandra-${{ needs.cassandra-tarball-cache.outputs.cassandraversion }}-bin.tar.gz \
157+
/home/runner/work/management-api-for-apache-cassandra/management-api-for-apache-cassandra/
96158
- name: Set up JDK 11
97159
uses: actions/setup-java@v4
98160
with:
@@ -131,7 +193,7 @@ jobs:
131193
target: cassandra
132194
outputs: type=docker,dest=/tmp/cassandra.${{ matrix.cassandra-version }}.${{ matrix.base-platform }}.tar
133195
- name: Build Cassandra ${{ matrix.cassandra-version }}-${{ matrix.base-platform }}
134-
if: ${{ matrix.base-platform != 'ubuntu' }}
196+
if: ${{ matrix.base-platform == 'ubi' }}
135197
id: docker_build_ubi
136198
uses: docker/build-push-action@v5
137199
with:

cassandra/Dockerfile-4.0.ubi

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,13 @@ RUN mkdir -m 775 ${CDC_AGENT_PATH} && \
4242
chmod -R g+w ${CDC_AGENT_PATH}
4343

4444
###
45-
# Download Cassandra archive
45+
# Coppy Cassandra archive
46+
# NOTE: For local builds, you will need to download the archive from
47+
# https://archive.apache.org/dist/cassandra/${CASSANDRA_VERSION}/apache-cassandra-${CASSANDRA_VERSION}-bin.tar.gz
48+
# NOTE: For GitHub Actions, the build jobs should cache the versions and only
49+
# download from the archives if the tarball isn't cached already.
4650
###
47-
ADD "https://archive.apache.org/dist/cassandra/${CASSANDRA_VERSION}/apache-cassandra-${CASSANDRA_VERSION}-bin.tar.gz" ./
51+
COPY apache-cassandra-${CASSANDRA_VERSION}-bin.tar.gz ./
4852
RUN tar --directory ${CASSANDRA_HOME} --strip-components 1 --extract --gzip --file apache-cassandra-${CASSANDRA_VERSION}-bin.tar.gz && \
4953
chown -R cassandra:root ${CASSANDRA_HOME} && \
5054
chmod -R a+rwX ${CASSANDRA_HOME}

cassandra/Dockerfile-4.1.ubi

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,13 @@ RUN mkdir -m 775 ${CDC_AGENT_PATH} && \
4343
chmod -R g+w ${CDC_AGENT_PATH}
4444

4545
###
46-
# Download Cassandra archive
46+
# Coppy Cassandra archive
47+
# NOTE: For local builds, you will need to download the archive from
48+
# https://archive.apache.org/dist/cassandra/${CASSANDRA_VERSION}/apache-cassandra-${CASSANDRA_VERSION}-bin.tar.gz
49+
# NOTE: For GitHub Actions, the build jobs should cache the versions and only
50+
# download from the archives if the tarball isn't cached already.
4751
###
48-
ADD "https://archive.apache.org/dist/cassandra/${CASSANDRA_VERSION}/apache-cassandra-${CASSANDRA_VERSION}-bin.tar.gz" ./
52+
COPY apache-cassandra-${CASSANDRA_VERSION}-bin.tar.gz ./
4953
RUN tar --directory ${CASSANDRA_HOME} --strip-components 1 --extract --gzip --file apache-cassandra-${CASSANDRA_VERSION}-bin.tar.gz && \
5054
chown -R cassandra:root ${CASSANDRA_HOME} && \
5155
chmod -R a+rwX ${CASSANDRA_HOME}

cassandra/Dockerfile-5.0.ubi

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,13 @@ RUN mkdir -m 775 ${CDC_AGENT_PATH} && \
3232
chmod -R g+w ${CDC_AGENT_PATH}
3333

3434
###
35-
# Download Cassandra archive
35+
# Coppy Cassandra archive
36+
# NOTE: For local builds, you will need to download the archive from
37+
# https://archive.apache.org/dist/cassandra/${CASSANDRA_VERSION}/apache-cassandra-${CASSANDRA_VERSION}-bin.tar.gz
38+
# NOTE: For GitHub Actions, the build jobs should cache the versions and only
39+
# download from the archives if the tarball isn't cached already.
3640
###
37-
ADD "https://archive.apache.org/dist/cassandra/${CASSANDRA_VERSION}/apache-cassandra-${CASSANDRA_VERSION}-bin.tar.gz" ./
41+
COPY apache-cassandra-${CASSANDRA_VERSION}-bin.tar.gz ./
3842
RUN tar --directory ${CASSANDRA_HOME} --strip-components 1 --extract --gzip --file apache-cassandra-${CASSANDRA_VERSION}-bin.tar.gz && \
3943
chown -R cassandra:root ${CASSANDRA_HOME} && \
4044
chmod -R a+rwX ${CASSANDRA_HOME}

0 commit comments

Comments
 (0)