Skip to content

Commit 77f6bec

Browse files
committed
Build docker for release and features
1 parent b530dee commit 77f6bec

File tree

3 files changed

+119
-2
lines changed

3 files changed

+119
-2
lines changed

.github/workflows/docker.yaml renamed to .github/workflows/publish-dev-docker.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
echo "${DOCKER_REPO}:${GITHUB_SHA::8}" >> $GITHUB_ENV
4040
if [ "${GITHUB_REF}" = "refs/heads/main" ]
4141
then
42-
echo "${DOCKER_REPO}:latest" >> $GITHUB_ENV
42+
echo "${DOCKER_REPO}:dev-latest" >> $GITHUB_ENV
4343
fi
4444
echo 'EOF' >> $GITHUB_ENV
4545
echo "BUILDX_BUILDER=${{ steps.docker-builder.outputs.name }}" >> $GITHUB_ENV
@@ -67,6 +67,8 @@ jobs:
6767
type=local,dest=/tmp/buildx-cache-cross-step,mode=max
6868
tags: |
6969
${{ env.DOCKER_TAGS }}
70+
build-args: |
71+
FEATURES=contextfree
7072
- name: Update registry cache
7173
uses: docker/build-push-action@v2
7274
if: github.ref == 'refs/heads/main'
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
name: Publish Docker image for new releases
2+
3+
on:
4+
release:
5+
types:
6+
- published
7+
8+
jobs:
9+
build_and_push:
10+
name: Build and Push
11+
runs-on: ubuntu-18.04
12+
env:
13+
DOCKER_REPO: atactr/automata
14+
steps:
15+
- uses: actions/checkout@v2
16+
- name: Set up QEMU
17+
uses: docker/setup-qemu-action@v1
18+
- name: Set up Docker Buildx
19+
id: docker-builder
20+
uses: docker/setup-buildx-action@v1
21+
- name: Cache Buildx
22+
uses: actions/cache@v2
23+
id: buildx-cache
24+
with:
25+
path: /tmp/buildx-cache
26+
key: ${{ runner.os }}-buildx-${{ hashFiles('**/Cargo.lock') }}
27+
restore-keys: |
28+
${{ runner.os }}-buildx-${{ hashFiles('**/Cargo.lock') }}
29+
${{ runner.os }}-buildx-
30+
- name: Login to DockerHub
31+
uses: docker/login-action@v1
32+
with:
33+
username: ${{ secrets.DOCKERHUB_USERNAME }}
34+
password: ${{ secrets.DOCKERHUB_TOKEN }}
35+
- name: Prepare Environment Variables
36+
run: |
37+
echo "BUILDX_BUILDER=${{ steps.docker-builder.outputs.name }}" >> $GITHUB_ENV
38+
echo "BUILDX_BUILDER_CONTAINER=buildx_buildkit_${{ steps.docker-builder.outputs.name }}0" >> $GITHUB_ENV
39+
- name: Restore buildx cache
40+
# Handle cache mount in buildx
41+
# See https://github.com/docker/buildx/issues/156#issuecomment-537492942
42+
if: steps.buildx-cache.outputs.cache-hit == 'true'
43+
run: |
44+
docker buildx stop --builder "${BUILDX_BUILDER}"
45+
docker run --rm --volumes-from "${BUILDX_BUILDER_CONTAINER}" \
46+
-v /tmp/buildx-cache:/backup \
47+
alpine:3.10 /bin/sh -c "cd / && tar xf /backup/backup.tar.gz"
48+
docker buildx inspect --builder "${BUILDX_BUILDER}" --bootstrap
49+
docker buildx --builder "${BUILDX_BUILDER}" du --verbose
50+
- name: ContextFree - Build with cache and push images
51+
uses: docker/build-push-action@v2
52+
id: contextfree_docker_build
53+
with:
54+
builder: ${{ steps.docker-builder.outputs.name }}
55+
push: true
56+
cache-from: |
57+
type=registry,ref=${{ env.DOCKER_REPO }}:builder
58+
cache-to: |
59+
type=local,dest=/tmp/buildx-cache-cross-step,mode=max
60+
tags: |
61+
atactr/automata:contextfree-latest
62+
atactr/automata:contextfree-${{ github.event.release.tag_name }}
63+
build-args: |
64+
FEATURES=contextfree
65+
- name: Automata - Build with cache and push images
66+
uses: docker/build-push-action@v2
67+
id: automata_docker_build
68+
with:
69+
builder: ${{ steps.docker-builder.outputs.name }}
70+
push: true
71+
cache-from: |
72+
type=registry,ref=${{ env.DOCKER_REPO }}:builder
73+
cache-to: |
74+
type=local,dest=/tmp/buildx-cache-cross-step,mode=max
75+
tags: |
76+
atactr/automata:automata-latest
77+
atactr/automata:automata-${{ github.event.release.tag_name }}
78+
build-args: |
79+
FEATURES=automata
80+
- name: Update registry cache
81+
uses: docker/build-push-action@v2
82+
if: github.ref == 'refs/heads/main'
83+
with:
84+
builder: ${{ steps.docker-builder.outputs.name }}
85+
cache-from: |
86+
type=registry,ref=${{ env.DOCKER_REPO }}:builder
87+
type=local,src=/tmp/buildx-cache-cross-step
88+
cache-to: |
89+
type=registry,ref=${{ env.DOCKER_REPO }}:builder,mode=max
90+
- name: Backup buildx cache
91+
# Handle cache mount in buildx
92+
# See https://github.com/docker/buildx/issues/156#issuecomment-537492942
93+
env:
94+
KEEP_STORAGE: "1073741824" # this is 1GB
95+
run: |
96+
echo "Before pruning"
97+
docker buildx --builder "${BUILDX_BUILDER}" du --verbose
98+
echo "Start pruning"
99+
docker buildx --builder "${BUILDX_BUILDER}" prune --force --filter type=frontend
100+
docker buildx --builder "${BUILDX_BUILDER}" prune --force --filter type=regular
101+
docker buildx --builder "${BUILDX_BUILDER}" prune --force --filter type=source.local
102+
docker buildx --builder "${BUILDX_BUILDER}" prune --force --keep-storage ${KEEP_STORAGE}
103+
echo "After pruning"
104+
docker buildx --builder "${BUILDX_BUILDER}" du --verbose
105+
echo "Backup buildx cache"
106+
docker run --rm --volumes-from "${BUILDX_BUILDER_CONTAINER}" \
107+
-v /tmp/buildx-cache:/backup \
108+
alpine:3.10 /bin/sh -c "cd / && tar cf /backup/backup.tar.gz /var/lib/buildkit"
109+
110+
- name: ContextFree Image digest
111+
run: echo ${{ steps.contextfree_docker_build.outputs.digest }}
112+
113+
- name: Automata Image digest
114+
run: echo ${{ steps.automata_docker_build.outputs.digest }}

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ LABEL maintainer "Automata Team"
44

55
ARG PROFILE=release
66
ARG TOOLCHAIN=nightly-2021-06-16
7+
ARG FEATURES
78

89
RUN apt-get update && \
910
apt-get install -y --no-install-recommends cmake clang curl
@@ -32,7 +33,7 @@ RUN --mount=type=cache,target=/root/.cache/sccache \
3233
--mount=type=cache,target=/usr/local/cargo/registry/index \
3334
--mount=type=cache,target=/usr/local/cargo/registry/cache \
3435
--mount=type=cache,target=/usr/local/cargo/git/db \
35-
cargo build --$PROFILE --bin automata --features contextfree && \
36+
cargo build --$PROFILE --bin automata --features ${FEATURES} && \
3637
cp /automata/target/${PROFILE}/automata /usr/local/bin/automata
3738

3839
# ===== SECOND STAGE ======

0 commit comments

Comments
 (0)