Skip to content

Commit 033d83d

Browse files
authored
Merge pull request #13 from mickamy/feat/apple-silicon
ci: try layer caching again
2 parents be6ffe3 + 7ab5cc1 commit 033d83d

File tree

12 files changed

+111
-73
lines changed

12 files changed

+111
-73
lines changed

.github/workflows/benchmark.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,16 @@ jobs:
3535
sed -i 's/ishocon2-bench/${{ env.UNAME }}\/ishocon2-bench/g' ./docker-compose.yml
3636
sed -i 's/ishocon2-app-${{ env.ISHOCON_APP_LANG }}/${{ env.UNAME }}\/ishocon2-app-${{ env.ISHOCON_APP_LANG }}/g' ./docker-compose.yml
3737
cat ./docker-compose.yml
38-
- name: Pull docker images
39-
run: make pull
40-
- run: make build
41-
timeout-minutes: 10
38+
- name: Login to Docker Hub
39+
uses: docker/login-action@v3
40+
with:
41+
username: ${{ env.UNAME }}
42+
password: ${{ secrets.DOCKER_HUB_TOKEN }}
43+
- name: Build images
44+
run: |
45+
make pull || true
46+
make build
47+
timeout-minutes: 20
4248
- run: make up bench-with-db-init
4349
timeout-minutes: 10
4450
- name: Dump docker logs

.github/workflows/build_and_push_images.yml

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,55 @@ jobs:
1616
runs-on: ubuntu-latest
1717
timeout-minutes: 60
1818
env:
19-
ISHOCON_APP_LANG: ${{ matrix.language }}
2019
UNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
2120
steps:
21+
- run: echo "DATE=$(date +%Y%m%d)" >> $GITHUB_ENV
2222
- uses: actions/checkout@v4
23+
- name: Set up QEMU
24+
uses: docker/setup-qemu-action@v3
2325
- name: Set up Docker Buildx
2426
uses: docker/setup-buildx-action@v3
2527
- name: Login to Docker Hub
2628
uses: docker/login-action@v3
2729
with:
2830
username: ${{ env.UNAME }}
2931
password: ${{ secrets.DOCKER_HUB_TOKEN }}
32+
- name: Cache docker layers
33+
uses: actions/cache@v3
34+
with:
35+
path: /tmp/.buildx-cache
36+
key: ${{ runner.os }}-buildx-${{ github.sha }}
37+
restore-keys: |
38+
${{ runner.os }}-buildx-
3039
- name: Build and push bench image
3140
uses: docker/build-push-action@v5
3241
with:
3342
context: .
3443
push: true
3544
file: ./docker/benchmarker/Dockerfile
36-
tags: ${{ env.UNAME }}/ishocon2-bench:latest
37-
cache-from: type=gha
38-
cache-to: type=gha,mode=max
45+
tags: ${{ env.UNAME }}/ishocon2-bench:latest,${{ env.UNAME }}/ishocon2-bench:${{ env.DATE }}
46+
cache-from: type=local,src=/tmp/.buildx-cache
47+
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
3948
platforms: linux/amd64,linux/arm64/v8
4049
- name: Build and push base image
4150
uses: docker/build-push-action@v5
4251
with:
4352
context: .
4453
push: true
4554
file: ./docker/app/base/Dockerfile
46-
tags: ${{ env.UNAME }}/ishocon2-app-base:latest
47-
cache-from: type=gha
48-
cache-to: type=gha,mode=max
55+
tags: ${{ env.UNAME }}/ishocon2-app-base:latest,${{ env.UNAME }}/ishocon2-app-base:${{ env.DATE }}
56+
cache-from: type=local,src=/tmp/.buildx-cache
57+
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
4958
platforms: linux/amd64,linux/arm64/v8
59+
- name: Move new cache to the place where to be cached
60+
run: |
61+
echo "Temporary fix for cleaning up old cache."
62+
echo "See isssues:
63+
- https://github.com/docker/build-push-action/issues/252
64+
- https://github.com/moby/buildkit/issues/1896
65+
"
66+
rm -rf /tmp/.buildx-cache
67+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
5068
build-app-images:
5169
name: Build app images
5270
runs-on: ubuntu-latest
@@ -66,21 +84,42 @@ jobs:
6684
ISHOCON_APP_LANG: ${{ matrix.language }}
6785
UNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
6886
steps:
87+
- run: echo "DATE=$(date +%Y%m%d)" >> $GITHUB_ENV
6988
- uses: actions/checkout@v4
89+
- name: Set up QEMU
90+
uses: docker/setup-qemu-action@v3
7091
- name: Set up Docker Buildx
7192
uses: docker/setup-buildx-action@v3
7293
- name: Login to Docker Hub
7394
uses: docker/login-action@v3
7495
with:
7596
username: ${{ env.UNAME }}
7697
password: ${{ secrets.DOCKER_HUB_TOKEN }}
98+
- name: Cache docker layers
99+
uses: actions/cache@v3
100+
with:
101+
path: /tmp/.buildx-cache
102+
key: ${{ runner.os }}-buildx-${{ matrix.language }}-${{ github.sha }}
103+
restore-keys: |
104+
${{ runner.os }}-buildx-${{ matrix.language }}
105+
${{ runner.os }}-buildx
77106
- name: Build and push app image
78107
uses: docker/build-push-action@v5
79108
with:
80109
context: .
81110
push: true
82-
file: ./docker/app/base/Dockerfile
83-
tags: ${{ env.UNAME }}/ishocon2-app-${{ env.ISHOCON_APP_LANG }}:latest
84-
cache-from: type=gha
85-
cache-to: type=gha,mode=max
111+
file: ./docker/app/${{ env.ISHOCON_APP_LANG }}/Dockerfile
112+
tags: ${{ env.UNAME }}/ishocon2-app-${{ env.ISHOCON_APP_LANG }}:latest,${{ env.UNAME }}/ishocon2-app-${{ env.ISHOCON_APP_LANG }}:${{ env.DATE }}
113+
build-args: BASE_IMAGE=${{ env.UNAME }}/ishocon2-app-base:latest
114+
cache-from: type=local,src=/tmp/.buildx-cache
115+
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
86116
platforms: linux/amd64,linux/arm64/v8
117+
- name: Move new cache to the place where to be cached
118+
run: |
119+
echo "Temporary fix for cleaning up old cache."
120+
echo "See isssues:
121+
- https://github.com/docker/build-push-action/issues/252
122+
- https://github.com/moby/buildkit/issues/1896
123+
"
124+
rm -rf /tmp/.buildx-cache
125+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,5 @@ __pycache__/
4747

