-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from maietta/main
Clean commit for replacement pull request
- Loading branch information
Showing
5 changed files
with
161 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
name: Build release | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
# Publish semver tags as releases. | ||
tags: [ 'v*.*.*' ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
workflow_dispatch: | ||
branches: [ main ] | ||
tags: [ 'v*.*.*' ] | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
# github.repository as <account>/<repo> | ||
IMAGE_NAME: ${{ github.repository }} | ||
|
||
jobs: | ||
buildx: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- | ||
name: Checkout | ||
uses: actions/checkout@v3 | ||
- | ||
name: Set up Docker Buildx | ||
id: buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
# Login against a Docker registry except on PR | ||
# https://github.com/docker/login-action | ||
- name: Log into registry ${{ env.REGISTRY }} | ||
if: github.event_name != 'pull_request' | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
# Extract metadata (tags, labels) for Docker | ||
# https://github.com/docker/metadata-action | ||
- name: Extract Docker metadata | ||
id: meta | ||
uses: docker/metadata-action@v4 | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
|
||
# Build and push Docker image with Buildx (don't push on PR) | ||
# https://github.com/docker/build-push-action | ||
- name: Build and push Docker image | ||
id: build-and-push | ||
uses: docker/build-push-action@v3 | ||
with: | ||
context: . | ||
push: ${{ github.event_name != 'pull_request' }} | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
FROM node:16.16.0-alpine3.16 | ||
|
||
LABEL org.opencontainers.image.source = "https://github.com/caprover/deploy-from-github" | ||
|
||
RUN apk add --no-cache git \ | ||
&& npm i -g caprover \ | ||
&& npm cache clean --force | ||
|
||
COPY entrypoint.sh /entrypoint.sh | ||
|
||
ENTRYPOINT ["sh","/entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,67 @@ | ||
# deploy-from-github | ||
# Deploy from Github | ||
|
||
This Github Action leverages the official Caprover CLI and the App Token strategy to deploy an app directly from Github. | ||
An example workflow provided below, shows how we can automagically create a deploy.tar file as a required part of a build & deployment strategy. | ||
|
||
Using this Github Action requires the following three pieces of information to be entered into Github Secrets for your project repository: | ||
|
||
- APP_NAME secret is the name of your app, exactly as it's specified in Caprover. | ||
- APP_TOKEN secret is obtained fromt he "Deployment" tab of the app in Caprover. Click "Enable App Token" to generate a token. | ||
- CAPROVER_SERVER secret can be organization-wide, per project, or per project override and in the format of https://captain.apps.your-domain.com. | ||
|
||
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. | ||
|
||
``` | ||
name: Build App & Deploy | ||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
jobs: | ||
build-and-deploy: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: [18.x] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
cache: "npm" | ||
- run: npm ci | ||
- run: npm run build --if-present | ||
- run: npm run test --if-present | ||
# Future plans in the works to create tarball from within the caprover/deploy-from-github action. | ||
- uses: a7ul/[email protected] | ||
with: | ||
command: c | ||
cwd: "./" | ||
files: | | ||
backend/ | ||
frontend/dist/ | ||
captain-definition | ||
outPath: deploy.tar | ||
- uses: caprover/deploy-from-github@main | ||
with: | ||
server: '${{ secrets.CAPROVER_SERVER }}' | ||
app: '${{ secrets.APP_NAME }}' | ||
token: '${{ secrets.APP_TOKEN }}' | ||
``` | ||
|
||
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. | ||
|
||
For more information: | ||
|
||
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/. | ||
The example workflow presented on this page was sourced from https://github.com/PremoWeb/SDK-Foundation-Vue/blob/main/.github/workflows/deploy.yml. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: 'Deploy App to Caprover' | ||
description: 'Github Action for deploying your app to Caprover.' | ||
author: 'Caprover Contributors' | ||
|
||
inputs: | ||
server: | ||
description: 'Captover server URL, i.e. https://captain.apps.your-domain.com.' | ||
required: true | ||
token: | ||
description: 'App Token' | ||
required: true | ||
app: | ||
description: 'App Name' | ||
required: true | ||
|
||
runs: | ||
using: 'docker' | ||
image: 'docker://ghcr.io/caprover/deploy-from-github:main' | ||
env: | ||
server: ${{ inputs.server }} | ||
app: ${{ inputs.app }} | ||
token: ${{ inputs.token }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
caprover deploy --appName $INPUT_APP --appToken $INPUT_TOKEN --caproverUrl $INPUT_SERVER --tarFile ./deploy.tar |