Skip to content

Commit 3f0b358

Browse files
committed
Add maps cache to gh actions and squash by default
1 parent 8b81a32 commit 3f0b358

6 files changed

Lines changed: 88 additions & 79 deletions

File tree

.github/workflows/docker-ci.yml

Lines changed: 76 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,41 @@ on:
1414
- develop
1515

1616
env:
17-
VERSION_NUMBER: "1.0.6"
17+
VERSION_NUMBER: "1.0.7"
1818
LATEST_PYTHON_VERSION: "3.14"
1919
LATEST_SC2_VERSION: "4.10"
2020
EXPERIMENTAL_PYTHON_VERSION: "3.15"
2121

2222
jobs:
23+
download_sc2_maps:
24+
name: Download and cache sc2 maps
25+
runs-on: ${{ matrix.os }}
26+
timeout-minutes: 15
27+
strategy:
28+
fail-fast: false
29+
matrix:
30+
os: [ubuntu-latest]
31+
32+
steps:
33+
- uses: actions/checkout@v3
34+
35+
- name: Cache sc2 maps
36+
uses: actions/cache@v4
37+
id: cache-sc2-maps
38+
with:
39+
path: |
40+
dockerfiles/maps
41+
key: ${{ runner.os }}-maps-${{ hashFiles('dockerfiles/maps/**') }}
42+
restore-keys: |
43+
${{ runner.os }}-maps-
44+
45+
- name: Download sc2 maps
46+
run: sh dockerfiles/download_maps.sh
47+
if: steps.cache-sc2-maps.outputs.cache-hit != 'true'
48+
2349
run_test_docker_image:
2450
name: Run test_docker_image.sh
51+
needs: [download_sc2_maps]
2552
runs-on: ${{ matrix.os }}
2653
timeout-minutes: 30
2754
strategy:
@@ -32,6 +59,20 @@ jobs:
3259
steps:
3360
- uses: actions/checkout@v3
3461

62+
- name: Cache sc2 maps
63+
uses: actions/cache@v4
64+
id: cache-sc2-maps
65+
with:
66+
path: |
67+
dockerfiles/maps
68+
key: ${{ runner.os }}-maps-${{ hashFiles('dockerfiles/maps/**') }}
69+
restore-keys: |
70+
${{ runner.os }}-maps-
71+
72+
- name: Download sc2 maps
73+
run: sh dockerfiles/download_maps.sh
74+
if: steps.cache-sc2-maps.outputs.cache-hit != 'true'
75+
3576
- name: Enable experimental docker features
3677
run: |
3778
echo $'{\n "experimental": true\n}' | sudo tee /etc/docker/daemon.json
@@ -46,6 +87,7 @@ jobs:
4687

4788
run_test_new_python_version:
4889
name: Run test_new_python_candidate.sh
90+
needs: [download_sc2_maps]
4991
runs-on: ${{ matrix.os }}
5092
timeout-minutes: 30
5193
strategy:
@@ -56,6 +98,20 @@ jobs:
5698
steps:
5799
- uses: actions/checkout@v3
58100

101+
- name: Cache sc2 maps
102+
uses: actions/cache@v4
103+
id: cache-sc2-maps
104+
with:
105+
path: |
106+
dockerfiles/maps
107+
key: ${{ runner.os }}-maps-${{ hashFiles('dockerfiles/maps/**') }}
108+
restore-keys: |
109+
${{ runner.os }}-maps-
110+
111+
- name: Download sc2 maps
112+
run: sh dockerfiles/download_maps.sh
113+
if: steps.cache-sc2-maps.outputs.cache-hit != 'true'
114+
59115
- name: Enable experimental docker features
60116
run: |
61117
echo $'{\n "experimental": true\n}' | sudo tee /etc/docker/daemon.json
@@ -71,6 +127,7 @@ jobs:
71127

