Skip to content

Commit b829c89

Browse files
committed
Clean commit for replacement pull request
1 parent a07f3a7 commit b829c89

File tree

5 files changed

+161
-1
lines changed

5 files changed

+161
-1
lines changed

.github/workflows/release.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Build release
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
# Publish semver tags as releases.
7+
tags: [ 'v*.*.*' ]
8+
pull_request:
9+
branches: [ main ]
10+
11+
workflow_dispatch:
12+
branches: [ main ]
13+
tags: [ 'v*.*.*' ]
14+
15+
env:
16+
REGISTRY: ghcr.io
17+
# github.repository as <account>/<repo>
18+
IMAGE_NAME: ${{ github.repository }}
19+
20+
jobs:
21+
buildx:
22+
runs-on: ubuntu-latest
23+
steps:
24+
-
25+
name: Checkout
26+
uses: actions/checkout@v3
27+
-
28+
name: Set up Docker Buildx
29+
id: buildx
30+
uses: docker/setup-buildx-action@v2
31+
32+
# Login against a Docker registry except on PR
33+
# https://github.com/docker/login-action
34+
- name: Log into registry ${{ env.REGISTRY }}
35+
if: github.event_name != 'pull_request'
36+
uses: docker/login-action@v2
37+
with:
38+
registry: ${{ env.REGISTRY }}
39+
username: ${{ github.actor }}
40+
password: ${{ secrets.GITHUB_TOKEN }}
41+
42+
# Extract metadata (tags, labels) for Docker
43+
# https://github.com/docker/metadata-action
44+
- name: Extract Docker metadata
45+
id: meta
46+
uses: docker/metadata-action@v4
47+
with:
48+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
49+
50+
# Build and push Docker image with Buildx (don't push on PR)
51+
# https://github.com/docker/build-push-action
52+
- name: Build and push Docker image
53+
id: build-and-push
54+
uses: docker/build-push-action@v3
55+
with:
56+
context: .
57+
push: ${{ github.event_name != 'pull_request' }}
58+
tags: ${{ steps.meta.outputs.tags }}
59+
labels: ${{ steps.meta.outputs.labels }}
60+

Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM node:16.16.0-alpine3.16
2+
3+
LABEL org.opencontainers.image.source = "https://github.com/caprover/deploy-from-github"
4+
5+
RUN apk add --no-cache git \
6+
&& npm i -g caprover \
7+
&& npm cache clean --force
8+
9+
COPY entrypoint.sh /entrypoint.sh
10+
11+
ENTRYPOINT ["sh","/entrypoint.sh"]

README.md

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,67 @@
1-
# deploy-from-github
1+
# Deploy from Github
2+
3+
This Github Action leverages the official Caprover CLI and the App Token strategy to deploy an app directly from Github.
4+
An example workflow provided below, shows how we can automagically create a deploy.tar file as a required part of a build & deployment strategy.
5+
6+
Using this Github Action requires the following three pieces of information to be entered into Github Secrets for your project repository:
7+
8+
- APP_NAME secret is the name of your app, exactly as it's specified in Caprover.
9+
- APP_TOKEN secret is obtained fromt he "Deployment" tab of the app in Caprover. Click "Enable App Token" to generate a token.
10+
- CAPROVER_SERVER secret can be organization-wide, per project, or per project override and in the format of https://captain.apps.your-domain.com.
11+
12+
The example workflow contains a few steps to process your source code into a deployed app in Caprover. The first step uses the a CI/CD version of Node Package Manager (NPM) to build the front-end from source code. The second step packages up your newly minted dist/ directory, the existing backend/ directory and captain-definition file into a deploy.tar file. In the last step the deploy.tar file is picked up by this Github Action and using the provided secrets, will send the file to the Caprover server where it will be deployed.
13+
14+
```
15+
name: Build App & Deploy
16+
17+
on:
18+
push:
19+
branches: [ "main" ]
20+
21+
pull_request:
22+
branches: [ "main" ]
23+
24+
jobs:
25+
build-and-deploy:
26+
runs-on: ubuntu-latest
27+
28+
strategy:
29+
matrix:
30+
node-version: [18.x]
31+
32+
steps:
33+
- uses: actions/checkout@v3
34+
- name: Use Node.js ${{ matrix.node-version }}
35+
uses: actions/setup-node@v3
36+
with:
37+
node-version: ${{ matrix.node-version }}
38+
cache: "npm"
39+
- run: npm ci
40+
- run: npm run build --if-present
41+
- run: npm run test --if-present
42+
43+
# Future plans in the works to create tarball from within the caprover/deploy-from-github action.
44+
- uses: a7ul/[email protected]
45+
with:
46+
command: c
47+
cwd: "./"
48+
files: |
49+
backend/
50+
frontend/dist/
51+
captain-definition
52+
outPath: deploy.tar
53+
54+
- uses: caprover/deploy-from-github@main
55+
with:
56+
server: '${{ secrets.CAPROVER_SERVER }}'
57+
app: '${{ secrets.APP_NAME }}'
58+
token: '${{ secrets.APP_TOKEN }}'
59+
60+
```
61+
62+
NOTE: Deployments take place within seconds after the workflow has been processed succesfully with any failed deployments sending an email alert to your email on file with Github.
63+
64+
For more information:
65+
66+
A complete Vue 3 frontend starter project that includes a PHP backend that uses this Github Action can be found at https://github.com/PremoWeb/SDK-Foundation-Vue/.
67+
The example workflow presented on this page was sourced from https://github.com/PremoWeb/SDK-Foundation-Vue/blob/main/.github/workflows/deploy.yml.

action.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: 'Deploy App to Caprover'
2+
description: 'Github Action for deploying your app to Caprover.'
3+
author: 'Caprover Contributors'
4+
5+
inputs:
6+
server:
7+
description: 'Captover server URL, i.e. https://captain.apps.your-domain.com.'
8+
required: true
9+
token:
10+
description: 'App Token'
11+
required: true
12+
app:
13+
description: 'App Name'
14+
required: true
15+
16+
runs:
17+
using: 'docker'
18+
image: 'docker://ghcr.io/caprover/deploy-from-github:main'
19+
env:
20+
server: ${{ inputs.server }}
21+
app: ${{ inputs.app }}
22+
token: ${{ inputs.token }}

entrypoint.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
caprover deploy --appName $INPUT_APP --appToken $INPUT_TOKEN --caproverUrl $INPUT_SERVER --tarFile ./deploy.tar

0 commit comments

Comments
 (0)