Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add docker build action #549

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
7d31a75
ci: add docker build action
vnghia Jan 2, 2024
e17c2a2
docker: ignore .git for better cache
vnghia Jan 2, 2024
87a0e85
ci: add missing permissions
vnghia Jan 2, 2024
12637b4
cargo: remove cargo dist
vnghia Jan 2, 2024
bd813fc
ci: cache to github action
vnghia Jan 2, 2024
969051b
ci: move docker-release to `docker.yml`
vnghia Jan 2, 2024
db4b54a
ci: update image release tags
vnghia Jan 2, 2024
24b2f82
cargo: merge profile dist to profile release
vnghia Jan 2, 2024
e7f7f76
Merge branch 'main' into docker-build-pr
IgnisDa Jan 2, 2024
1fe5be9
ci: move deploy to docker
vnghia Jan 3, 2024
eb4c31a
Merge branch 'main'
IgnisDa Jan 3, 2024
c466d39
ci: only run deploy if docker success
vnghia Jan 4, 2024
e591c35
Merge branch 'main' into docker-build-pr
IgnisDa Jan 15, 2024
79dd887
ci: push semver tags only when default branch
IgnisDa Jan 15, 2024
b4847d1
ci: release for semver only
IgnisDa Jan 15, 2024
2c92bc5
ci: add deploy for workflow
IgnisDa Jan 15, 2024
af771ab
ci: change workflow name
IgnisDa Jan 15, 2024
fac2f92
ci: change image name
IgnisDa Jan 15, 2024
dd85cf8
ci: deploy docs only on release
IgnisDa Jan 15, 2024
840aea6
Merge branch 'main'
IgnisDa Jan 21, 2024
a3ddedd
ci: remove changelog
IgnisDa Jan 21, 2024
e12d13f
docs: remove section about changelogs
IgnisDa Jan 21, 2024
b176cb0
ci: remove useless files
IgnisDa Jan 21, 2024
ecddef9
Merge branch 'main'
IgnisDa Jan 22, 2024
7bee441
ci: change order of services
IgnisDa Jan 22, 2024
e6cb3ec
docs: improve wording
IgnisDa Jan 22, 2024
64d5b41
docs: remove outdated section from dashboard
IgnisDa Jan 22, 2024
fec7880
ci: do not release pr tag if on default branch
IgnisDa Jan 22, 2024
c50989f
Merge branch 'main'
IgnisDa Jan 28, 2024
f103af0
Merge branch 'main' into docker-build-pr
IgnisDa Apr 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules
.moon/cache
.moon/docker
**/.env
.git
61 changes: 61 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Docker

permissions:
contents: write
packages: write

env:
REGISTRY: ghcr.io

on:
push:
branches:
- main
tags:
- "*-?v[0-9]+*"
pull_request:
branches:
- main

jobs:
docker-build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: |
name=ghcr.io/${{ github.repository }}
tags: |
type=ref,event=pr
type=semver,pattern=v{{version}}
type=semver,pattern=v{{major}}.{{minor}}
Copy link
Owner

@IgnisDa IgnisDa Jan 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tags (v4.1 or v4.1.0) are being released for PRs too. I think the enable attribute needs to be used here?

type=semver,pattern=v{{major}}
type=raw,value=unstable,enable={{is_default_branch}}

- name: Build and push to ghcr
uses: docker/build-push-action@v3
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max
42 changes: 1 addition & 41 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,51 +113,11 @@ jobs:
run: |
gh release upload ${{ github.ref_name }} "tmp/script.ryot.zip"

docker-release:
runs-on: ubuntu-latest
needs: create-release
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Get docker image name and build args
id: required_args
run: |
image_name="${{ env.REGISTRY }}/${{ github.actor }}/${{ github.event.repository.name }}"
image_names="$image_name:${{ github.ref_name }},$image_name:unstable"
if [ "${{ needs.create-release.outputs.is-prerelease }}" = "false" ]; then
image_names="$image_names,$image_name:latest"
fi
# lowercase the name
image_names=$(echo "$image_names" | tr '[:upper:]' '[:lower:]')
echo "image_names=$image_names" >> $GITHUB_OUTPUT