4848
# go
4949
/webapp/go/webapp
50+
51+
.secret

Makefile

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,20 @@ ifeq ($(ARCH),)
77
ARCH = $(shell uname -m)
88
endif
99

10-
UBUNTU_VERSION = 18.04
11-
12-
ifeq ($(ARCH), x86_64)
13-
BASE_IMAGE = amd64/ubuntu:$(UBUNTU_VERSION)
14-
else ifeq ($(ARCH), arm64)
15-
BASE_IMAGE = arm64v8/ubuntu:$(UBUNTU_VERSION)
16-
else ifeq ($(ARCH), aarch64)
17-
BASE_IMAGE = arm64v8/ubuntu:$(UBUNTU_VERSION)
18-
else
19-
BASE_IMAGE = ubuntu:$(UBUNTU_VERSION)
20-
endif
21-
2210
LOCAL_ISHOCON_BASE_IMAGE = ishocon2-app-base:latest
2311

2412
build-base:
2513
docker build \
26-
--build-arg BASE_IMAGE=$(BASE_IMAGE) \
2714
-f ./docker/app/base/Dockerfile \
2815
-t $(LOCAL_ISHOCON_BASE_IMAGE) \
2916
-t $(UNAME)/ishocon2-app-base:latest \
30-
-t $(UNAME)/ishocon2-app-base:${ARCH} \
3117
.;
3218

3319
build-bench:
3420
docker build \
35-
--build-arg BASE_IMAGE=$(BASE_IMAGE) \
3621
-f ./docker/benchmarker/Dockerfile \
3722
-t ishocon2-bench:latest \
3823
-t $(UNAME)/ishocon2-bench:latest \
39-
-t $(UNAME)/ishocon2-bench:${ARCH} \
4024
.;
4125

4226
build-app: change-lang build-base
@@ -46,16 +30,25 @@ build-app: change-lang build-base
4630
-f ./docker/app/$(ISHOCON_APP_LANG)/Dockerfile \
4731
-t ishocon2-app-$(ISHOCON_APP_LANG):latest \
4832
-t $(UNAME)/ishocon2-app-$(ISHOCON_APP_LANG):latest \
49-
-t $(UNAME)/ishocon2-app-$(ISHOCON_APP_LANG):${ARCH} \
5033
.;
5134

5235
build: build-bench build-app
5336
@echo "Build done."
5437

