-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: github actions workflow to test scaf project create
- Loading branch information
Showing
5 changed files
with
152 additions
and
17 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,45 @@ | ||
name: Create scaf project | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build-and-push: | ||
environment: dev | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out the repo | ||
uses: actions/checkout@v3 | ||
|
||
- name: Log in to Docker Hub | ||
uses: docker/#-action@v3 | ||
with: | ||
username: ${{ secrets.DOCKER_USERNAME }} | ||
password: ${{ secrets.DOCKER_ACCESS_TOKEN }} | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v2 | ||
with: | ||
push: true | ||
tags: sixfeetup/scaf:${{ github.sha }} | ||
|
||
setup: | ||
environment: dev | ||
needs: build-and-push | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Install Requirements | ||
shell: bash | ||
run: | | ||
INSTALL_URL="https://raw.githubusercontent.com/sixfeetup/scaf/$GITHUB_REF_NAME/install.sh" | ||
export SCAF_SCRIPT_BRANCH=$GITHUB_REF_NAME | ||
echo "Downloading install script from $INSTALL_URL" | ||
curl -sSL $INSTALL_URL | sh | ||
- name: Create Project with Scaf | ||
shell: bash | ||
run: | | ||
IMAGE_TAG=$GITHUB_SHA | ||
echo "Running scaf with sixfeetup/scaf:$IMAGE_TAG" | ||
/usr/local/bin/scaf myproject --no-input | ||
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
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 |
---|---|---|
@@ -1,40 +1,85 @@ | ||
#!/usr/bin/env sh | ||
set -e | ||
|
||
echo "Starting entrypoint script..." | ||
|
||
# Check if HOST_UID and HOST_GID are provided | ||
if [ -z "$HOST_UID" ]; then | ||
echo "ERROR: please set HOST_UID" >&2 | ||
exit 1 | ||
else | ||
echo "HOST_UID provided: $HOST_UID" | ||
fi | ||
|
||
if [ -z "$HOST_GID" ]; then | ||
echo "ERROR: please set HOST_GID" >&2 | ||
exit 1 | ||
else | ||
echo "HOST_GID provided: $HOST_GID" | ||
fi | ||
|
||
# Function to check if a group with the given GID already exists | ||
group_exists_with_gid() { | ||
getent group | cut -d: -f3 | grep -q "^$1$" | ||
echo "Checking if group with GID $1 exists..." | ||
} | ||
|
||
# Function to check if a user with the given UID already exists | ||
user_exists_with_uid() { | ||
getent passwd | cut -d: -f3 | grep -q "^$1$" | ||
echo "Checking if user with UID $1 exists..." | ||
} | ||
|
||
# Function to check if the scaf user already has the target UID | ||
scaf_has_uid() { | ||
[ "$(id -u scaf)" -eq "$1" ] | ||
echo "Checking if scaf has UID $1..." | ||
} | ||
|
||
# Function to check if the scaf group already has the target GID | ||
scaf_has_gid() { | ||
[ "$(getent group scaf | cut -d: -f3)" -eq "$1" ] | ||
echo "Checking if scaf group has GID $1..." | ||
} | ||
|
||
# Modify the scaf user account to match the host user, adjusting for existing GID | ||
if group_exists_with_gid "$HOST_GID"; then | ||
# Find the group name with the target GID | ||
existing_group=$(getent group | awk -F: "\$3 == $HOST_GID { print \$1 }") | ||
|
||
# Use the existing group for the scaf user | ||
usermod -g "$existing_group" scaf | ||
echo "Group with GID $HOST_GID exists." | ||
if ! scaf_has_gid "$HOST_GID"; then | ||
existing_group=$(getent group | awk -F: "\$3 == $HOST_GID { print \$1 }") | ||
echo "Existing group with GID $HOST_GID: $existing_group" | ||
usermod -g "$existing_group" scaf | ||
echo "Assigned existing group $existing_group to scaf." | ||
else | ||
echo "scaf already in the correct group." | ||
fi | ||
else | ||
# If GID does not exist, modify the scaf group to match HOST_GID | ||
echo "Group with GID $HOST_GID does not exist, attempting to modify scaf group." | ||
groupmod -g "$HOST_GID" scaf | ||
echo "Modified scaf group to GID $HOST_GID." | ||
fi | ||
|
||
if ! scaf_has_uid "$HOST_UID"; then | ||
if user_exists_with_uid "$HOST_UID"; then | ||
echo "ERROR: UID '$HOST_UID' already exists" >&2 | ||
exit 1 | ||
else | ||
echo "Modifying scaf UID to $HOST_UID." | ||
usermod -u "$HOST_UID" scaf | ||
echo "Modified scaf UID to $HOST_UID." | ||
fi | ||
else | ||
echo "scaf already has the UID $HOST_UID." | ||
fi | ||
|
||
# Modify the scaf user to match HOST_UID | ||
usermod -u "$HOST_UID" scaf | ||
chown scaf:scaf /home/scaf/out | ||
|
||
echo "Finalizing: Dropping privileges and executing command..." | ||
# Drop privileges and execute the next container command, or 'sh' if not specified | ||
if [ "$#" -gt 0 ]; then | ||
echo "Executing command: $@" | ||
su-exec scaf "$@" | ||
else | ||
echo "No command specified, launching shell." | ||
su-exec scaf sh | ||
fi |
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
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