Skip to content

Commit

Permalink
Add github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
KennethWussmann committed Mar 5, 2024
1 parent f799f14 commit 5861b1d
Show file tree
Hide file tree
Showing 12 changed files with 250 additions and 13 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
README.md
.github
build
27 changes: 27 additions & 0 deletions .github/actions/docker-publish/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: docker-publish
description: Publish the Docker image to GH Container Registry
inputs:
githubToken:
description: "Token to access private GH Docker registry"
required: true
tags:
description: "Tags to assign for the published docker container"
required: true
build-args:
description: "Build args"
required: false
runs:
using: "composite"
steps:
- name: Login to GitHub Packages Docker Registry
uses: docker/login-action@v2
with:
username: ${{ github.repository_owner }}
password: ${{ inputs.githubToken }}
registry: ghcr.io
- name: Build and push
uses: docker/build-push-action@v4
with:
push: true
tags: ${{ inputs.tags }}
build-args: ${{ inputs.build-args }}
27 changes: 27 additions & 0 deletions .github/actions/pnpm-install/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: pnpm-install
description: Install Node, pnpm and dependencies
runs:
using: "composite"
steps:
- name: Install Node
uses: actions/setup-node@v2
with:
node-version: 20
- uses: pnpm/action-setup@v3
with:
version: 8
run_install: false
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm i --frozen-lockfile
shell: bash
19 changes: 19 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: build

on:
push:
branches:
- main
pull_request:

env:
FORCE_COLOR: 1

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/pnpm-install
- run: pnpm lint
- run: pnpm build
57 changes: 57 additions & 0 deletions .github/workflows/release-docker-develop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: release-docker-develop

on:
push:
branches:
- main

concurrency: release-docker-develop

env:
FORCE_COLOR: 1

jobs:
build:
runs-on: ${{ matrix.runner }}
strategy:
matrix:
include:
- runner: buildjet-8vcpu-ubuntu-2204-arm
arch: arm64
- runner: ubuntu-latest
arch: amd64
permissions:
packages: write
contents: read
outputs:
SHORT_SHA: ${{ steps.git-commit.outputs.SHORT_SHA }}
steps:
- uses: actions/checkout@v4
- name: Get git commit
id: git-commit
run: echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> "$GITHUB_OUTPUT"
- uses: ./.github/actions/docker-publish
with:
githubToken: ${{ secrets.GITHUB_TOKEN }}
tags: ghcr.io/kennethwussmann/github-archive:${{ matrix.arch }}-${{ steps.git-commit.outputs.SHORT_SHA }}
build-args: VERSION=${{ steps.git-commit.outputs.SHORT_SHA }}

create-and-push-manifest:
needs: build
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- name: Login to GitHub Packages Docker Registry
uses: docker/login-action@v3
with:
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
- name: Create and push Docker manifest
run: |
docker manifest create ghcr.io/kennethwussmann/github-archive:develop \
--amend ghcr.io/kennethwussmann/github-archive:amd64-${{ needs.build.outputs.SHORT_SHA }} \
--amend ghcr.io/kennethwussmann/github-archive:arm64-${{ needs.build.outputs.SHORT_SHA }}
docker manifest push ghcr.io/kennethwussmann/github-archive:develop
61 changes: 61 additions & 0 deletions .github/workflows/release-docker-latest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: release-docker-latest

on:
push:
tags:
- "*"

concurrency: release-docker-latest

env:
FORCE_COLOR: 1

jobs:
build:
runs-on: ${{ matrix.runner }}
strategy:
matrix:
include:
- runner: buildjet-8vcpu-ubuntu-2204-arm
arch: arm64
- runner: ubuntu-latest
arch: amd64
permissions:
packages: write
contents: read
outputs:
tag: ${{ steps.vars.outputs.tag }}
steps:
- uses: actions/checkout@v4
- name: Get version
id: vars
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}
- uses: ./.github/actions/docker-publish
with:
githubToken: ${{ secrets.GITHUB_TOKEN }}
tags: ghcr.io/kennethwussmann/github-archive:${{ matrix.arch }}-${{ steps.vars.outputs.tag }}
build-args: VERSION=${{ steps.vars.outputs.tag }}

create-and-push-manifest:
needs: build
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- name: Login to GitHub Packages Docker Registry
uses: docker/login-action@v2
with:
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
- name: Create and push Docker manifest
run: |
docker manifest create ghcr.io/kennethwussmann/github-archive:${{ needs.build.outputs.tag }} \
--amend ghcr.io/kennethwussmann/github-archive:amd64-${{ needs.build.outputs.tag }} \
--amend ghcr.io/kennethwussmann/github-archive:arm64-${{ needs.build.outputs.tag }}
docker manifest push ghcr.io/kennethwussmann/github-archive:${{ needs.build.outputs.tag }}
docker manifest create ghcr.io/kennethwussmann/github-archive:latest \
--amend ghcr.io/kennethwussmann/github-archive:amd64-${{ needs.build.outputs.tag }} \
--amend ghcr.io/kennethwussmann/github-archive:arm64-${{ needs.build.outputs.tag }}
docker manifest push ghcr.io/kennethwussmann/github-archive:latest
27 changes: 27 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
ARG NODE_VERSION=20
FROM node:${NODE_VERSION}-slim AS builder

RUN apt-get update && apt-get install -y python3 build-essential

WORKDIR /app

COPY . .

RUN npm install -g pnpm@8
RUN pnpm install --frozen-lockfile
RUN pnpm build

FROM node:${NODE_VERSION}-slim

WORKDIR /app

ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}

ARG VERSION=develop
ENV VERSION=${VERSION}
LABEL org.opencontainers.image.source https://github.com/KennethWussmann/github-archive

COPY --from=builder /app/build/index.js /app/index.js

CMD [ "index.js" ]
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
services:
github-archive:
build: .
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.0.0",
"description": "",
"scripts": {
"build": "tsc",
"build": "tsc --noEmit && ncc build src/start.ts -o build -m",
"lint": "eslint \"**/*.{ts,tsx}\" --ext .ts",
"lint:fix": "npm run lint -- --fix",
"format": "prettier . --write",
Expand Down
8 changes: 8 additions & 0 deletions src/start.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { rootLogger } from "./utils/logger";

const start = async () => {
rootLogger.info("Starting GitHub archiver");
await new Promise((resolve) => setTimeout(resolve, 100000));
};

void start();
2 changes: 2 additions & 0 deletions src/utils/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,5 @@ export const createLogger = ({
| DailyRotateFile => !!t,
),
});

export const rootLogger = createLogger({ meta: { name: "GitHubArchive" } });
26 changes: 14 additions & 12 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,23 @@
"exactOptionalPropertyTypes": true,
"noFallthroughCasesInSwitch": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
"noUncheckedIndexedAccess": true,
"noUnusedLocals": true,
"noUnusedParameters": true,

"isolatedModules": true,

"checkJs": true,

"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"types": ["node"]
"types": ["node"],
"incremental": true,
"target": "es2019",
"module": "commonjs",
"sourceMap": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true
},
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Strictest",
"_version": "2.0.0"
"include": ["src"],
"$schema": "https://json.schemastore.org/tsconfig"
}

0 comments on commit 5861b1d

Please sign in to comment.