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

Dockerize Fill Station Binary #24

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.3.1
29 changes: 0 additions & 29 deletions .github/workflows/bazel.yml

This file was deleted.

69 changes: 69 additions & 0 deletions .github/workflows/fill_station_build_and_push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Create and publish the Fill Station Docker image

# 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-push-image:
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 repository
uses: actions/checkout@v4

# 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
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
32 changes: 32 additions & 0 deletions .github/workflows/fill_station_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Build and Test the Fill Station Code with Bazel

# 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']

# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
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 test //fill:all
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Create and publish the Ground Station Docker image
name: Create and publish the Ground Server Docker image

# 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:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

# New change
# Bazel files
bazel-*
bazel_format_virtual_environment/
Expand Down
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
# 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
docker pull ghcr.io/cornellrocketryteam/ground-server
docker run -it -d -p 80:80 ghcr.io/cornellrocketryteam/ground-server
```

If you want to build the docker image locally, navigate to the root directory then build:
```shell
cd Ground-Software/ground-server
docker build -t 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 --network="host" ghcr.io/cornellrocketryteam/fill-station
```

If you want to build the docker image locally, navigate to the root directory then build:
```shell
cd Ground-Software
docker build -t fill-station -f ./fill/Dockerfile .
```

## Fix and Format Bazel files
Buildifier will fix a lot and format all bazel files by running

Expand All @@ -20,7 +40,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```

Expand Down
29 changes: 29 additions & 0 deletions fill/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Stage 1: Build
FROM golang AS build

# Install Bazelisk
RUN go install github.com/bazelbuild/bazelisk@latest

# Set the working directory
WORKDIR /app

# Copy the source code
COPY . .

# Build the project using Bazelisk (via Bazel)
RUN bazelisk build //fill:all

# Stage 2: Create lightweight runtime image
FROM ubuntu

# Set the working directory
WORKDIR /app

# Copy the build output from the GitHub Workflow to Alpine
COPY --from=build /app/bazel-bin/fill/fill_station ./fill_station

# Expose the gRPC Server Port
EXPOSE 50051

# Run the binary
CMD [ "/app/fill_station" ]