Simplify Docker build in CI
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
target/
|
||||
crates/*/target
|
||||
crates/*/node_modules
|
||||
docs/
|
||||
.devcontainer/
|
||||
.git/
|
||||
.github/
|
||||
.gitignore
|
||||
Dockerfile
|
||||
.dockerignore
|
||||
docker-bake.hcl
|
||||
|
||||
17
.github/workflows/check.yaml
vendored
17
.github/workflows/check.yaml
vendored
@@ -322,7 +322,6 @@ jobs:
|
||||
bake-target: docker-metadata-action
|
||||
tags: |
|
||||
type=ref,event=branch
|
||||
type=ref,event=pr
|
||||
type=semver,pattern={{version}}
|
||||
type=semver,pattern={{major}}.{{minor}}
|
||||
type=semver,pattern={{major}}
|
||||
@@ -336,7 +335,6 @@ jobs:
|
||||
bake-target: docker-metadata-action-debug
|
||||
tags: |
|
||||
type=ref,event=branch,suffix=-debug
|
||||
type=ref,event=pr,suffix=-debug
|
||||
type=semver,pattern={{version}},suffix=-debug
|
||||
type=semver,pattern={{major}}.{{minor}},suffix=-debug
|
||||
type=semver,pattern={{major}},suffix=-debug
|
||||
@@ -353,9 +351,6 @@ jobs:
|
||||
[registry."docker.io"]
|
||||
mirrors = ["mirror.gcr.io"]
|
||||
|
||||
[worker.oci]
|
||||
max-parallelism = 2
|
||||
|
||||
- name: Login to GitHub Container Registry
|
||||
if: github.event_name != 'pull_request'
|
||||
uses: docker/login-action@v1
|
||||
@@ -364,20 +359,20 @@ jobs:
|
||||
username: ${{ github.repository_owner }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
# For pull-requests, only read from the cache, do not try to push to the
|
||||
# cache or the image itself
|
||||
- name: Build
|
||||
uses: docker/bake-action@v1
|
||||
if: github.event_name == 'pull_request'
|
||||
with:
|
||||
targets: gha
|
||||
set: |
|
||||
gha-push.cache-from=type=registry,ref=${{ env.IMAGE }}:buildcache
|
||||
base.cache-from=type=registry,ref=${{ env.IMAGE }}:buildcache
|
||||
|
||||
- name: Build and push
|
||||
uses: docker/bake-action@v1
|
||||
if: github.event_name != 'pull_request'
|
||||
with:
|
||||
targets: gha
|
||||
set: |
|
||||
gha-push.output=type=image,push=true
|
||||
gha-push.cache-from=type=registry,ref=${{ env.IMAGE }}:buildcache
|
||||
gha-push.cache-to=type=registry,ref=${{ env.IMAGE }}:buildcache,mode=max
|
||||
base.output=type=image,push=true
|
||||
base.cache-from=type=registry,ref=${{ env.IMAGE }}:buildcache
|
||||
base.cache-to=type=registry,ref=${{ env.IMAGE }}:buildcache,mode=max
|
||||
|
||||
19
Dockerfile
19
Dockerfile
@@ -104,25 +104,6 @@ RUN cargo build \
|
||||
# Move the binary to avoid having to guess its name in the next stage
|
||||
RUN mv target/$(/docker-arch-to-rust-target.sh "${TARGETPLATFORM}")/release/mas-cli /mas-cli
|
||||
|
||||
## Stage to run unit tests ##
|
||||
FROM --platform=${BUILDPLATFORM} chef AS test
|
||||
|
||||
ARG TARGETPLATFORM
|
||||
|
||||
# Build dependencies
|
||||
COPY --from=planner /app/recipe.json recipe.json
|
||||
RUN cargo chef cook \
|
||||
--recipe-path recipe.json \
|
||||
--target $(/docker-arch-to-rust-target.sh "${TARGETPLATFORM}")
|
||||
|
||||
# Run the tests
|
||||
COPY . .
|
||||
COPY --from=static-files /app/crates/static-files/public /app/crates/static-files/public
|
||||
ENV SQLX_OFFLINE=true
|
||||
RUN cargo test \
|
||||
--workspace \
|
||||
--target $(/docker-arch-to-rust-target.sh "${TARGETPLATFORM}")
|
||||
|
||||
## Runtime stage, debug variant ##
|
||||
FROM --platform=${TARGETPLATFORM} gcr.io/distroless/cc-debian${DEBIAN_VERSION}:debug-nonroot AS debug
|
||||
COPY --from=builder /mas-cli /mas-cli
|
||||
|
||||
@@ -1,55 +1,25 @@
|
||||
// Target filled by GitHub Actions, one for the regular tag, one for the debug tag
|
||||
// This is what is baked by GitHub Actions
|
||||
group "default" { targets = ["regular", "debug"] }
|
||||
|
||||
// Targets filled by GitHub Actions: one for the regular tag, one for the debug tag
|
||||
target "docker-metadata-action" {}
|
||||
target "docker-metadata-action-debug" {}
|
||||
|
||||
target "default" {
|
||||
dockerfile = "Dockerfile"
|
||||
context = "./"
|
||||
// This sets the platforms and is further extended by GitHub Actions to set the
|
||||
// output and the cache locations
|
||||
target "base" {
|
||||
platforms = [
|
||||
"linux/amd64",
|
||||
"linux/arm64",
|
||||
"linux/arm",
|
||||
]
|
||||
}
|
||||
|
||||
target "regular" {
|
||||
inherits = ["base", "docker-metadata-action"]
|
||||
}
|
||||
|
||||
target "debug" {
|
||||
inherits = ["default"]
|
||||
inherits = ["base", "docker-metadata-action-debug"]
|
||||
target = "debug"
|
||||
}
|
||||
|
||||
target "test" {
|
||||
inherits = ["default"]
|
||||
target = "test"
|
||||
}
|
||||
|
||||
target "release" {
|
||||
inherits = ["default"]
|
||||
platforms = [
|
||||
"linux/amd64",
|
||||
"linux/arm64",
|
||||
"linux/arm",
|
||||
]
|
||||
}
|
||||
|
||||
// This is what is baked by GitHub Actions
|
||||
group "gha" { targets = ["gha-regular", "gha-debug", "gha-test"] }
|
||||
|
||||
target "gha-base" {
|
||||
inherits = ["release"]
|
||||
// TODO: there seems to be a bug with inheriting twice the platforms, here is a workaround
|
||||
platforms = [
|
||||
"linux/amd64",
|
||||
"linux/arm64",
|
||||
"linux/arm",
|
||||
]
|
||||
}
|
||||
|
||||
// This is filled by GitHub Actions
|
||||
target "gha-push" {}
|
||||
|
||||
target "gha-regular" {
|
||||
inherits = ["gha-base", "gha-push", "docker-metadata-action"]
|
||||
}
|
||||
|
||||
target "gha-debug" {
|
||||
inherits = ["gha-base", "gha-push", "debug", "docker-metadata-action-debug"]
|
||||
}
|
||||
|
||||
target "gha-test" {
|
||||
inherits = ["gha-base", "test"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user