-
Notifications
You must be signed in to change notification settings - Fork 2
82 feature request suggestion create fe image workflow #99
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
Merged
lmcdonough
merged 9 commits into
main
from
82-feature-request-suggestion-create-fe-image-workflow
Apr 12, 2025
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b67afa2
modifies Dockerfile to work with gh actions and support multiple plat…
lmcdonough a3c33a5
adds github actions workflow to build frontend multiplatform image an…
lmcdonough b953bab
upgrades base node image to a version without any critical vulnerabil…
lmcdonough 7f1b4e6
updates ENTRYPOINT and CMD to allow for flexibility at runtime.
lmcdonough e083ed9
adds .vscode settings to gitignore
lmcdonough 03ed618
adds vscode to gitignore
lmcdonough e0b4c6d
updates readme to include containerized docs for frontend
lmcdonough 3f0dc41
adds docs/runbooks/Container-README and references it in main README
lmcdonough ca9b4db
Merge branch 'main' into 82-feature-request-suggestion-create-fe-imag…
jhodapp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,99 @@ | ||
name: Build and Push Frontend Image | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
branches: [main] | ||
types: [opened, synchronize, reopened] | ||
workflow_dispatch: | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
|
||
jobs: | ||
build_and_push_frontend: | ||
runs-on: ubuntu-22.04 | ||
|
||
permissions: | ||
contents: read | ||
packages: write | ||
id-token: write # Required for Cosign OIDC signing | ||
|
||
steps: | ||
# Checkout the source code | ||
- uses: actions/checkout@v4 | ||
|
||
# Setup QEMU for emulating multi-arch (e.g., ARM64 on x86) | ||
- uses: docker/setup-qemu-action@v2 | ||
with: | ||
platforms: linux/amd64,linux/arm64 | ||
|
||
# Setup Buildx for advanced Docker builds (multiarch, caching, sbom) | ||
- uses: docker/setup-buildx-action@v3 | ||
with: | ||
install: true | ||
|
||
# Login to GHCR (GitHub Container Registry) | ||
- name: Docker login | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
# Dynamically generate image tag and name based on repo/org/branch | ||
- name: Determine Image Tags | ||
id: tags | ||
run: | | ||
BRANCH_NAME=${GITHUB_HEAD_REF:-${GITHUB_REF##*/}} | ||
ORG_NAME="refactor-group" | ||
REPO_NAME="refactor-platform-fe" | ||
IMAGE="${{ env.REGISTRY }}/${ORG_NAME}/${REPO_NAME}/${BRANCH_NAME}:latest" | ||
echo "tag=$IMAGE" >> $GITHUB_OUTPUT | ||
echo "image=$IMAGE" >> $GITHUB_OUTPUT | ||
|
||
# Build, SBOM, and Push the multi-arch Docker image | ||
- name: Build + Push Frontend | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
file: ./Dockerfile # Dockerfile is at the root of the repo | ||
target: runner # Your Dockerfile defines this stage | ||
platforms: linux/amd64,linux/arm64 | ||
push: true | ||
provenance: true # Enables provenance metadata | ||
sbom: true # Enables SBOM generation | ||
build-args: | | ||
NEXT_PUBLIC_BACKEND_SERVICE_PROTOCOL=${{ secrets.BACKEND_SERVICE_PROTOCOL }} | ||
NEXT_PUBLIC_BACKEND_SERVICE_HOST=${{ secrets.BACKEND_SERVICE_HOST }} | ||
NEXT_PUBLIC_BACKEND_SERVICE_PORT=${{ secrets.BACKEND_PORT }} | ||
NEXT_PUBLIC_BACKEND_API_VERSION=${{ secrets.BACKEND_API_VERSION }} | ||
FRONTEND_SERVICE_PORT=${{ secrets.FRONTEND_SERVICE_PORT }} | ||
FRONTEND_SERVICE_INTERFACE=${{ secrets.FRONTEND_SERVICE_INTERFACE }} | ||
tags: ${{ steps.tags.outputs.tag }} | ||
cache-from: type=gha # GitHub-hosted build cache | ||
cache-to: type=gha,mode=max | ||
|
||
# Install Cosign CLI for image signing | ||
- name: Install Cosign | ||
uses: sigstore/cosign-installer@v3 | ||
|
||
# Sign image using GitHub OIDC token (no secrets needed) | ||
- name: Sign image with Cosign | ||
env: | ||
COSIGN_EXPERIMENTAL: "true" | ||
run: | | ||
cosign sign --yes ${{ steps.tags.outputs.image }} | ||
|
||
# Output usage instructions | ||
- name: Print Pull & Run Instructions | ||
run: | | ||
echo -e "\033[1;32mFrontend Image Pushed & Signed:\033[0m" | ||
echo " docker pull ${{ steps.tags.outputs.image }}" | ||
echo "" | ||
echo -e "\033[1;36mRun locally or with Compose:\033[0m" | ||
echo " docker run --rm --env-file .env -p 3000:3000 ${{ steps.tags.outputs.image }}" | ||
echo "" | ||
echo -e "\033[1;33mSignature Verification:\033[0m" | ||
echo " cosign verify ${{ steps.tags.outputs.image }}" |
This file contains hidden or 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 |
---|---|---|
|
@@ -34,3 +34,7 @@ yarn-error.log* | |
# typescript | ||
*.tsbuildinfo | ||
next-env.d.ts | ||
|
||
# vscode | ||
.vscode/ | ||
|
This file contains hidden or 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 hidden or 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 hidden or 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,98 @@ | ||
# Refactor Platform Frontend Docker Image Management | ||
|
||
## Managing the Project with Docker & GitHub Actions (CI/CD) | ||
|
||
This project builds and pushes a multi-arch Docker image to [GHCR](https://github.com/orgs/refactor-group/packages) and triggers a build workflow on GitHub automatically on pushes to branches with open pull requests. | ||
|
||
**Key Steps:** | ||
|
||
1. **Develop Your Changes:** | ||
- Work on your feature or fix in your branch. | ||
2. **Open a Pull Request:** | ||
- When you open a PR, GitHub Actions triggers the build workflow. | ||
3. **Automated Build & Push:** | ||
- The workflow builds a multi-arch Docker image and pushes it to GHCR. | ||
- Verify the build status in GitHub Actions. | ||
- The images are named as follows: `ghcr.io/refactor-group/refactor-platform-fe/<branch>:latest` | ||
4. **Local Testing (Optional):** | ||
- For local Docker testing, note that the Docker Compose file and environment variables are maintained in the backend repository. Make sure you have access to that repo for configuration details. | ||
|
||
--- | ||
|
||
## Manual Docker Image Management | ||
|
||
### If you plan on working with the Docker Image Locally as well the following section acts as a quickstart guide for managing the Docker images manually | ||
|
||
#### Prerequisites | ||
|
||
- Before running any Docker commands, ensure you are logged into GHCR using your GitHub personal access token (PAT): | ||
|
||
```bash | ||
docker login ghcr.io -u <your_github_username> -p <your_PAT> | ||
``` | ||
|
||
- Ensure you have Containerd installed and running | ||
- Ensure you have Docker Buildx installed and configured | ||
- Ensure you are using the builder instance you create using steps 1-4 below | ||
- Ensure you have Docker installed and running | ||
**Image Naming Convention:** | ||
The Docker images follow the naming convention: | ||
`ghcr.io/refactor-group/refactor-platform-fe/<branch>:latest` | ||
|
||
Where: | ||
|
||
- `refactor-group` is your GitHub organization. | ||
- `refactor-platform-fe` is the repository name. | ||
- `<branch>` is the name of the branch, with underscores converted to dashes. | ||
- `latest` is the tag. | ||
|
||
**Useful Commands:** | ||
|
||
```bash | ||
# Docker Buildx: Enhanced Image Management | ||
|
||
# 1. Inspect Docker Buildx | ||
docker buildx version # Verify Docker Buildx is installed | ||
|
||
# 2. Create a new builder instance (if needed) | ||
docker buildx create --name mybuilder --driver docker-container # Creates a builder instance named 'mybuilder' using the docker-container driver | ||
|
||
# 3. Use the builder | ||
docker buildx use mybuilder # Sets 'mybuilder' as the current builder | ||
|
||
# 4. Inspect the builder | ||
docker buildx inspect --bootstrap # Displays details and ensures the builder is running | ||
|
||
# 5. Login to GHCR | ||
docker login ghcr.io -u <your_github_username> -p <your_PAT> # Authenticates with GitHub Container Registry using your username and PAT | ||
|
||
# 6. Build the image for multiple architectures and push to registry | ||
docker buildx build --platform linux/amd64,linux/arm64 -t ghcr.io/refactor-group/refactor-platform-fe:<branch> --push . # Builds for specified architectures and pushes to GHCR | ||
|
||
# 7. Build the image for multiple architectures and load to local docker daemon | ||
docker buildx build --platform linux/amd64,linux/arm64 -t ghcr.io/refactor-group/refactor-platform-fe:<branch> --load . # Builds for specified architectures and loads to local docker daemon | ||
|
||
# 8. Tag the image | ||
docker tag ghcr.io/refactor-group/refactor-platform-fe:<branch> ghcr.io/refactor-group/refactor-platform-fe:<branch>:latest # Creates an additional tag 'latest' for the image | ||
|
||
# 9. Push the image | ||
docker push ghcr.io/refactor-group/refactor-platform-fe:<branch>:latest # Uploads the image to the container registry | ||
|
||
# 10. Pull the image | ||
docker pull ghcr.io/refactor-group/refactor-platform-fe:<branch>:latest # Downloads the image from the container registry | ||
|
||
# 11. Run the image | ||
docker run -p 3000:3000 ghcr.io/refactor-group/refactor-platform-fe:<branch>:latest # Starts a container from the image, mapping port 3000 | ||
|
||
# 12. Inspect the image | ||
docker inspect ghcr.io/refactor-group/refactor-platform-fe:<branch>:latest # Shows detailed information about the image | ||
|
||
# 13. Remove the image | ||
docker rmi ghcr.io/refactor-group/refactor-platform-fe:<branch>:latest # Deletes the image from the local machine | ||
``` | ||
|
||
### Important Notes | ||
|
||
- Always use the `latest` tag for the most recent version (it defaults to `latest`) | ||
- Ensure your branch is up to date with the main branch before opening a PR | ||
- For backend-specific configuration (Docker Compose & env vars), refer to the backend repository documentation |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.