Skip to content

Commit

Permalink
feat!: release new rust pdf-rendering-srv
Browse files Browse the repository at this point in the history
  • Loading branch information
Vilsol committed Apr 17, 2024
1 parent ac05376 commit 5385e81
Show file tree
Hide file tree
Showing 10 changed files with 165 additions and 36 deletions.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
!Cargo.toml
!src/
!build.rs
!pdf_rendering.proto
!pdf_rendering.proto
!cfg
25 changes: 25 additions & 0 deletions .github/workflows/approve-merge.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Merge Release PR

on:
pull_request_review:
types: [submitted]

jobs:
pr_approved:
if: ${{ github.event.review.state == 'approved' && github.event.pull_request.base.ref == 'master' && github.event.pull_request.head.ref == 'next' }}
runs-on: ubuntu-latest
steps:
- name: Clone git repo
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Merge PR
run: |
git checkout master
git merge --ff origin/next
git push -u origin master
- uses: benc-uk/workflow-dispatch@v1
with:
workflow: release.yaml
ref: master
20 changes: 20 additions & 0 deletions .github/workflows/pr-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: "Lint PR"

on:
pull_request_target:
types:
- opened
- edited
- synchronize

permissions:
pull-requests: read

jobs:
lint:
name: pr-lint
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46 changes: 46 additions & 0 deletions .github/workflows/release-pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Release PR

on:
push:
branches:
- next

permissions:
contents: read

jobs:
release_pr:
permissions:
issues: write
pull-requests: write
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'

- name: Install Dependencies
run: npm clean-install

- name: Generate Changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -ex
echo '# Release Changes' > changes.md
npx [email protected] -d -p '@semantic-release/release-notes-generator' -b next | grep -v semantic-release | tee -a changes.md
printf '\n---\n\n### Approve this PR to release above packages!' >> changes.md
- name: Create PR
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -ex
export PR_NUMBER=$(gh pr list -B master -H next --json number | jq -r '.[0].number')
if [[ "$(git rev-parse origin/master)" == "$(git rev-parse origin/next)" ]]; then exit 0; fi
if [[ "$PR_NUMBER" == "null" ]]; then gh pr create -B master -H next -t "chore: release" -F changes.md; fi
if [[ "$PR_NUMBER" != "null" ]]; then gh pr edit $PR_NUMBER -F changes.md; fi
70 changes: 38 additions & 32 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
name: release
name: Release

on:
push:
tags:
- v*
branches:
- master
workflow_dispatch:

permissions:
contents: read

jobs:
release:
runs-on: ubuntu-20.04
permissions:
contents: write
issues: write
pull-requests: write
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
ref: master

- name: Login to DockerHub
uses: docker/login-action@v1
- uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.CR_PAT }}

- uses: docker/setup-buildx-action@v1
- uses: docker/setup-buildx-action@v3
with:
install: true

Expand All @@ -34,28 +41,27 @@ jobs:
run: |
echo ::set-output name=repo_name::$(echo ${GITHUB_REPOSITORY#*/*})
- name: Docker meta
- uses: docker/metadata-action@v5
id: docker_meta
uses: crazy-max/ghaction-docker-meta@v1
with:
images: |
${{ github.repository }}
ghcr.io/${{ github.repository }}
tag-sha: true
tag-semver: |
{{version}}
{{major}}.{{minor}}
- name: Build and push
uses: docker/build-push-action@v2
images: ${{ github.repository }}

- uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/amd64
push: true
build-args: |
APP_HOME=/home/node/${{ steps.vars.outputs.repo_name }}
cache-from: |
${{ github.repository }}:latest
tags: ${{ steps.docker_meta.outputs.tags }}
load: true
tags: ${{ github.repository }}
labels: ${{ steps.docker_meta.outputs.labels }}

- name: Install Dependencies
run: npm i --no-save @semantic-release-plus/docker

- run: npx [email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- uses: benc-uk/workflow-dispatch@v1
with:
workflow: upgrade-services.yaml
ref: master
repo: restorecommerce/charts
token: "${{ secrets.CHARTS_WORKFLOW_TOKEN }}"
24 changes: 24 additions & 0 deletions .releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"branches": [
"master"
],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/github",
[
"@semantic-release-plus/docker",
{
"name": "docker.io/restorecommerce/pdf-rendering-srv",
"skipLogin": true
}
],
[
"@semantic-release-plus/docker",
{
"name": "ghcr.io/restorecommerce/pdf-rendering-srv",
"skipLogin": true
}
]
]
}
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ RUN cargo chef prepare --recipe-path recipe.json
FROM rust:1.77.2-alpine as build

RUN rustup target add x86_64-unknown-linux-musl
RUN apk add --no-cache build-base pkgconfig dbus-dev libressl-dev protoc
RUN apk add --no-cache build-base pkgconfig dbus-dev libressl-dev protoc protobuf-dev

WORKDIR /app

Expand Down Expand Up @@ -38,6 +38,7 @@ RUN apk add --no-cache chromium
WORKDIR /app

COPY --from=build /app/target/x86_64-unknown-linux-musl/debug/pdf-rendering-srv /app/pdf-rendering-srv
COPY ./cfg /app/cfg

EXPOSE 50051

Expand Down
2 changes: 1 addition & 1 deletion cfg/config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"server": {
"host": "0.0.0.0",
"port": 50069
"port": 50062
},

"s3": {
Expand Down
4 changes: 4 additions & 0 deletions cfg/config_production.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"server": {
"port": 50051
},

"s3": {
"client": {
"endpoint": "http://cloudserver:8000"
Expand Down
4 changes: 3 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ fn logging(req: Request<()>) -> Result<Request<()>, Status> {
fn load_config() -> Config {
let run_mode = env::var("NODE_ENV").unwrap_or_else(|_| "development".into());

info!("Running in mode: {}", run_mode);

Config::builder()
.add_source(config::File::with_name("cfg/config"))
.add_source(File::with_name("cfg/config"))
.add_source(File::with_name(&format!("cfg/config_{}", run_mode)))
.add_source(config::Environment::with_convert_case(Case::Lower).separator("__"))
.build()
Expand Down

0 comments on commit 5385e81

Please sign in to comment.