Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 1 addition & 30 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI/CD
name: CI

on:
push:
Expand All @@ -9,35 +9,6 @@ on:
- main

jobs:
build:
name: Build and Push to GHCR
runs-on: ubuntu-latest

needs: test
steps:
- name: Check out code
uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '1.23'

- name: Build Docker Image
run: |
git fetch --unshallow --tags
BUILDTIME=$(date -R)
docker build --build-arg VERSION=$(git describe --tags --always) --build-arg BUILDTIME='$BUILDTIME' . -f build/Dockerfile -t ghcr.io/${{ github.repository }}:latest

- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Push Docker Image
run: docker push ghcr.io/${{ github.repository }}:latest
check-dependencies:
name: Check dependencies with nancy
runs-on: ubuntu-latest
Expand Down
70 changes: 70 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: CD

on:
push:
# branches:
# - main
pull_request:
# branches:
# - main
workflow_dispatch: # Позволяет запустить workflow вручную через интерфейс GitHub

jobs:
build:
name: Build and Push to GHCR
runs-on: ubuntu-latest

# needs: test
steps:
- name: Check out code
uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '1.23'

- name: Build Docker Image
run: |
git fetch --unshallow --tags
BUILDTIME=$(date -R)
docker build --build-arg VERSION=$(git describe --tags --always) --build-arg BUILDTIME='$BUILDTIME' . -f build/Dockerfile -t ghcr.io/${{ github.repository }}:latest

- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Push Docker Image
run: docker push ghcr.io/${{ github.repository }}:latest

deploy:
name: Deploy to Staging
runs-on: ubuntu-latest
needs: build
steps:
- name: Check out code
uses: actions/checkout@v3

- name: Start SSH Agent and Add Key
uses: webfactory/ssh-agent@v0.5.4
with:
ssh-private-key: ${{ secrets.STAGE_SSH_KEY }}

- name: Install SSH Known Hosts
run: ssh-keyscan -H ctf01d.ru >> ~/.ssh/known_hosts

- name: Deploy Docker Compose to Staging
run: |
scp build/docker-compose.staging.yml root@ctf01d.ru:/root/ctf01d-training-platform/build
scp build/docker-compose.yml root@ctf01d.ru:/root/ctf01d-training-platform/build
ssh root@ctf01d.ru "docker login ghcr.io -u '${{ secrets.GHCR_USERNAME }}' -p '${{ secrets.GHCR_TOKEN }}' && docker compose -f docker-compose.yml -f docker-compose.stage.yml pull && docker compose -f docker-compose.yml -f docker-compose.stage.yml stop && docker compose -f docker-compose.yml -f docker-compose.stage.yml up -d"
env:
GHCR_USERNAME: ${{ secrets.GHCR_USERNAME }}
GHCR_TOKEN: ${{ secrets.GHCR_TOKEN }}

environment:
name: staging
url: http://ctf01d.ru
Loading