Skip to content

Commit

Permalink
Merge pull request #10 from runtimeverification/ci
Browse files Browse the repository at this point in the history
update path
  • Loading branch information
asavienko authored Nov 1, 2023
2 parents 9ef4ec6 + 3ba1283 commit 89f0f1e
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 23 deletions.
55 changes: 42 additions & 13 deletions .github/workflows/build-deploy-by-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:
NGINX_SSL_TEMPLATE_CONFIG: ${{ steps.process-outputs.outputs.NGINX_SSL_TEMPLATE_CONFIG }}
IMAGE_PREFIX: ${{ steps.process-outputs.outputs.IMAGE_PREFIX }}
IMAGE_TAG: ${{ steps.process-outputs.outputs.IMAGE_TAG }}
DB_PORT: ${{ steps.process-outputs.outputs.DB_PORT }}
DB_NAME: ${{ steps.process-outputs.outputs.DB_NAME }}
steps: # - name: Get GitHub payload
# env:
# GITHUB_CONTEXT: ${{ toJson(vars) }}
Expand All @@ -33,6 +35,11 @@ jobs:
BACKEND_PORT=$(printf "%d" $(expr 15000 + $PULL_REQUEST_NUMBER))
HOST=$(printf "pr-%s.%s" ${{ github.event.number }} ${{ vars.HOST }})
IMAGE_TAG=$(printf "pr-%s" ${{ github.event.number }})
DB_PORT=$(printf "%d" $(expr 20000 + $PULL_REQUEST_NUMBER))
DB_NAME=$(printf "simbolik-db-pr-%s" $PULL_REQUEST_NUMBER)
echo "HOST=$HOST" >> $GITHUB_OUTPUT
echo "DB_PORT=$DB_PORT" >> $GITHUB_OUTPUT
echo "DB_NAME=$DB_NAME" >> $GITHUB_OUTPUT
echo "FRONTEND_PORT=$FRONTEND_PORT" >> $GITHUB_OUTPUT
echo "BACKEND_PORT=$BACKEND_PORT" >> $GITHUB_OUTPUT
echo "HOST=$HOST" >> $GITHUB_OUTPUT
Expand Down Expand Up @@ -95,8 +102,8 @@ jobs:
script: |
source "/home/ubuntu/.acme.sh/acme.sh.env"
PULL_REQUEST_NAME=$(printf "pr-%s" ${{ github.event.number }})
mkdir -p /opt/deployments/simbolik-$PULL_REQUEST_NAME
cd /opt/deployments/simbolik-$PULL_REQUEST_NAME
mkdir -p ~/opt/deployments/simbolik-$PULL_REQUEST_NAME
cd ~/opt/deployments/simbolik-$PULL_REQUEST_NAME
# Frontend
docker pull ${{ needs.build.outputs.IMAGE_PREFIX }}/frontend:$PULL_REQUEST_NAME
Expand All @@ -109,14 +116,36 @@ jobs:
-e RECAPTCHA_SITE_KEY=${{ secrets.RECAPTCHA_SITE_KEY }} \
${{ needs.build.outputs.IMAGE_PREFIX }}/frontend:$PULL_REQUEST_NAME
#DB
docker pull postgres
docker stop ${{ needs.build.outputs.DB_NAME }} || true
docker rm ${{ needs.build.outputs.DB_NAME }} || true
docker network create ${{ needs.build.outputs.DB_NAME }}
docker run -p ${{ needs.build.outputs.DB_PORT }}:5432 \
--name ${{ needs.build.outputs.DB_NAME }} \
-d --restart=always \
--network=${{ needs.build.outputs.DB_NAME }} \
-e POSTGRES_USER=${{ secrets.DB_USER }} \
-e POSTGRES_PASSWORD=${{ secrets.DB_PASSWORD }} \
-e POSTGRES_DB=${{ secrets.DB_NAME }} \
postgres
# Backend
docker pull ${{ needs.build.outputs.IMAGE_PREFIX }}/backend:$PULL_REQUEST_NAME
docker stop simbolik-backend-$PULL_REQUEST_NAME
docker rm simbolik-backend-$PULL_REQUEST_NAME
docker run -p ${{ needs.build.outputs.BACKEND_PORT }}:8080 \
--name simbolik-backend-$PULL_REQUEST_NAME \
-d --restart=always \
-e DATABASE_URL="postgresql://${{ secrets.POSTGRES_USER }}:${{ secrets.POSTGRES_PASSWORD }}@${{ secrets.POSTGRES_HOST }}:${{ secrets.POSTGRES_PORT }}/simbolik?schema=$PULL_REQUEST_NAME&connection_limit=40&pool_timeout=30" \
--network=${{ needs.build.outputs.DB_NAME }} \
-e DATABASE_URL="postgresql://${{ secrets.DB_USER }}:${{ secrets.DB_PASSWORD }}@${{ needs.build.outputs.DB_NAME }}/simbolik?schema=$PULL_REQUEST_NAME&connection_limit=40&pool_timeout=30" \
-e FRONTEND_URL=https://${{ needs.build.outputs.HOST }} \
-e GITHUB_CLIENT_ID=${{ secrets.GH_CLIENT_ID }} \
-e GITHUB_CLIENT_SECRET=${{ secrets.GH_CLIENT_SECRET }} \
Expand All @@ -132,22 +161,22 @@ jobs:
${{ needs.build.outputs.IMAGE_PREFIX }}/backend:$PULL_REQUEST_NAME
# Nginx
mkdir -p /opt/deployments/nginx/www
mkdir -p /opt/deployments/nginx/conf.d
mkdir -p /opt/deployments/nginx/ssl/${{ needs.build.outputs.HOST }}
cd /opt/deployments/nginx
docker stop nginx-root
docker rm nginx-root
mkdir -p ~/opt/deployments/nginx/www
mkdir -p ~/opt/deployments/nginx/conf.d
mkdir -p ~/opt/deployments/nginx/ssl/${{ needs.build.outputs.HOST }}
cd ~/opt/deployments/nginx
echo '${{ needs.build.outputs.NGINX_MAIN_CONFIG }}' > ./nginx.conf
echo '${{ needs.build.outputs.NGINX_NO_SSL_TEMPLATE_CONFIG }}' > ./conf.d/${{ needs.build.outputs.HOST }}.conf
docker stop nginx-root
docker rm nginx-root
docker run -p 80:80 -p 443:443 \
--net=host \
--name nginx-root \
-d --restart=always \
-v ./conf.d:/etc/nginx/conf.d \
-v ./nginx.conf:/etc/nginx/nginx.conf \
-v ./www:/var/www \
-v ./ssl:/etc/nginx/ssl \
-v $PWD/conf.d:/etc/nginx/conf.d \
-v $PWD/nginx.conf:/etc/nginx/nginx.conf \
-v $PWD/www:/var/www \
-v $PWD/ssl:/etc/nginx/ssl \
nginx:alpine
## Issue and install SSL certificate
/home/ubuntu/.acme.sh/acme.sh --issue \
Expand Down
22 changes: 14 additions & 8 deletions .github/workflows/build-deploy-by-push-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ jobs:
port: 22
script: |
source "/home/ubuntu/.acme.sh/acme.sh.env"
mkdir -p /opt/deployments/simbolik-${{ github.ref_name }}
cd /opt/deployments/simbolik-${{ github.ref_name }}
mkdir -p ~/opt/deployments/simbolik-${{ github.ref_name }}
cd ~/opt/deployments/simbolik-${{ github.ref_name }}
# Frontend
docker tag ${{ needs.build.outputs.IMAGE_PREFIX }}/frontend:${{ github.ref_name }} ${{ needs.build.outputs.IMAGE_PREFIX }}/frontend:${{ github.ref_name }}-backup
Expand All @@ -95,7 +95,13 @@ jobs:
-e GRAPHQL_ENDPOINT=https://${{ needs.build.outputs.HOST }}/graphql \
-e RECAPTCHA_SITE_KEY=${{ secrets.RECAPTCHA_SITE_KEY }} \
${{ needs.build.outputs.IMAGE_PREFIX }}/frontend:${{ github.ref_name }}
DATABASE_URL=$(printf "postgresql://%s:%s@%s/%s/simbolik?schema=${{ github.ref_name }}&connection_limit=40&pool_timeout=30" \
${{ secrets.DB_USER }} \
${{ secrets.DB_PASSWORD }} \
${{ secrets.DB_HOST_PORT }} \
${{ secrets.DB_NAME }})
# Backend
docker tag ${{ needs.build.outputs.IMAGE_PREFIX }}/backend:${{ github.ref_name }} ${{ needs.build.outputs.IMAGE_PREFIX }}/backend:${{ github.ref_name }}-backup
docker pull ${{ needs.build.outputs.IMAGE_PREFIX }}/backend:${{ github.ref_name }}
Expand All @@ -104,7 +110,7 @@ jobs:
docker run -p ${{ needs.build.outputs.BACKEND_PORT }}:8080 \
--name simbolik-backend-${{ github.ref_name }} \
-d --restart=always \
-e DATABASE_URL="postgresql://${{ secrets.POSTGRES_USER }}:${{ secrets.POSTGRES_PASSWORD }}@${{ secrets.POSTGRES_HOST }}:${{ secrets.POSTGRES_PORT }}/simbolik?schema=${{ github.ref_name }}&connection_limit=40&pool_timeout=30" \
-e DATABASE_URL=$DATABASE_URL \
-e FRONTEND_URL=https://${{ needs.build.outputs.HOST }} \
-e GITHUB_CALLBACK_HOST=${{ needs.build.outputs.HOST }} \
-e GITHUB_CLIENT_ID=${{ secrets.GH_CLIENT_ID }} \
Expand All @@ -120,10 +126,10 @@ jobs:
${{ needs.build.outputs.IMAGE_PREFIX }}/backend:${{ github.ref_name }}
# Nginx
mkdir -p /opt/deployments/nginx/www
mkdir -p /opt/deployments/nginx/conf.d
mkdir -p /opt/deployments/nginx/ssl/${{ needs.build.outputs.HOST }}
cd /opt/deployments/nginx
mkdir -p ~/opt/deployments/nginx/www
mkdir -p ~/opt/deployments/nginx/conf.d
mkdir -p ~/opt/deployments/nginx/ssl/${{ needs.build.outputs.HOST }}
cd ~/opt/deployments/nginx
docker stop nginx-root
docker rm nginx-root
echo '${{ needs.build.outputs.NGINX_MAIN_CONFIG }}' > ./nginx.conf
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/close-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ jobs:
docker rm simbolik-frontend-$PULL_REQUEST_NAME
docker stop simbolik-backend-$PULL_REQUEST_NAME
docker rm simbolik-backend-$PULL_REQUEST_NAME
rm -rfv /opt/deployments/simbolik-${PULL_REQUEST_NAME}
cd /opt/deployments/nginx
rm -rfv ~/opt/deployments/simbolik-${PULL_REQUEST_NAME}
cd ~/opt/deployments/nginx
rm -rfv ./conf.d/${{ steps.process-outputs.outputs.HOST }}.conf
rm -rfv ./ssl/${{ steps.process-outputs.outputs.HOST }}
rm -rfv ./www/${{ steps.process-outputs.outputs.HOST }}
Expand Down
2 changes: 2 additions & 0 deletions frontend/pages/access-token.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import { useEffect } from 'react';
*/
export default function AccessTokenPage() {
const { token } = useRouter().query;
const router = useRouter();

useEffect(() => {
if (!token) {
return;
}

localStorage.setItem('token', token as string);
router.push('/account');
}, [token]);

return (
Expand Down

0 comments on commit 89f0f1e

Please sign in to comment.