72128
docker_build:
73129
name: Build docker image
130+
needs: [download_sc2_maps]
74131
runs-on: ${{ matrix.os }}
75132
timeout-minutes: 30
76133
strategy:
@@ -86,26 +143,31 @@ jobs:
86143
steps:
87144
- uses: actions/checkout@v3
88145

89-
- name: Build docker image
90-
run: docker build -t $IMAGE_NAME-v$VERSION_NUMBER $BUILD_ARGS - < dockerfiles/Dockerfile
146+
- name: Cache sc2 maps
147+
uses: actions/cache@v4
148+
id: cache-sc2-maps
149+
with:
150+
path: |
151+
dockerfiles/maps
152+
key: ${{ runner.os }}-maps-${{ hashFiles('dockerfiles/maps/**') }}
153+
restore-keys: |
154+
${{ runner.os }}-maps-
91155
92-
- name: Enable experimental docker features
93-
run: |
94-
echo $'{\n "experimental": true\n}' | sudo tee /etc/docker/daemon.json
95-
sudo systemctl restart docker.service
156+
- name: Download sc2 maps
157+
run: sh dockerfiles/download_maps.sh
158+
if: steps.cache-sc2-maps.outputs.cache-hit != 'true'
96159

97-
- name: Build squashed image
98-
run: docker build -t $IMAGE_NAME-v$VERSION_NUMBER-squashed --squash $BUILD_ARGS - < dockerfiles/Dockerfile
160+
- name: Build docker image
161+
run: docker build -f dockerfiles/Dockerfile -t $IMAGE_NAME-v$VERSION_NUMBER $BUILD_ARGS .
99162

100-
- name: Run test bots on squashed image
101-
if: matrix.python-version != '3.7'
163+
- name: Run test bots on image
102164
run: |
103165
echo "Start container, override the default entrypoint"
104166
docker run -i -d \
105167
--name test_container \
106168
--env 'PYTHONPATH=/root/python-sc2/' \
107169
--entrypoint /bin/bash \
108-
$IMAGE_NAME-v$VERSION_NUMBER-squashed
170+
$IMAGE_NAME-v$VERSION_NUMBER
109171
echo "Install python-sc2"
110172
docker exec -i test_container mkdir -p /root/python-sc2
111173
docker cp pyproject.toml test_container:/root/python-sc2/
@@ -131,12 +193,8 @@ jobs:
131193
if: github.ref == 'refs/heads/develop' && github.event_name == 'push'
132194
run: docker push $IMAGE_NAME-v$VERSION_NUMBER
133195

134-
- name: Upload squashed docker image
135-
if: github.ref == 'refs/heads/develop' && github.event_name == 'push'
136-
run: docker push $IMAGE_NAME-v$VERSION_NUMBER-squashed
137-
138-
- name: Upload squashed docker image as latest tag
196+
- name: Upload docker image as latest tag
139197
if: github.ref == 'refs/heads/develop' && github.event_name == 'push' && matrix.python-version == env.LATEST_PYTHON_VERSION && matrix.sc2-version == env.LATEST_SC2_VERSION
140198
run: |
141-
docker tag $IMAGE_NAME-v$VERSION_NUMBER-squashed burnysc2/python-sc2-docker:latest
199+
docker tag $IMAGE_NAME-v$VERSION_NUMBER burnysc2/python-sc2-docker:latest
142200
docker push burnysc2/python-sc2-docker:latest

dockerfiles/Dockerfile

Lines changed: 7 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
ARG PYTHON_VERSION=3.10
33

44
# https://docs.astral.sh/uv/guides/integration/docker/#available-images
5-
FROM ghcr.io/astral-sh/uv:python$PYTHON_VERSION-bookworm-slim
5+
FROM ghcr.io/astral-sh/uv:python$PYTHON_VERSION-bookworm-slim AS base
66

77
ARG SC2_VERSION=4.10
88