- name: Build and push to ghcr
uses: docker/build-push-action@v3
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.required_args.outputs.image_names }}

# Mark the Github Release™ as a non-draft now that everything has succeeded!
publish-release:
# Only run after all the other tasks, but it's ok if upload-artifacts was skipped
needs:
[create-release, upload-artifacts, docker-release, upload-kodi-plugin]
[create-release, upload-artifacts, upload-kodi-plugin]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we do away with cargo-dist in this release?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, what do you mean by "do away" ?

Copy link
Contributor Author

@vnghia vnghia Jan 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I got it, never heard it before. The reason why I haven't touched it is because I don't have enough information about what it is doing, espcially the upload-kodi-plugin. Also the deploy and the build docs should probably be kept so what do you think about these two jobs ?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep deploy updates the public instance and upload-kodi-plugin creates the kodi archive. Both of the jobs are required.

if: ${{ always() && needs.create-release.result == 'success' && (needs.upload-artifacts.result == 'skipped' || needs.upload-artifacts.result == 'success') }}
runs-on: ubuntu-latest
env:
Expand Down
16 changes: 0 additions & 16 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,3 @@ sea-orm-migration = "0.12.4"
serde = { version = "1.0.189", features = ["derive"] }
serde_json = "1.0.107"
strum = { version = "0.25.0", features = ["derive"] }

[workspace.metadata.dist]
cargo-dist-version = "0.2.0"
ci = ["github"]
installers = ["shell", "powershell"]
targets = [
"x86_64-unknown-linux-gnu",
"x86_64-apple-darwin",
"aarch64-apple-darwin",
]

[profile.dist]
inherits = "release"
opt-level = 's'
strip = true
lto = "thin"
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ RUN cargo chef prepare --recipe-path recipe.json

FROM chef AS app-builder
ARG TARGETARCH
ARG BUILD_PROFILE=release
ENV RUST_TARGET_TRIPLE_arm64="aarch64-unknown-linux-gnu"
ENV RUST_TARGET_TRIPLE_amd64="x86_64-unknown-linux-gnu"
ENV TARGET_CC="clang"
Expand All @@ -38,7 +39,7 @@ ENV CFLAGS_aarch64_unknown_linux_gnu="--sysroot=/usr/aarch64-linux-gnu"
ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc
COPY --from=planner /app/recipe.json recipe.json
RUN rustup target add $(eval "echo \$RUST_TARGET_TRIPLE_$TARGETARCH")
RUN cargo chef cook --profile dist --target $(eval "echo \$RUST_TARGET_TRIPLE_$TARGETARCH") --recipe-path recipe.json
RUN cargo chef cook --profile $BUILD_PROFILE --target $(eval "echo \$RUST_TARGET_TRIPLE_$TARGETARCH") --recipe-path recipe.json
COPY . .
RUN ./apps/backend/ci/build-app.sh

Expand Down
4 changes: 2 additions & 2 deletions apps/backend/ci/build-app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ set -euxo pipefail
export RUST_TARGET_TRIPLE=$(eval "echo \$RUST_TARGET_TRIPLE_$TARGETARCH")

rustup target add $RUST_TARGET_TRIPLE
cargo build --profile dist --bin ryot --target ${RUST_TARGET_TRIPLE}
cp -R /app/target/${RUST_TARGET_TRIPLE}/dist/ryot /app/ryot
cargo build --profile ${BUILD_PROFILE} --bin ryot --target ${RUST_TARGET_TRIPLE}
cp -R /app/target/${RUST_TARGET_TRIPLE}/${BUILD_PROFILE}/ryot /app/ryot