Skip to content

Commit

Permalink
Merge pull request #6 from sehyun-hwang/fly-initial
Browse files Browse the repository at this point in the history
Fly initial
  • Loading branch information
sehyun-hwang authored Sep 10, 2023
2 parents aa29028 + 25065a0 commit d0459d3
Show file tree
Hide file tree
Showing 26 changed files with 1,127 additions and 720 deletions.
5 changes: 3 additions & 2 deletions .actrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
--privileged
--container-options --privileged
--container-daemon-socket /run/user/1000/podman/podman.sock
--pull=false
--artifact-server-path act/artifact
-P ubuntu-latest=localhost/act
--env CONTAINER_REGISTRY=nextlab.hwangsehyun.com:41443
-s GITHUB_TOKEN
-e act/pull-target.json
64 changes: 64 additions & 0 deletions .github/workflows/express-ghcr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Build and push express to GHCR


on:
push:
branches-ignore:
- wip/*
paths:
- express/**

workflow_call:
inputs:
service-name:
default: stream
type: string
tag:
required: true
type: string
outputs:
stream-image:
value: ${{ jobs.build-push-ghcr.outputs.stream-image }}


jobs:
build-push-ghcr:
name: Build and push to GHCR
runs-on: ubuntu-latest
env:
TAG: ${{ github.ref_name || inputs.tag }}

permissions:
packages: write

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

- name: docker compose config
id: docker-compose-config
run: >
echo -n stream-image= >> "$GITHUB_OUTPUT"
&& docker compose config --format json | jq .services.stream.image >> "$GITHUB_OUTPUT"
shell: sh

- name: Build a container
run: docker compose build ${{ inputs.service-name || 'express' }}
shell: sh
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- if: ${{ !env.ACT }}
name: Login to GHCR
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Push a container to GHCR
run: docker compose push ${{ inputs.service-name || 'express'}}
shell: sh

outputs:
stream-image: ${{ steps.docker-compose-config.outputs.stream-image }}
37 changes: 0 additions & 37 deletions .github/workflows/ghcr.yml

This file was deleted.

59 changes: 59 additions & 0 deletions .github/workflows/nginx-ghcr-pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Build and push nginx to GHCR, Deploy to Pages


on:
push:
branches-ignore:
- wip/*
paths:
- nginx/**

jobs:
build-push-ghcr:
uses: ./.github/workflows/express-ghcr.yml
with:
tag: ${{ github.ref_name }}

deploy-pages:
needs: build-push-ghcr
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest

permissions:
contents: read
pages: write
id-token: write

steps:
- name: Export static files
run: docker cp $(docker create ${{ needs.build-push-ghcr.outputs.stream-image }}):/var/www/html /tmp/pages
shell: sh

- name: Set API URLs
working-directory: /tmp/pages
run: >
sed -i 's;<script src="./index.js";
<script>\n
var PUB_URL = "https://imshow-express.fly.dev"\;\n
var SUB_URL = "wss://imshow-nginx.fly.dev/ws/imshow"\;\n
</script>\n
<script src="./index.js";'
index.html
&& grep fly.dev index.html
shell: sh

- if: ${{ !env.ACT }}
name: Setup Pages
uses: actions/configure-pages@v3

- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v2
with:
path: /tmp/pages

- if: ${{ !env.ACT }}
name: Deploy Pages
id: deployment
uses: actions/deploy-pages@v2
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules/
dist.js

act/artifact/
*.log
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"eslint.workingDirectories": [
{
"mode": "auto"
}
]
}
5 changes: 4 additions & 1 deletion act/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
FROM node:alpine

COPY --from=docker/compose /usr/local/bin/docker /usr/local/bin/docker-compose /usr/local/bin/
COPY --from=docker:cli /usr/local/bin/docker /usr/local/bin/
COPY --from=docker:cli /usr/local/bin/docker-compose /root/.docker/cli-plugins/

RUN apk add jq tar
2 changes: 1 addition & 1 deletion act/pull-target.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
"ref": "act-base-ref"
}
}
}
}
1 change: 0 additions & 1 deletion act/run.sh

This file was deleted.

23 changes: 16 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,27 @@ version: '3'
services:
express:
image: ${CONTAINER_REGISTRY-ghcr.io/sehyun-hwang}/imshow-express:${TAG:-latest}
build: express
build:
context: express
secrets:
- NODE_AUTH_TOKEN
ports:
- 8080:8080
#volumes:
# - /mnt/node/utils:/mnt/node_modules/utils
environment:
- PORT=8080
- ${EXPRESS_PORT-8889}:80

stream:
image: ${CONTAINER_REGISTRY-ghcr.io/sehyun-hwang}/imshow-nginx:${TAG:-latest}
build: nginx
command:
- sh
- -c
- >
sed -i 's/listen 80/listen 80;listen [::]:80/' /etc/nginx/nginx.conf
&& /usr/local/nginx/sbin/nginx -c /etc/nginx/nginx.conf
depends_on:
- express
ports:
- 8000:80
- ${NGINX_PORT-8888}:80

secrets:
NODE_AUTH_TOKEN:
environment: NODE_AUTH_TOKEN
3 changes: 3 additions & 0 deletions express/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@sehyun-hwang:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${NODE_AUTH_TOKEN}
always-auth=true
20 changes: 15 additions & 5 deletions express/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
FROM node:alpine

WORKDIR /mnt
COPY package.json yarn.lock ./
COPY package.json pnpm-lock.yaml .npmrc ./

RUN yarn add https://www.hwangsehyun.com/node/utils.tar.gz
RUN --mount=type=secret,id=NODE_AUTH_TOKEN corepack enable pnpm \
&& NODE_AUTH_TOKEN=$(cat /run/secrets/NODE_AUTH_TOKEN) pnpm i -P --force --frozen-lockfile \
&& pnpm store prune

RUN echo '#!/bin/sh' > entrypoint.sh \
&& echo exec $(NODE_AUTH_TOKEN= pnpm which express | tee /dev/stderr) '$@' >> entrypoint.sh \
&& chmod +x entrypoint.sh

COPY index.js ./

LABEL express.route=/imshow
LABEL org.opencontainers.image.source https://github.com/sehyun-hwang/imshow
CMD ["node", "node_modules/utils/Express.js", "index.js"]
LABEL express.route=/imshow \
org.opencontainers.image.source=https://github.com/sehyun-hwang/imshow

EXPOSE 80
ENV PORT=80
ENTRYPOINT ["/mnt/entrypoint.sh"]
CMD ["index.js"]
19 changes: 19 additions & 0 deletions express/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import globals from 'globals';

export default [{
languageOptions: {
globals: {
...globals.nodeBuiltin,
}
},
rules: {
'import/no-unresolved': [
'error',
{
ignore: [
'got',
]
}
]
}
}];
15 changes: 15 additions & 0 deletions express/example-svg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { generate } from 'random-words';

const hue = Math.random() * 360;
const text = generate(3).join(' ');

const svg = `<svg version="1.1"
width="300" height="200"
xmlns="http://www.w3.org/2000/svg">
<rect width="100%" height="100%" fill="hsl(${hue}, 100%, 50%)" />
<text x="0" y="125" font-size="100" fill="white">${text}</text>
</svg>`;
process.stderr.write(svg);
process.stderr.write('\n');

console.log(svg);
Loading

0 comments on commit d0459d3

Please sign in to comment.