Skip to content

Commit

Permalink
Added docker image and build pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterZydra committed Jan 14, 2024
1 parent 027f45a commit d745db4
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 0 deletions.
94 changes: 94 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: Build Docker image

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

on:
workflow_dispatch: # Allow manual run
push:
branches: [ "main" ]
# Publish semver tags as releases.
tags: [ 'v*.*.*' ]
pull_request:
branches: [ "main" ]

env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: masterzydra/bio-manager

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@v3
with:
cosign-release: 'v2.1.1'

# Set up BuildKit Docker container builder to be able to build
# multi-platform images and export cache
# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Set tag
- name: Set tag
if: ${{ github.ref_type == 'tag' }}
run: echo "TAGS=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }}" >> "$GITHUB_ENV"
- name: Set tag
if: ${{ github.ref_type != 'tag' }}
run: echo "TAGS=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" >> "$GITHUB_ENV"

# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v5
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ env.TAGS }}
cache-from: type=gha
cache-to: type=gha,mode=max

# Sign the resulting Docker image digest except on PRs.
# This will only write to the public Rekor transparency log when the Docker
# repository is public to avoid leaking data. If you would like to publish
# transparency data even for private images, pass --force to cosign below.
# https://github.com/sigstore/cosign
- name: Sign the published Docker image
if: ${{ github.event_name != 'pull_request' }}
env:
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
TAGS: ${{ env.TAGS }}
DIGEST: ${{ steps.build-and-push.outputs.digest }}
# This step uses the identity token to provision an ephemeral certificate
# against the sigstore community Fulcio instance.
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Types of changes: `Added`, `Changed`, `Deprecate`, `Removed`, `Fixed`, `Secruity
- Added migration to call seeder and create a default user
- Added namespace starting with `Resources` to autoloader
- Added checkboxes for each role to the user create and edit form and added logic to controller
- Added docker image and build pipeline

### Changed
- Improved the autoloader to work for the new folder structure of version 2
Expand Down
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM serversideup/php:8.2-fpm-apache

WORKDIR /var/www/html

COPY . .

# Rename env.example so that .env exists
RUN cp .env.example .env; \
# Fix permissions
chown -R webuser:webgroup /var/www/html ; \
# Add bioman-automations to startup
mv ./bioman-automations /etc/s6-overlay/scripts ; \
sed -i 's/\r$//' /etc/s6-overlay/scripts/bioman-automations ; \
chown root:root /etc/s6-overlay/scripts/bioman-automations ; \
chmod ugo+x /etc/s6-overlay/scripts/bioman-automations ; \
mkdir /etc/s6-overlay/s6-rc.d/bioman-automations ; \
echo "/etc/s6-overlay/scripts/bioman-automations" > /etc/s6-overlay/s6-rc.d/bioman-automations/up ; \
echo "oneshot" > /etc/s6-overlay/s6-rc.d/bioman-automations/type ; \
echo "runas-user" > /etc/s6-overlay/s6-rc.d/bioman-automations/dependencies ; \
touch /etc/s6-overlay/s6-rc.d/user/contents.d/bioman-automations

EXPOSE 80
30 changes: 30 additions & 0 deletions bioman-automations
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/command/with-contenv bash

# Exit on error
set -e

# Check to see if the bioman CLI exists and assume it means bioman is configured
if [ -f $WEBUSER_HOME/bioman ] && [ ${AUTORUN_ENABLED:="true"} == "true" ]; then
echo "🏃‍♂️ Checking for automations..."

############################################################################
# Automated file ownership fix
############################################################################
if [ ${AUTORUN_BIOMAN_FILE_OWNERSHIP:="true"} == "true" ]; then
echo "🔐 Fixing file ownership..."
chown -R webuser:webgroup $WEBUSER_HOME
fi

############################################################################
# Automated database upgrade
############################################################################
if [ ${AUTORUN_BIOMAN_DATABASE_UPGRADE:="true"} == "true" ]; then
echo "🚀 Running database upgrade..."
s6-setuidgid webuser php $WEBUSER_HOME/bioman migrate
fi

else
echo "👉 Skipping automations because we could not detect a bioman install or it was specifically disabled..."
fi

exit 0

0 comments on commit d745db4

Please sign in to comment.