55-
pull:
38+
pull-bench:
5639
docker pull $(UNAME)/ishocon2-bench:latest;
40+
docker tag $(UNAME)/ishocon2-bench:latest ishocon2-bench:latest;
41+
42+
pull-base:
5743
docker pull $(UNAME)/ishocon2-app-base:latest;
44+
docker tag $(UNAME)/ishocon2-app-base:latest $(LOCAL_ISHOCON_BASE_IMAGE);
45+
46+
pull-app: check-lang
5847
docker pull $(UNAME)/ishocon2-app-$(ISHOCON_APP_LANG):latest;
48+
docker tag $(UNAME)/ishocon2-app-$(ISHOCON_APP_LANG):latest ishocon2-app-$(ISHOCON_APP_LANG):latest;
49+
50+
pull: pull-bench pull-base pull-app
51+
@echo "Pull done."
5952

6053
push:
6154
docker push $(UNAME)/ishocon2-bench:latest;

docker/app/base/Dockerfile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
ARG BASE_IMAGE=ubuntu:18.04
2-
FROM ${BASE_IMAGE}
1+
FROM ubuntu:18.04
32

4-
ENV LANG en_US.UTF-8
5-
ENV LC_ALL=C.UTF-8
6-
ENV TZ Asia/Tokyo
3+
4+
ENV LANG=en_US.UTF-8 \
5+
LC_ALL=C.UTF-8 \
6+
TZ=Asia/Tokyo
77
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
88

99
RUN apt-get update && \
10-
apt-get install -y wget sudo less vim tzdata \
11-
nginx \
10+
apt-get install -y sudo wget less vim tzdata nginx \
1211
# 各言語のインストールに必要なもの下準備 \
13-
curl git gcc make libssl-dev libreadline-dev
12+
curl git gcc make libssl-dev libreadline-dev && \
13+
apt-get clean
1414

1515
# ishocon ユーザ作成
1616
RUN groupadd -g 1001 ishocon && \

docker/app/crystal/Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ARG BASE_IMAGE=showwin/ishocon2_app_base:latest
1+
ARG BASE_IMAGE=ishocon2-app-base:latest
22
FROM ${BASE_IMAGE}
33

44
RUN sudo apt update && \
@@ -11,7 +11,8 @@ RUN curl -fsSL https://packagecloud.io/84codes/crystal/gpgkey | gpg --dearmor |
1111
. /etc/os-release && \
1212
echo "deb https://packagecloud.io/84codes/crystal/$ID $VERSION_CODENAME main" | sudo tee /etc/apt/sources.list.d/84codes_crystal.list && \
1313
sudo apt-get update && \
14-
sudo apt-get install -y crystal
14+
sudo apt-get install -y crystal && \
15+
sudo apt-get clean
1516

1617
# アプリケーション
1718
COPY --chown=ishocon:ishocon webapp/ /home/ishocon/webapp

docker/app/go/Dockerfile

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
ARG BASE_IMAGE=showwin/ishocon2_app_base:latest
1+
ARG BASE_IMAGE=ishocon2-app-base:latest
22
FROM ${BASE_IMAGE}
33

4-
# Go のインストール
5-
ARG TARGETARCH
6-
ENV GOARCH ${TARGETARCH}
7-
8-
RUN sudo apt-get update
9-
104
# Go のインストール
115
ARG TARGETARCH
126
RUN sudo wget -q https://dl.google.com/go/go1.15.8.linux-${TARGETARCH}.tar.gz && \
@@ -21,7 +15,7 @@ ENV PATH $PATH:$GOROOT/bin
2115
COPY --chown=ishocon:ishocon webapp/ /home/ishocon/webapp
2216
RUN cd ~/webapp/go && \
2317
mkdir -p /tmp/go && \
24-
go build -x -o /tmp/go/webapp *.go
18+
GOARCH=${TARGETARCH} go build -x -o /tmp/go/webapp *.go
2519

2620
WORKDIR /home/ishocon
2721

docker/app/nodejs/Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
ARG BASE_IMAGE=showwin/ishocon2_app_base:latest
1+
ARG BASE_IMAGE=ishocon2-app-base:latest
22
FROM ${BASE_IMAGE}
33

44
# NodeJS のインストール
55
RUN sudo apt-get update
6-
RUN sudo apt install -y nodejs-dev node-gyp libssl1.0-dev
7-
RUN sudo apt install -y nodejs npm
6+
RUN sudo apt install -y nodejs-dev node-gyp libssl1.0-dev \
7+
nodejs npm && \
8+
sudo apt-get clean
89

910
# アプリケーション
1011
COPY --chown=ishocon:ishocon webapp/ /home/ishocon/webapp

docker/app/php/Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
ARG BASE_IMAGE=showwin/ishocon2_app_base:latest
1+
ARG BASE_IMAGE=ishocon2-app-base:latest
22
FROM ${BASE_IMAGE}
33

44
# PHP のインストール
55
RUN sudo mkdir /run/php
6-
RUN sudo apt-get update
7-
RUN sudo apt install -y php php-fpm php-mysql php-cli
6+
RUN sudo apt-get update && \
7+
sudo apt install -y php php-fpm php-mysql php-cli && \
8+
sudo apt-get clean
89

