Skip to content

Commit d3d545e

Browse files
committed
feat(): Bake a docker and deploy
1 parent 7f43986 commit d3d545e

File tree

15 files changed

+228
-11
lines changed

15 files changed

+228
-11
lines changed

.github/workflows/release.yml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: Service Release
2+
3+
on:
4+
push:
5+
branches: [dev]
6+
7+
jobs:
8+
docker:
9+
runs-on: ubuntu-latest
10+
name: Push docker image
11+
steps:
12+
- name: App version
13+
run: echo Picked the app version ${{ github.sha }}
14+
15+
- name: Checkout
16+
uses: actions/checkout@v2.3.4
17+
18+
- uses: actions/setup-node@v2
19+
with:
20+
node-version: '14.17.6'
21+
22+
- name: Publish to Registry
23+
uses: docker/build-push-action@v1
24+
with:
25+
registry: docker.pkg.github.com
26+
username: ${{ github.actor }}
27+
password: ${{ secrets.GITHUB_TOKEN }}
28+
repository: '${{ github.actor }}/n0th1ng-else.github.io/n0th1ng-else-blog'
29+
tag_with_sha: true
30+
build_args: APP_VERSION=${{ github.sha }},GH_AUTHOR_LOGIN=${{ secrets.GH_AUTHOR_LOGIN }},GH_AUTHOR_LINKED_IN=${{ secrets.GH_AUTHOR_LINKED_IN }},GH_AUTHOR_TELEGRAM=${{ secrets.GH_AUTHOR_TELEGRAM }},GH_AUTHOR_MEDIUM=${{ secrets.GH_AUTHOR_MEDIUM }},GH_AUTHOR_HABR=${{ secrets.GH_AUTHOR_HABR }},GH_AUTHOR_NPM=${{ secrets.GH_AUTHOR_NPM }},GH_AUTHOR_TWITTER=${{ secrets.GH_AUTHOR_TWITTER }},GH_AUTHOR_DEVTO=${{ secrets.GH_AUTHOR_DEVTO }}
31+
32+
heroku:
33+
runs-on: ubuntu-latest
34+
name: Deploy to Heroku
35+
steps:
36+
- name: Fetch the last commit in the PR
37+
id: sha
38+
uses: actions/github-script@v4
39+
with:
40+
result-encoding: string
41+
script: |
42+
const { owner, repo, number } = context.issue;
43+
const pr = await github.pulls.get({
44+
owner,
45+
repo,
46+
pull_number: number,
47+
});
48+
return pr.data.head.sha
49+
50+
- name: App version
51+
run: echo Picked the app version ${{ github.sha }}
52+
53+
- name: Checkout
54+
uses: actions/checkout@v2.3.4
55+
56+
- uses: actions/setup-node@v2
57+
with:
58+
node-version: '14.17.6'
59+
60+
- name: Docker login
61+
run: echo ${{ env.D_PWD }} | docker login --username=${{ env.D_LOGIN }} ${{ env.D_REGISTRY }} --password-stdin
62+
env:
63+
D_LOGIN: ${{ secrets.HEROKU_EMAIL }}
64+
D_PWD: ${{ secrets.HEROKU_API_KEY }}
65+
D_REGISTRY: registry.heroku.com
66+
67+
- name: Push docker image
68+
run: |
69+
heroku container:${{ env.D_ACTION }} web --app ${{ env.D_NAME }} --arg \
70+
APP_VERSION=${{ env.D_VERSION }},\
71+
GH_AUTHOR_LOGIN=${{ secrets.GH_AUTHOR_LOGIN }},\
72+
GH_AUTHOR_LINKED_IN=${{ secrets.GH_AUTHOR_LINKED_IN }},\
73+
GH_AUTHOR_TELEGRAM=${{ secrets.GH_AUTHOR_TELEGRAM }},\
74+
GH_AUTHOR_MEDIUM=${{ secrets.GH_AUTHOR_MEDIUM }},\
75+
GH_AUTHOR_HABR=${{ secrets.GH_AUTHOR_HABR }},\
76+
GH_AUTHOR_NPM=${{ secrets.GH_AUTHOR_NPM }},\
77+
GH_AUTHOR_TWITTER=${{ secrets.GH_AUTHOR_TWITTER }},\
78+
GH_AUTHOR_DEVTO=${{ secrets.GH_AUTHOR_DEVTO }}
79+
env:
80+
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
81+
D_ACTION: push
82+
D_NAME: ${{ secrets.HEROKU_APP_NAME }}
83+
D_VERSION: ${{ github.sha }}
84+
85+
- name: Release docker image
86+
run: heroku container:${{ env.D_ACTION }} web --app ${{ env.D_NAME }}
87+
env:
88+
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
89+
D_ACTION: release
90+
D_NAME: ${{ secrets.HEROKU_APP_NAME }}
91+
92+
- name: Sleep for around 1 minute
93+
run: sleep 60s
94+
shell: bash
95+
96+
- name: Toggle healthcheck handler
97+
uses: fjogeleit/http-request-action@master
98+
with:
99+
url: https://${{ secrets.HEROKU_APP_NAME }}.herokuapp.com/status
100+
method: GET

