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

build: generate template tar.gz on release #12

Merged
merged 1 commit into from
Mar 30, 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
66 changes: 66 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Release

on:
release:
types: [released]
workflow_dispatch:

permissions:
contents: write

jobs:
docker-build:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- name: nextjs-blank
target: scratch_nextjs_blank
out: nextjs-blank.tar.gz

steps:
- uses: actions/checkout@v4

- name: Set up docker buildx
uses: docker/setup-buildx-action@v3

- name: Prepare template ${{ matrix.name }}
uses: docker/build-push-action@v5
with:
file: Dockerfile
cache-from: type=gha,scope=cached-stage
# Exports the artefacts from the final stage
outputs: ./out
target: ${{ matrix.target }}

- run: sha256sum out/${{ matrix.out }}

- run: mv out/${{ matrix.out }} ${{ matrix.out }}

- name: 'Upload ${{ matrix.name }}'
uses: actions/upload-artifact@v4
with:
# name is the name used to display and retrieve the artifact
name: ${{ matrix.name }}
# path is the name used as the file to upload and the name of the
# downloaded file
path: ./${{ matrix.out }}

release:
runs-on: ubuntu-latest
needs: ['docker-build']
steps:
- uses: actions/checkout@v4

- name: Download nextjs-blank
uses: actions/download-artifact@v4
with:
name: nextjs-blank.tar.gz
path: .

- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
./nextjs-blank.tar.gz
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM alpine:3.19.1 as deps

# Install bash package
RUN apk add --no-cache bash

# Create and use a user instead of using root
RUN addgroup -S appgroup && adduser -S apprunner -G appgroup
USER apprunner

# Define working directories
WORKDIR /prepare

# Copy resources
COPY --chown=apprunner:apprunner . /prepare

# Create output directory
RUN mkdir -p ./target

FROM deps as build_nextjs_blank

RUN ./docker/compress app/nextjs-blank

FROM scratch AS scratch_nextjs_blank
COPY --from=build_nextjs_blank ./prepare/target/nextjs-blank.tar.gz /
32 changes: 32 additions & 0 deletions docker/compress
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash

# Check if an argument is provided
if [ "$#" -eq 0 ]; then
echo "Usage: $0 <subdirectory>"
exit 1
fi

# Construct the path
path="./templates/$1"

# Check if the directory exists
if [ ! -d "$path" ]; then
echo "Directory $path does not exist. Skipping."
exit 0
fi

function compress() {
local folder=$1

# Extract the base name of the folder to use as the archive name
local foldername=$(basename "$folder")

local output="./target/${foldername}.tar.gz"

# Create a tar.gz file for the folder
tar -czf "$output" -C "$(dirname "$folder")" "$(basename "$folder")"

sha256sum "$output"
}

compress "$path"
Loading