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

Creating a base image to speed up builds #262

Merged
merged 1 commit into from
Nov 16, 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
81 changes: 81 additions & 0 deletions .github/workflows/build-base-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Copyright (c) 2024 Isaac Adams
# Licensed under the MIT License. See LICENSE file in the project root for full license information.
name: Build Base Image

on:
push:
paths-ignore:
- '.github/**'
- 'seeds/**'
- 'dump/**'
- 'k8s/**'
- '!Base.Dockerfile'
- '!requirements.txt'
- '!package-lock.json'
- '.gitignore'

concurrency:
group: deployment

env:
PROJECT_ID: crank-404520
SERVICE: crank
REGION: us-west1
ARTIFACT_REPO: crank-repository

jobs:
build-base-image:
permissions:
contents: 'read'
id-token: 'write'
packages: 'write'

runs-on: ubuntu-latest

steps:
- name: Check if last commit was a merge commit
id: check
run: |
if [[ "$(git log --merges -1 --pretty=%H)" != "$(git log -1 --pretty=%H)" ]]; then
echo "This was not a merge commit. Exiting..."
exit 1
fi

- name: Checkout code
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt

- name: Install Node.js dependencies
run: npm install

- name: Authenticate with GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Copy Base.Dockerfile to Dockerfile
run: |
cp Base.Dockerfile Dockerfile

- name: Build and Push Container to GitHub Container Registry
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ghcr.io/${{ github.repository }}/crank-base:${{ github.sha }}

- name: Tag and Push Image as Latest
run: |
docker tag ghcr.io/${{ github.repository }}/crank-base:${{ github.sha }} ghcr.io/${{ github.repository }}/crank-base:latest
docker push ghcr.io/${{ github.repository }}/crank-base:latest
5 changes: 0 additions & 5 deletions .github/workflows/build-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20

- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/check-license.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ jobs:
with:
python-version: 3.13

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt

- name: Check for license headers
run: |
python check_license.py
6 changes: 1 addition & 5 deletions .github/workflows/deploy-home.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ jobs:
with:
ref: main

- name: Get latest commit SHA from main branch
id: get-sha
run: echo "GITHUB_SHA=$(git rev-parse HEAD)" >> $GITHUB_ENV

- name: Set up Node.js
uses: actions/setup-node@v4
with:
Expand Down Expand Up @@ -57,7 +53,7 @@ jobs:

# Apply the copied crank.yml
ssh -o ProxyCommand='cloudflared access ssh --hostname %h' -o StrictHostKeyChecking=no ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }} <<EOF
export GITHUB_SHA=${{ env.GITHUB_SHA }}
export GITHUB_SHA=${{ github.sha }}
envsubst < /tmp/crank.yml | k3s kubectl apply -f -
envsubst < /tmp/crank-configmap.yml | k3s kubectl apply -f -
EOF
30 changes: 30 additions & 0 deletions Base.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Use an official Python runtime as a parent image
FROM python:3.13.0-alpine3.20

# create a non-root user to run the app as
RUN addgroup -S appgroup -g 10000
RUN adduser -S appuser -u 10000 -G appgroup

# Set the working directory in the container to /app
WORKDIR /app

# Add current directory code to /app in container
ADD . /app

COPY .env-prod .env

# fixing busybox vulnerabilities identified by synk
RUN apk add --no-cache --upgrade busybox
RUN apk add --no-cache busybox-extras

RUN apk add --no-cache --virtual build-deps gcc musl-dev libffi-dev pkgconf mariadb-dev
RUN apk add --no-cache mariadb-connector-c-dev
RUN pip install --no-cache-dir -r requirements.txt
RUN apk del build-deps

# Install Node.js and npm
RUN apk update
RUN apk add nodejs npm

# Install npm dependencies
RUN npm install
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Use an official Python runtime as a parent image
FROM python:3.13.0-alpine3.20
FROM ghcr.io/norcalipa/crank/crank-base:latest

# create a non-root user to run the app as
RUN addgroup -S appgroup -g 10000
Expand Down
Loading