@@ -37,7 +37,7 @@ WORKDIR /root/
3737
# Download and uncompress StarCraftII from https://github.com/Blizzard/s2client-proto#linux-packages and remove zip file
3838
# If file is locally available, use this instead:
3939
#COPY SC2.4.10.zip /root/
40-
RUN curl --retry 3 --retry-delay 5 -C - http://blzdistsc2-a.akamaihd.net/Linux/SC2.$SC2_VERSION.zip -o "SC2.$SC2_VERSION.zip" \
40+
RUN curl --retry 5 --retry-delay 5 -C - http://blzdistsc2-a.akamaihd.net/Linux/SC2.$SC2_VERSION.zip -o "SC2.$SC2_VERSION.zip" \
4141
&& unzip -q -P iagreetotheeula "SC2.$SC2_VERSION.zip" \
4242
&& rm SC2.$SC2_VERSION.zip
4343

@@ -51,51 +51,13 @@ RUN ln -s /root/StarCraftII/Maps /root/StarCraftII/maps \
5151
# Remove the Maps that come with the SC2 client
5252
&& rm -rf /root/StarCraftII/maps/*
5353

54-
# Change to maps folder
55-
WORKDIR /root/StarCraftII/maps/
56-
57-
# Maps are available here https://github.com/Blizzard/s2client-proto#map-packs and here https://sc2ai.net/wiki/maps/
58-
# Download and uncompress StarCraftII Maps, remove zip file - using "maps" instead of "Maps" as target folder
59-
60-
# Get sc2ai.net ladder maps
61-
# -L param follows links https://stackoverflow.com/a/2663023/10882657
62-
RUN curl -L https://sc2ai.net/wiki/184/plugin/attachments/download/9/ -o 1.zip \
63-
&& curl -L https://sc2ai.net/wiki/184/plugin/attachments/download/14/ -o 2.zip \
64-
&& curl -L https://sc2ai.net/wiki/184/plugin/attachments/download/21/ -o 3.zip \
65-
&& curl -L https://sc2ai.net/wiki/184/plugin/attachments/download/35/ -o 4.zip \
66-
&& curl -L https://sc2ai.net/wiki/184/plugin/attachments/download/36/ -o 5.zip \
67-
&& curl -L https://sc2ai.net/wiki/184/plugin/attachments/download/38/ -o 6.zip \
68-
&& curl -L https://sc2ai.net/wiki/184/plugin/attachments/download/39/ -o 7.zip \
69-
&& unzip -q -o '*.zip' \
70-
&& rm *.zip
71-
72-
# Get official blizzard maps
73-
RUN curl --retry 3 --retry-delay 5 -C - http://blzdistsc2-a.akamaihd.net/MapPacks/Ladder2019Season3.zip -o 'Ladder2019Season3.zip' \
74-
&& unzip -q -P iagreetotheeula -o 'Ladder2019Season3.zip' \
75-
&& mv Ladder2019Season3/* . \
76-
&& rm Ladder2019Season3.zip \
77-
&& rm -r Ladder2019Season3
78-
79-
# Get v5.0.6 maps
80-
RUN curl -L https://github.com/shostyn/sc2patch/raw/4987d4915b47c801adbc05e297abaa9ca2988838/Maps/506.zip -o 506.zip \
81-
&& unzip -q -o '506.zip' \
82-
&& rm 506.zip
83-
84-
# Get flat and empty maps
85-
RUN curl --retry 3 --retry-delay 5 -C - http://blzdistsc2-a.akamaihd.net/MapPacks/Melee.zip -o Melee.zip \
86-
&& unzip -q -P iagreetotheeula -o 'Melee.zip' \
87-
&& mv Melee/* . \
88-
&& rm Melee.zip \
89-
&& rm -r Melee
90-
91-
# Remove LE suffix from file names
92-
RUN rename -v 's/LE.SC2Map/.SC2Map/' *.SC2Map
93-
94-
# List all map files
95-
RUN tree
54+
# See download_maps.sh
55+
COPY dockerfiles/maps/* /root/StarCraftII/maps/
9656

57+
# Squash image with trick https://stackoverflow.com/a/56118557/10882657
58+
FROM scratch
59+
COPY --from=base / /
9760
WORKDIR /root/
98-
9961
ENTRYPOINT [ "/bin/bash" ]
10062

10163
# To run a python-sc2 bot:

dockerfiles/test_docker_image.sh

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,9 @@ export SC2_VERSION=${SC2_VERSION:-4.10}
1414
IMAGE_NAME=burnysc2/python-sc2-docker:py_$PYTHON_VERSION-sc2_$SC2_VERSION-v$VERSION_NUMBER
1515
BUILD_ARGS="--build-arg PYTHON_VERSION=$PYTHON_VERSION --build-arg SC2_VERSION=$SC2_VERSION"
1616

17-
# Allow image squashing by enabling experimental docker features
18-
# https://stackoverflow.com/a/21164441/10882657
19-
# https://github.com/actions/virtual-environments/issues/368#issuecomment-582387669
20-
# file=/etc/docker/daemon.json
21-
# if [ ! -e "$file" ]; then
22-
# echo $'{\n "experimental": true\n}' | sudo tee /etc/docker/daemon.json
23-
# sudo systemctl restart docker.service
24-
# fi
25-
2617
# Build image without context
2718
# https://stackoverflow.com/a/54666214/10882657
28-
docker build -t $IMAGE_NAME $BUILD_ARGS - < dockerfiles/Dockerfile
29-
# Build squashed image where the layers are combined to one
30-
#docker build -t $IMAGE_NAME-squashed --squash $BUILD_ARGS - < dockerfiles/Dockerfile
19+
docker build -f dockerfiles/Dockerfile -t $IMAGE_NAME $BUILD_ARGS .
3120

3221
# Delete previous container if it exists
3322
docker rm -f test_container

dockerfiles/test_new_python_candidate.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ IMAGE_NAME=burnysc2/python-sc2-docker:py_$PYTHON_VERSION-sc2_$SC2_VERSION-v$VERS
1616
BUILD_ARGS="--build-arg PYTHON_VERSION=$PYTHON_VERSION --build-arg SC2_VERSION=$SC2_VERSION"
1717

1818
# Build image
19-
docker build -t $IMAGE_NAME $BUILD_ARGS - < dockerfiles/Dockerfile
19+
docker build -f dockerfiles/Dockerfile -t $IMAGE_NAME $BUILD_ARGS .
2020

2121
# Delete previous container if it exists
2222
docker rm -f test_container

test/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Buildable via command from root folder
2-
# docker build -t test_image -f test/Dockerfile --build-arg PYTHON_VERSION=3.10 --build-arg SC2_VERSION=4.10 .
2+
# docker build -f test/Dockerfile -t test_image --build-arg PYTHON_VERSION=3.10 --build-arg SC2_VERSION=4.10 .
33

44
# For more info see https://github.com/BurnySc2/python-sc2-docker
55
ARG PYTHON_VERSION=3.10
66
ARG SC2_VERSION=4.10
77
ARG VERSION_NUMBER=1.0.0
88

9-
FROM burnysc2/python-sc2-docker:py_$PYTHON_VERSION-sc2_$SC2_VERSION-v$VERSION_NUMBER-squashed
9+
FROM burnysc2/python-sc2-docker:py_$PYTHON_VERSION-sc2_$SC2_VERSION-v$VERSION_NUMBER
1010

1111
# Debugging purposes
1212
RUN echo $PYTHON_VERSION

test/travis_test_script.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
Usage:
66
cd into python-sc2/ directory
7-
docker build -t test_image -f test/Dockerfile .
7+
docker build -f test/Dockerfile -t test_image .
88
docker run test_image -c "python test/travis_test_script.py test/autotest_bot.py"
99
1010
Or if you want to run from windows:

0 commit comments

Comments
 (0)