Dockerfile

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
FROM node:14.17.6
2+
3+
EXPOSE 8080
4+
5+
ENV NODE_ENV production
6+
7+
ARG APP_DIR=/usr/src/app/
8+
9+
RUN mkdir -p $APP_DIR
10+
WORKDIR $APP_DIR
11+
12+
ARG GH_AUTHOR_LOGIN
13+
ENV GH_AUTHOR_LOGIN ${GH_AUTHOR_LOGIN}
14+
15+
ARG GH_AUTHOR_LINKED_IN
16+
ENV GH_AUTHOR_LINKED_IN ${GH_AUTHOR_LINKED_IN}
17+
18+
ARG GH_AUTHOR_TELEGRAM
19+
ENV GH_AUTHOR_TELEGRAM ${GH_AUTHOR_TELEGRAM}
20+
21+
ARG GH_AUTHOR_MEDIUM
22+
ENV GH_AUTHOR_MEDIUM ${GH_AUTHOR_MEDIUM}
23+
24+
ARG GH_AUTHOR_HABR
25+
ENV GH_AUTHOR_HABR ${GH_AUTHOR_HABR}
26+
27+
ARG GH_AUTHOR_NPM
28+
ENV GH_AUTHOR_NPM ${GH_AUTHOR_NPM}
29+
30+
ARG GH_AUTHOR_TWITTER
31+
ENV GH_AUTHOR_TWITTER ${GH_AUTHOR_TWITTER}
32+
33+
ARG GH_AUTHOR_DEVTO
34+
ENV GH_AUTHOR_DEVTO ${GH_AUTHOR_DEVTO}
35+
36+
COPY package.json package-lock.json $APP_DIR
37+
RUN npm ci --include=dev --also=dev && npm cache clean --force
38+
39+
COPY . $APP_DIR
40+
41+
ARG APP_VERSION=local
42+
ENV APP_VERSION ${APP_VERSION}
43+
ENV COMMIT_HASH ${APP_VERSION}
44+
45+
RUN echo ${APP_VERSION}
46+
47+
RUN npm run meta
48+
49+
RUN npm run build
50+
51+
RUN find $APP_DIR/src -type f | xargs -L1 rm -f
52+
53+
CMD ["npm", "start"]

env.js renamed to env.cjs

File renamed without changes.

info.js renamed to info.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const fs = require('fs');
22
const path = require('path');
3-
const Logger = require('./log');
3+
const Logger = require('./log.cjs');
44

55
const logger = new Logger('info');
66

links.js renamed to links.cjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
const https = require('https');
22
const crypto = require('crypto');
33
const slug = require('slug');
4-
const { saveMetaToFile } = require('./info');
5-
const { resources, procEnv } = require('./env');
6-
const Logger = require('./log');
4+
const { saveMetaToFile } = require('./info.cjs');
5+
const { resources, procEnv } = require('./env.cjs');
6+
const Logger = require('./log.cjs');
77
const metascraper = require('metascraper')([
88
require('metascraper-author')(),
99
require('metascraper-date')(),

log.js renamed to log.cjs

File renamed without changes.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"typescript": "4.3.5"
4646
},
4747
"scripts": {
48-
"meta": "node links.js",
48+
"meta": "node links.cjs",
4949
"format": "prettier --write",
5050
"format:check": "prettier --check .",
5151
"lint": "eslint",

src/components/Footer.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import { getVersion } from '../helpers/version';
1010
1111
export let showFCP: boolean;
12-
const version = getVersion();
12+
const version = `v${getVersion()}`;
1313
const year = getCurrentYear();
1414
1515
let fcp = '';

src/helpers/log.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
export class Logger {
22
constructor(private readonly context: string) {}
33

4+
public warn<Data>(msg: string, data?: Data): void {
5+
const ctx = this.getContext();
6+
// eslint-disable-next-line no-console
7+
console.warn(ctx, msg, data || '');
8+
}
9+
410
public error(msg: string, err: Error): void {
511
const ctx = this.getContext();
612
// eslint-disable-next-line no-console

src/helpers/selectors.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ export const getArticles = (): LinkInfo[] => runtime.publications;
99
export const getAccounts = (): ProfileAccounts => runtime.env.accounts;
1010

1111
export const getVersion = (): string => runtime.env.version ?? '';
12+
13+
export const isProduction = (): boolean => runtime.env.mode === 'production';

0 commit comments

Comments
 (0)