Update environment variables on deployment
This commit is contained in:
parent
7244fb1d53
commit
3a39f967ef
5
.env
5
.env
@ -1,5 +1,6 @@
|
|||||||
ASTRO_URL=http://localhost:3000
|
ASTRO_HOST=localhost:3000
|
||||||
PAYLOAD_URL=http://localhost:3001
|
PAYLOAD_HOST=payload:3001
|
||||||
|
PAYLOAD_SERVER_URL=http://localhost:3001
|
||||||
PAYLOAD_PORT=3001
|
PAYLOAD_PORT=3001
|
||||||
PAYLOAD_SECRET=supersecretkey
|
PAYLOAD_SECRET=supersecretkey
|
||||||
MONGODB_URI=mongodb://payload:test@mongo:27017
|
MONGODB_URI=mongodb://payload:test@mongo:27017
|
||||||
|
66
.github/workflows/push.yml
vendored
66
.github/workflows/push.yml
vendored
@ -1,38 +1,72 @@
|
|||||||
name: Clone or pull repository
|
name: Code Deployment and Environment Setup
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
name: Run remote SSH command
|
name: Run remote SSH commands
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Trigger build via ssh
|
- name: Clone or pull repository
|
||||||
uses: appleboy/ssh-action@master
|
uses: appleboy/ssh-action@v0.1.10
|
||||||
with:
|
with:
|
||||||
host: ${{ secrets.HOST }}
|
host: ${{ secrets.HOST }}
|
||||||
username: ${{ secrets.USER }}
|
username: ${{ secrets.USER }}
|
||||||
key: ${{ secrets.KEY }}
|
key: ${{ secrets.KEY }}
|
||||||
|
script_stop: false
|
||||||
script: |
|
script: |
|
||||||
if [ -d ${{ secrets.PATH }} ]; then
|
if [ -d ${{ secrets.PATH }} ]; then
|
||||||
cd ${{ secrets.PATH }}
|
cd ${{ secrets.PATH }}
|
||||||
git pull
|
git pull
|
||||||
else
|
else
|
||||||
mkdir ${{ secrets.PATH }}
|
mkdir -p ${{ secrets.PATH }}
|
||||||
cd ${{ secrets.PATH }}
|
cd ${{ secrets.PATH }}
|
||||||
git clone https://github.com/${{ github.repository }} .
|
git clone https://github.com/${{ github.repository }} .
|
||||||
sed -i "s/ASTRO_URL=.*/ASTRO_URL=${{ vars.ASTRO_URL }}/" .env
|
|
||||||
sed -i "s/PAYLOAD_URL=.*/PAYLOAD_URL=${{ vars.PAYLOAD_URL }}/" .env
|
|
||||||
sed -i "s/PAYLOAD_PORT=.*/PAYLOAD_PORT=${{ secrets.PAYLOAD_PORT }}/" .env
|
|
||||||
sed -i "s/PAYLOAD_SECRET=.*/PAYLOAD_SECRET=${{ secrets.PAYLOAD_SECRET }}/" .env
|
|
||||||
sed -i "s/MONGODB_URI=.*/MONGODB_URI=${{ secrets.MONGODB_URI }}/" .env
|
|
||||||
sed -i "s/MONGODB_USER=.*/MONGODB_USER=${{ secrets.MONGODB_USER }}/" .env
|
|
||||||
sed -i "s/MONGODB_PW=.*/MONGODB_PW=${{ secrets.MONGODB_PW }}/" .env
|
|
||||||
sed -i "s/TOKEN=.*/TOKEN=${{ secrets.TOKEN }}/" .env
|
|
||||||
sed -i "s/NAME=.*/NAME=${{ vars.NAME }}/" .env
|
|
||||||
cp .env ./astro/.env
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
- name: Update environment variables
|
||||||
|
uses: appleboy/ssh-action@v0.1.10
|
||||||
|
with:
|
||||||
|
host: ${{ secrets.HOST }}
|
||||||
|
username: ${{ secrets.USER }}
|
||||||
|
key: ${{ secrets.KEY }}
|
||||||
|
script_stop: false
|
||||||
|
script: |
|
||||||
|
# Bash function to replace env variables
|
||||||
|
replace_env() {
|
||||||
|
local env_var=$1
|
||||||
|
local new_value=$2
|
||||||
|
local file=$3
|
||||||
|
sed -i "s/${env_var}=.*/${env_var}=${new_value}/" $file
|
||||||
|
}
|
||||||
|
|
||||||
|
cd ${{ secrets.PATH }}
|
||||||
|
|
||||||
|
# Replace .env with vars
|
||||||
|
replace_env 'NAME' '${{ vars.NAME }}' .env
|
||||||
|
replace_env 'ASTRO_HOST' '${{ vars.ASTRO_HOST }}' .env
|
||||||
|
replace_env 'PAYLOAD_HOST' '${{ vars.PAYLOAD_HOST }}' .env
|
||||||
|
replace_env 'PAYLOAD_SERVER_URL' '${{ vars.PAYLOAD_SERVER_URL }}' .env
|
||||||
|
replace_env 'PAYLOAD_PORT' '${{ vars.PAYLOAD_PORT }}' .env
|
||||||
|
|
||||||
|
# Replace .env with secrets
|
||||||
|
replace_env 'PAYLOAD_SECRET' '${{ secrets.PAYLOAD_SECRET }}' .env
|
||||||
|
replace_env 'MONGODB_URI' '${{ secrets.MONGODB_URI }}' .env
|
||||||
|
replace_env 'MONGODB_USER' '${{ secrets.MONGODB_USER }}' .env
|
||||||
|
replace_env 'MONGODB_PW' '${{ secrets.MONGODB_PW }}' .env
|
||||||
|
replace_env 'TOKEN' '${{ secrets.TOKEN }}' .env
|
||||||
|
|
||||||
|
# mkdir -p ./astro
|
||||||
|
# cp .env ./astro/.env
|
||||||
|
|
||||||
|
- name: Start Production Services
|
||||||
|
uses: appleboy/ssh-action@v0.1.10
|
||||||
|
with:
|
||||||
|
host: ${{ secrets.HOST }}
|
||||||
|
username: ${{ secrets.USER }}
|
||||||
|
key: ${{ secrets.KEY }}
|
||||||
|
script: |
|
||||||
|
cd ${{ secrets.PATH }}
|
||||||
yarn prod payload
|
yarn prod payload
|
||||||
sleep 10
|
|
||||||
yarn prod astro
|
yarn prod astro
|
||||||
|
@ -16,7 +16,6 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- ./payload/src:/base/src
|
- ./payload/src:/base/src
|
||||||
- ./astro/src/types.ts:/types.ts
|
- ./astro/src/types.ts:/types.ts
|
||||||
- ./data/media:/base/dist/media
|
|
||||||
ports:
|
ports:
|
||||||
- 3001:3001
|
- 3001:3001
|
||||||
|
|
||||||
|
@ -5,8 +5,6 @@ services:
|
|||||||
target: prod
|
target: prod
|
||||||
environment:
|
environment:
|
||||||
PAYLOAD_URL: ${PAYLOAD_URL}
|
PAYLOAD_URL: ${PAYLOAD_URL}
|
||||||
volumes:
|
|
||||||
- ./data/media:/prod/dist/media
|
|
||||||
labels:
|
labels:
|
||||||
- "traefik.enable=true"
|
- "traefik.enable=true"
|
||||||
- "traefik.http.routers.${NAME}-astro.rule=Host(`${ASTRO_URL}`)"
|
- "traefik.http.routers.${NAME}-astro.rule=Host(`${ASTRO_URL}`)"
|
||||||
@ -37,6 +35,8 @@ services:
|
|||||||
build:
|
build:
|
||||||
context: payload
|
context: payload
|
||||||
target: prod
|
target: prod
|
||||||
|
volumes:
|
||||||
|
- ./data/media:/prod/dist/media
|
||||||
labels:
|
labels:
|
||||||
- traefik.enable=true
|
- traefik.enable=true
|
||||||
- traefik.http.routers.${NAME}-payload.rule=Host(`${PAYLOAD_URL}`)
|
- traefik.http.routers.${NAME}-payload.rule=Host(`${PAYLOAD_URL}`)
|
||||||
|
@ -5,7 +5,7 @@ import Users from "./collections/Users";
|
|||||||
import Media from "./collections/Media";
|
import Media from "./collections/Media";
|
||||||
|
|
||||||
export default buildConfig({
|
export default buildConfig({
|
||||||
serverURL: process.env.PAYLOAD_URL,
|
serverURL: process.env.PAYLOAD_SERVER_URL,
|
||||||
admin: {
|
admin: {
|
||||||
user: Users.slug,
|
user: Users.slug,
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user