diff --git a/.bazelversion b/.bazelversion new file mode 100644 index 0000000..34a8f74 --- /dev/null +++ b/.bazelversion @@ -0,0 +1 @@ +7.3.1 \ No newline at end of file diff --git a/.github/workflows/bazel.yml b/.github/workflows/bazel.yml deleted file mode 100644 index 67706f3..0000000 --- a/.github/workflows/bazel.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: Bazel - -on: [push, pull_request] - -jobs: - setup-bazel: - runs-on: ubuntu-22.04 - steps: - - name: Run setup-bazel - uses: bazel-contrib/setup-bazel@0.8.5 - with: - # Avoid downloading Bazel every time. - bazelisk-cache: true - # Store build cache per workflow. - disk-cache: ${{ github.workflow }} - # Share repository cache between workflows. - repository-cache: true - - # Checks-out your repository under $GITHUB_WORKSPACE, which is the CWD for - # the rest of the steps - - uses: actions/checkout@v2 - - # build - - name: Build the code - run: bazel build //... - - # test - - name: Test the code - run: bazel test //... diff --git a/.github/workflows/fill_station_build_and_push.yml b/.github/workflows/fill_station_build_and_push.yml new file mode 100644 index 0000000..7e3181c --- /dev/null +++ b/.github/workflows/fill_station_build_and_push.yml @@ -0,0 +1,112 @@ +name: Fill Station Build Test Push + +# Configures this workflow to run every time a change is pushed to the branch called `main` or a pull request to `main` is created +on: + push: + branches: ['main'] + pull_request: + branches: ['main'] + +# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds. +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository_owner }}/fill-station + +jobs: + build-and-test: + runs-on: ubuntu-latest + + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, which is the CWD for + # the rest of the steps + - name: Checkout code + uses: actions/checkout@v4 + + - uses: bazel-contrib/setup-bazel@0.8.5 + with: + # Avoid downloading Bazel every time. + bazelisk-cache: true + # Store build cache per workflow. + disk-cache: ${{ github.workflow }} + # Share repository cache between workflows. + repository-cache: true + + # test + - name: Build and Test with Bazel + run: bazel --output_base=/tmp/bazel/output test //fill:all + + # Upload the fill station binary as an artifact + - uses: actions/upload-artifact@v4 + with: + # Name of the artifact to upload. + # Optional. Default is 'artifact' + name: fill_station + # The path to the fill station binary from bazel build + path: /tmp/bazel/output/execroot/_main/bazel-out/k8-fastbuild/bin/fill/fill_station + + push-image: + needs: build-and-test + runs-on: ubuntu-latest + # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. + permissions: + contents: read + packages: write + attestations: write + id-token: write + + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, which is the CWD for + # the rest of the steps + - name: Checkout code + uses: actions/checkout@v4 + + - uses: actions/download-artifact@v4 + with: + # Name of the artifact to download. + # If unspecified, all artifacts for the run are downloaded. + # Optional. + name: fill_station + + # Destination path. Supports basic tilde expansion. + # Optional. Default is $GITHUB_WORKSPACE + path: fill/fill_station + + # Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here. + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels. + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=raw,value=latest,enable={{is_default_branch}} + type=ref,event=branch + type=ref,event=pr + + # This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages. + # It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository. + # It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step. + - name: Build and push Fill Station Docker image + id: push + uses: docker/build-push-action@v5 + with: + context: . + file: ./fill/Dockerfile # Path to your Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + # This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see "[AUTOTITLE](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds)." + - name: Generate artifact attestation + uses: actions/attest-build-provenance@v1 + with: + subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} + subject-digest: ${{ steps.push.outputs.digest }} + push-to-registry: true \ No newline at end of file diff --git a/.gitignore b/.gitignore index a3f0a16..352bf96 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +# Docker ignore files +.dockerignore # Bazel files bazel-* diff --git a/README.md b/README.md index 99a4f09..075ccae 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Ground-Software Ground Support Equipment Software for the Cornell Rocketry Team including fill station and ground server -## Ground Server +## Ground Server Docker Image First, install Docker for your specific computer. Then, to start the ground server run: ```shell @@ -9,6 +9,14 @@ docker pull ghcr.io/cornellrocketryteam/ground-server docker run -it -d -p 80:80 ghcr.io/cornellrocketryteam/ground-server ``` +## Fill Station Docker Image + +First, install Docker for your specific computer. Then, to start the ground server run: +```shell +docker pull ghcr.io/cornellrocketryteam/fill-station +docker run -it -d -p 50051:50051 --network="host" ghcr.io/cornellrocketryteam/ground-server +``` + ## Fix and Format Bazel files Buildifier will fix a lot and format all bazel files by running @@ -20,7 +28,7 @@ FOR x86 LINUX OR WSL (NOT RASPBERRY PI) ```sudo apt install bazel``` -2. Check version (tested with version 7.1.1): +2. Check version (tested with version 7.3.1): ```bazel --version``` diff --git a/fill/Dockerfile b/fill/Dockerfile new file mode 100644 index 0000000..61140b2 --- /dev/null +++ b/fill/Dockerfile @@ -0,0 +1,13 @@ +# Load a lightweight Linux image +FROM ubuntu:22.04 AS run + +# Copy the build output from the GitHub Workflow to Alpine +COPY ./fill/fill_station /bin/fill_station + +RUN ["chmod", "+x", "/bin/fill_station/fill_station"] + +# Expose the gRPC Server Port +EXPOSE 50051 + +# Run the binary +ENTRYPOINT [ "/bin/fill_station/fill_station" ]