Skip to content

Commit

Permalink
all in one image (#2)
Browse files Browse the repository at this point in the history
* update
  • Loading branch information
swuecho authored May 11, 2023
1 parent ab2e2ca commit 87ff814
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 48 deletions.
55 changes: 10 additions & 45 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ env:
PG_PASS: thisisapassword

jobs:
build_chat:
build_logbook:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -21,54 +21,19 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: "16.x"

- name: build web
run: |
npm install
npm run build
yarn install
yarn build
working-directory: web
- name: Set up dotnet
uses: actions/setup-go@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
go-version: 1.19
- name: Build API
run: go build -v ./...
working-directory: api
- name: Test API
run: go test -v ./...
dotnet-version: "7.0.x"
- name: Restore dependencies
run: dotnet restore
working-directory: api
- name: Build Chat image
- name: Build logbook image
run: |
docker build . --file Dockerfile -t ghcr.io/swuecho/logbook:${GITHUB_SHA}
- name: change docker image tag
run: python scripts/replace_tag_to_test.py ${GITHUB_SHA}

- name: docker-compose
run: docker-compose up -d

- name: show docker ps
run: docker-compose ps

- name: show docker logs
run: docker-compose logs

# Setup cache for node_modules
- name: Cache node modules
uses: actions/cache@v3
with:
path: e2e/node_modules
key: ${{ runner.os }}-node-${{ hashFiles('e2e/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
run: npm ci
working-directory: e2e

- name: Install playwright browsers
run: npx playwright install --with-deps
working-directory: e2e

- run: npx playwright test
working-directory: e2e
working-directory: api
51 changes: 51 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Publish

on:
push:
tags:
- "v*"

jobs:
build_api:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: "16.x"

- name: build web
run: |
npm install
npm run build
working-directory: web
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
- name: Restore dependencies
run: dotnet restore
working-directory: api
# use root folder docker
- name: Build logbook image
run: |
docker build . --file Dockerfile -t ghcr.io/swuecho/logbook:${GITHUB_REF#refs/tags/}
- name: Login to GitHub Container Registry
run: echo "${{ secrets.GHCR_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Push API image to GitHub Container Registry
run: |
docker push ghcr.io/swuecho/logbook:${GITHUB_REF#refs/tags/}
docker tag ghcr.io/swuecho/logbook:${GITHUB_REF#refs/tags/} ghcr.io/swuecho/logbook:latest
docker push ghcr.io/swuecho/logbook:latest
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: push to docker
run: |
docker tag ghcr.io/swuecho/logbook:${GITHUB_REF#refs/tags/} echowuhao/logbook:${GITHUB_REF#refs/tags/}
docker tag ghcr.io/swuecho/logbook:${GITHUB_REF#refs/tags/} echowuhao/logbook:latest
docker push echowuhao/logbook:${GITHUB_REF#refs/tags/}
docker push echowuhao/logbook:latest
2 changes: 1 addition & 1 deletion api/Database.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Config =
/// Custom operator for combining paths
let postgresDSN =
try
System.Environment.GetEnvironmentVariable("BESTQA_PG_DSN")
System.Environment.GetEnvironmentVariable("DATABASE_URL")
with _ -> raise (System.Exception "check if BESTQA_FS_PORT is set")
let connection () = postgresDSN |> Sql.connect

Expand Down
4 changes: 2 additions & 2 deletions api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/dotnet/sdk:5.0-alpine3.12 AS build
FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine3.17 AS build

# build application
WORKDIR /src
Expand All @@ -8,7 +8,7 @@ RUN dotnet restore
RUN dotnet publish -c release -o /app --no-self-contained --no-restore

# final stage/image
FROM mcr.microsoft.com/dotnet/aspnet:5.0-alpine3.12
FROM mcr.microsoft.com/dotnet/aspnet:7.0-alpine3.17
ENV TZ=Asia/Shanghai
WORKDIR /app
# copy Resource folder
Expand Down
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: "3"
services:
web:
image: echowuhao/logbook:latest
environment:
DATABASE_URL: db url
ports:
- "5000:5000"

0 comments on commit 87ff814

Please sign in to comment.