-
Notifications
You must be signed in to change notification settings - Fork 2
Set up CD to staging #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
787a5a5
build: cd workflow and and move to non-root image
rohsyl 73c6060
build: cd wip
rohsyl 04ea75d
build: cd wip
rohsyl fc8f078
build: cd wip
rohsyl 44f7016
build: cd wip
rohsyl 4a86ef0
build: cd wip
rohsyl 15d3605
build: cd wip
rohsyl ad1a97e
Merge branch 'main' into staging
rohsyl ce5752f
build: expose only necessary ports on prod
rohsyl c4a78a8
build: add missing allowed hosts
rohsyl 8af8c35
Merge branch 'main' into staging
rohsyl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,102 @@ | ||
| name: Build and Deploy | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| push: | ||
| branches: | ||
| - 'main' | ||
| - 'staging' | ||
| tags: | ||
| - 'v*' | ||
| pull_request: | ||
| branches: | ||
| - 'main' | ||
| - 'staging' | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| permissions: | ||
| contents: read | ||
| packages: write | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Log in to GitHub Container Registry | ||
| run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin | ||
|
|
||
| - name: Extract metadata for Docker | ||
| id: meta | ||
| uses: docker/metadata-action@v5 | ||
| with: | ||
| images: ghcr.io/${{ github.repository }} | ||
| tags: | | ||
| type=ref,event=branch | ||
| type=ref,event=pr | ||
| type=semver,pattern={{version}} | ||
| type=semver,pattern={{major}}.{{minor}} | ||
| type=raw,value=latest,enable={{is_default_branch}} | ||
|
|
||
| - name: Build and push | ||
| uses: docker/build-push-action@v6 | ||
| with: | ||
| context: . | ||
| file: ./docker/Dockerfile | ||
| target: 'prod' | ||
| push: ${{ github.event_name != 'pull_request' }} | ||
| tags: ${{ steps.meta.outputs.tags }} | ||
| labels: ${{ steps.meta.outputs.labels }} | ||
|
|
||
| deploy: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| packages: read | ||
| needs: build | ||
| strategy: | ||
| matrix: | ||
| include: | ||
| - environment: staging | ||
| branch: staging | ||
| target_path: "~/staging.mapdb.cncnet.org" | ||
| compose_file: "docker-compose.prod.yml" | ||
| nginx_conf: "docker/nginx.prod.conf" | ||
| # disabled for now | ||
| # - environment: production | ||
| # branch: main | ||
| # target_path: "~/prod2.mapdb.cncnet.org" | ||
| # compose_file: "docker-compose.prod.yml" | ||
| # nginx_conf: "docker/nginx.prod.conf" | ||
|
|
||
| steps: | ||
| - name: "Exit if not matching branch" | ||
| if: github.ref != format('refs/heads/{0}', matrix.branch) | ||
| run: echo "Not target branch for this deployment. Skipping..." && exit 0 | ||
|
|
||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Copy docker-compose and nginx config over ssh | ||
| uses: appleboy/[email protected] | ||
| with: | ||
| host: ${{ secrets.SSH_HOST }} | ||
| username: ${{ secrets.SSH_USER }} | ||
| key: ${{ secrets.SSH_PRIVATE_KEY }} | ||
| source: "${{ matrix.compose_file }},${{ matrix.nginx_conf }}" | ||
| target: "${{ matrix.target_path }}" | ||
|
|
||
| - name: SSH into server and deploy | ||
| uses: appleboy/[email protected] | ||
| with: | ||
| host: ${{ secrets.SSH_HOST }} | ||
| username: ${{ secrets.SSH_USER }} | ||
| key: ${{ secrets.SSH_PRIVATE_KEY }} | ||
| script: | | ||
| cd ${{ matrix.target_path }} | ||
| echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin | ||
| docker compose -f ${{ matrix.compose_file }} pull | ||
| docker compose -f ${{ matrix.compose_file }} down | ||
| docker compose -f ${{ matrix.compose_file }} up -d |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,34 @@ | ||
| user nginx; | ||
| worker_processes 4; | ||
| pid /var/run/nginx.pid; | ||
|
|
||
| events { | ||
| worker_connections 1024; | ||
| } | ||
|
|
||
| http { | ||
| server { | ||
| listen 80; | ||
|
|
||
| # Serve static files: js, static images, etc. | ||
| location /static/ { | ||
| alias /usr/share/nginx/html/static/; # The nginx container's mounted volume. | ||
| expires 30d; | ||
| add_header Cache-Control public; | ||
| } | ||
|
|
||
| # Serve user uploaded files | ||
| location /silo/ { | ||
| alias /usr/share/nginx/html/silo/; # The container's mounted volume. | ||
| } | ||
|
|
||
| # Proxy requests to the Django app running in gunicorn | ||
| location / { | ||
| proxy_pass http://django:8000; # The Django app is exposed on the `django` container on port 8000 | ||
| proxy_set_header Host $host; | ||
| proxy_set_header X-Real-IP $remote_addr; | ||
| proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
| proxy_set_header X-Forwarded-Proto $scheme; | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.