-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Binary build and Docker image build (#97)
- Loading branch information
1 parent
29f14b7
commit eadad15
Showing
10 changed files
with
225 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.github | ||
.vscode | ||
benches | ||
temp | ||
tests | ||
renovate.json | ||
temp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
name: build | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
branches: | ||
- master | ||
release: | ||
types: [created] | ||
|
||
jobs: | ||
dockerize: | ||
name: dockerize | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: configure eqemu | ||
uses: docker/setup-qemu-action@v3 | ||
with: | ||
platforms: "linux/arm64,linux/amd64" | ||
|
||
- name: configure docker buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: login to docker registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: build docker images | ||
timeout-minutes: 15 | ||
id: docker-bake | ||
uses: docker/bake-action@v4 | ||
env: | ||
DOCKER_REGISTRY: ghcr.io/${{ github.repository }}/ | ||
COMMIT_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} | ||
PUBLISH_VERSION: ${{ github.event_name == 'release' && github.event.release.tag_name || '' }} | ||
PUBLISH_LATEST: ${{ github.event_name == 'release' && !github.event.release.prerelease && '1' || '' }} | ||
with: | ||
workdir: . | ||
provenance: false | ||
push: true | ||
files: docker/bake.hcl | ||
targets: build | ||
set: | | ||
*.cache-from=type=gha,scope=build | ||
*.cache-to=type=gha,scope=build,mode=max | ||
- name: docker details pr comment | ||
uses: marocchino/sticky-pull-request-comment@v2 | ||
if: ${{ github.event_name == 'pull_request' }} | ||
with: | ||
message: | | ||
🐋 This PR was built and pushed to the following [Docker images](https://github.com/the-guild-org/conductor-t2/pkgs/container/conductor-t2%2Fconductor): | ||
<details> | ||
<summary>Docker Bake metadata</summary> | ||
```json | ||
${{ steps.docker-bake.outputs.metadata }} | ||
``` | ||
</details> | ||
binary: | ||
name: compile binary (${{ matrix.platform.target }}) | ||
strategy: | ||
matrix: | ||
platform: | ||
- os: ubuntu-22.04 | ||
target: x86_64-unknown-linux-gnu | ||
|
||
- os: ubuntu-22.04 | ||
target: aarch64-unknown-linux-gnu | ||
|
||
runs-on: ${{ matrix.platform.os }} | ||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: build binary | ||
uses: houseabsolute/actions-rust-cross@v0 | ||
with: | ||
command: build | ||
target: ${{ matrix.platform.target }} | ||
args: "--locked --release" | ||
strip: true | ||
|
||
- uses: actions/upload-artifact@v3 | ||
if: ${{ github.event_name == 'pull_request' || github.event_name == 'push' }} | ||
name: upload binary artifact | ||
with: | ||
name: conductor-${{ matrix.platform.target }} | ||
path: target/${{ matrix.platform.target }}/release/conductor | ||
|
||
- name: upload binaries to release | ||
if: ${{ github.event_name == 'release' }} | ||
uses: svenstaro/upload-release-action@v2 | ||
with: | ||
repo_token: ${{ secrets.GITHUB_TOKEN }} | ||
file: target/${{ matrix.platform.target }}/release/conductor | ||
asset_name: conductor-${{ matrix.platform.target }} | ||
tag: ${{ github.ref }} | ||
overwrite: true |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
FROM rust:1.72.1 as builder | ||
|
||
WORKDIR /usr/src/conductor | ||
|
||
COPY Cargo.toml Cargo.lock ./ | ||
# This is a trick to get the most out of Docker's caching mechanism in GH Actions. | ||
RUN mkdir src | ||
RUN mkdir benches | ||
RUN echo 'fn main() { println!("Dummy!"); }' > ./src/main.rs | ||
RUN echo 'fn main() { println!("Dummy!"); }' > ./src/lib.rs | ||
RUN echo 'fn main() { println!("Dummy!"); }' > ./benches/bench.rs | ||
# We are only building the dependencies here, with a dummy file, this compiles all dependencies code only. | ||
RUN cargo build --release --bin conductor | ||
|
||
# Now we can remove the dummy code, copy the actual code and compile the user code. | ||
# This ensures that building dependencies and the actual code are cached separately. | ||
RUN rm -rf src | ||
COPY src src | ||
RUN touch src/main.rs src/lib.rs | ||
RUN cargo build --release --bin conductor | ||
|
||
FROM debian:12.1 | ||
|
||
RUN apt-get update -y && apt-get install -y ca-certificates | ||
|
||
COPY --from=builder /usr/src/conductor/target/release/conductor /usr/local/bin/conductor | ||
|
||
CMD conductor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
variable "DOCKER_REGISTRY" { | ||
default = "" | ||
} | ||
|
||
variable "COMMIT_SHA" { | ||
default = "local" | ||
} | ||
|
||
variable "PUBLISH_VERSION" { | ||
# Can be "" or the actual version to publish | ||
default = "" | ||
} | ||
|
||
variable "PUBLISH_LATEST" { | ||
# Can be "" or "1" | ||
default = "" | ||
} | ||
|
||
function "maybe_latest_image_tag" { | ||
params = [name] | ||
result = equal("1", PUBLISH_LATEST) ? "${DOCKER_REGISTRY}${name}:latest" : "" | ||
} | ||
|
||
function "maybe_version_tag" { | ||
params = [name] | ||
result = notequal("", PUBLISH_VERSION) ? "${DOCKER_REGISTRY}${name}:${PUBLISH_VERSION}" : "" | ||
} | ||
|
||
function "commit_id_tag" { | ||
params = [name, tag] | ||
result = notequal("", tag) ? "${DOCKER_REGISTRY}${name}:${tag}" : "" | ||
} | ||
|
||
target "conductor" { | ||
context = "./" | ||
dockerfile = "./docker/Dockerfile" | ||
tags = [ | ||
commit_id_tag("conductor", COMMIT_SHA), | ||
maybe_latest_image_tag("conductor"), | ||
maybe_version_tag("conductor"), | ||
] | ||
labels = { | ||
"org.opencontainers.image.source" = "https://github.com/the-guild-org/conductor-t2", | ||
"org.opencontainers.image.authors": "The Guild <[email protected]>", | ||
"org.opencontainers.image.vendor": "The Guild", | ||
"org.opencontainers.image.url": "https://the-guild.dev/graphql/gateway", | ||
"org.opencontainers.image.docs": "https://the-guild.dev/graphql/gateway", | ||
"org.opencontainers.image.version": PUBLISH_VERSION, | ||
"org.opencontainers.image.revision": COMMIT_SHA, | ||
"org.opencontainers.image.licenses": "MIT", | ||
"org.opencontainers.image.title": "Conductor", | ||
"org.opencontainers.image.description": "Conductor is a robust GraphQL Gateway." | ||
} | ||
} | ||
|
||
group "build" { | ||
targets = [ | ||
"conductor" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters