forked from Julien-cpsn/ATAC
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Julien-cpsn#105 from alan910127/main
feat: continuous deployment for docker image
- Loading branch information
Showing
3 changed files
with
106 additions
and
0 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,17 @@ | ||
.dockerignore | ||
Dockerfile | ||
|
||
.idea | ||
/target | ||
|
||
*.ps1 | ||
|
||
.gitignore | ||
|
||
/.github | ||
/base_collections | ||
/gifs | ||
/import-tests | ||
/.typos.toml | ||
LICENSE | ||
README.md |
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,61 @@ | ||
name: Build Docker Image | ||
|
||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
branches: [ "main" ] | ||
paths: | ||
- .github/workflows/build-docker.yml | ||
- Dockerfile | ||
push: | ||
branches: [ "main" ] | ||
release: | ||
types: [ "published" ] | ||
|
||
env: | ||
PUSH_IMAGE: false | ||
IMAGE_NAME: Julien-cpsn/ATAC | ||
RUST_VERSION: "1.79" | ||
|
||
jobs: | ||
build-and-publish: | ||
name: Build and Publish Docker Image | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Docker meta | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ${{ env.IMAGE_NAME }} | ||
tags: | | ||
# When the main branch gets updated, don't tag it as 'main'; instead, tag it as 'latest' | ||
type=ref,event=branch,enable=false | ||
type=raw,value=latest,enable={{is_default_branch}} | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Login to Docker Hub | ||
if: ${{ env.PUSH_IMAGE == true && github.event_name != 'pull_request' }} | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
||
- name: Build and push | ||
uses: docker/build-push-action@v6 | ||
with: | ||
context: . | ||
platforms: linux/amd64,linux/arm64 | ||
build-args: RUST_VERSION=${{ env.RUST_VERSION }} | ||
push: ${{ env.PUSH_IMAGE == 'true' && github.event_name != 'pull_request' }} | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
# Reuse docker build cache | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max | ||
|
||
|
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 @@ | ||
ARG RUST_VERSION | ||
FROM --platform=$BUILDPLATFORM lukemathwalker/cargo-chef:latest-rust-$RUST_VERSION-alpine3.20 AS base | ||
WORKDIR /app | ||
|
||
FROM base AS planner | ||
COPY . . | ||
RUN cargo chef prepare --recipe-path recipe.json | ||
|
||
FROM base AS builder | ||
ARG TARGETPLATFORM | ||
RUN case "$TARGETPLATFORM" in \ | ||
"linux/amd64") echo "x86_64-unknown-linux-musl" > rust_target.txt ;; \ | ||
"linux/arm64") echo "aarch64-unknown-linux-musl" > rust_target.txt ;; \ | ||
esac && \ | ||
# Install musl target | ||
rustup target add $(cat rust_target.txt) && \ | ||
apk add zig && \ | ||
cargo install cargo-zigbuild | ||
|
||
COPY --from=planner /app/recipe.json recipe.json | ||
RUN cargo chef cook --release --target $(cat rust_target.txt) --recipe-path recipe.json --zigbuild | ||
COPY . . | ||
RUN cargo zigbuild --release --target $(cat rust_target.txt) --bin atac && cp /app/target/$(cat rust_target.txt)/release/atac /atac | ||
|
||
FROM alpine:3.20 AS runtime | ||
COPY --from=builder /atac /atac | ||
WORKDIR /app | ||
ENTRYPOINT [ "/atac" ] |