910
# アプリケーション
1011
COPY --chown=ishocon:ishocon webapp/ /home/ishocon/webapp

docker/app/python/Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
ARG BASE_IMAGE=showwin/ishocon2_app_base:latest
1+
ARG BASE_IMAGE=ishocon2-app-base:latest
22
FROM ${BASE_IMAGE}
33

44
# Python のインストール
5-
RUN sudo apt-get update
6-
RUN sudo apt-get install -y zlib1g-dev
5+
RUN sudo apt-get update && \
6+
sudo apt-get install -y zlib1g-dev && \
7+
sudo apt-get clean
78
RUN git clone https://github.com/pyenv/pyenv.git ~/.pyenv && \
89
PYENV_ROOT="$HOME/.pyenv" && PATH="$PYENV_ROOT/bin:$PATH" && \
910
eval "$(pyenv init -)" && \

docker/app/ruby/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
ARG BASE_IMAGE=showwin/ishocon2_app_base:latest
1+
ARG BASE_IMAGE=ishocon2-app-base:latest
22
FROM ${BASE_IMAGE}
33

44
# Ruby のインストール
55
RUN sudo apt-get update && \
66
sudo apt-get install -y ruby-dev libmysqlclient-dev libffi6 libffi-dev libyaml-dev bzip2 && \
7+
sudo apt-get clean && \
78
git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
89
RUN PATH="$HOME/.rbenv/bin:$PATH" && \
910
eval "$(rbenv init -)" && \

docker/benchmarker/Dockerfile

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
1-
ARG BASE_IMAGE=ubuntu:18.04
2-
FROM ${BASE_IMAGE}
1+
FROM ubuntu:18.04
32

43
ENV LANG en_US.UTF-8
54
ENV LC_ALL=C.UTF-8
65
ENV TZ Asia/Tokyo
76
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
87

9-
# MySQL のインストール
10-
RUN ["/bin/bash", "-c", "debconf-set-selections <<< 'mysql-server mysql-server/root_password password ishocon'"]
11-
RUN ["/bin/bash", "-c", "debconf-set-selections <<< 'mysql-service mysql-server/mysql-apt-config string 4'"]
12-
138
RUN apt-get update && \
14-
apt-get install -y wget mysql-server git tzdata
9+
apt-get install -y wget tzdata mysql-server && \
10+
apt-get clean
1511

1612
# Go のインストール
1713
ARG TARGETARCH
1814
RUN wget -q https://dl.google.com/go/go1.13.15.linux-${TARGETARCH}.tar.gz && \
1915
tar -C /usr/local -xzf go1.13.15.linux-${TARGETARCH}.tar.gz && \
2016
rm go1.13.15.linux-${TARGETARCH}.tar.gz
21-
ENV PATH $PATH:/usr/local/go/bin
22-
ENV GOROOT /usr/local/go
23-
ENV GOPATH $HOME/.local/go
24-
ENV PATH $PATH:$GOROOT/bin
17+
ENV PATH=$PATH:/usr/local/go/bin \
18+
GOROOT=/usr/local/go \
19+
GOPATH=$HOME/.local/go
2520

2621
# build benchmark
2722
COPY admin/benchmarker /root/admin/benchmarker
@@ -34,12 +29,16 @@ COPY admin/config/my.bench.cnf /etc/mysql/my.cnf
3429

3530
WORKDIR /root
3631

32+
# MySQL のインストール
33+
RUN ["/bin/bash", "-c", "debconf-set-selections <<< 'mysql-server mysql-server/root_password password ishocon'"]
34+
RUN ["/bin/bash", "-c", "debconf-set-selections <<< 'mysql-service mysql-server/mysql-apt-config string 4'"]
35+
3736
# 初期データ投入
3837
RUN service mysql start && \
3938
mysql -u root -pishocon -e 'CREATE DATABASE IF NOT EXISTS ishocon2;' && \
4039
mysql -u root -pishocon -e "CREATE USER IF NOT EXISTS ishocon IDENTIFIED BY 'ishocon';" && \
4140
mysql -u root -pishocon -e 'GRANT ALL ON *.* TO ishocon;' && \
42-
tar -jxvf ~/admin/ishocon2.dump.tar.bz2 -C ~/admin && mysql -u root -pishocon ishocon2 < ~/admin/ishocon2.dump && \
41+
tar -jxvf ~/admin/ishocon2.dump.tar.bz2 -C ~/admin && mysql -u root -pishocon ishocon2 < ~/admin/ishocon2.dump && \
4342
rm -rf ~/admin/ishocon2.dump
4443

4544

0 commit comments

Comments
 (0)