diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..ecaf119 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,21 @@ +name: build + +on: + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + service: [api, bot, nginx] + steps: + - name: Checkout code + uses: actions/checkout@v6 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v4 + - name: Build ${{ matrix.service }} image + uses: docker/build-push-action@v6 + with: + context: ./server/${{ matrix.service }} + push: false diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml new file mode 100644 index 0000000..0496113 --- /dev/null +++ b/.github/workflows/deploy.yaml @@ -0,0 +1,88 @@ +name: deploy + +on: + push: + branches: [main] + +jobs: + to-docker-hub: + runs-on: ubuntu-latest + strategy: + matrix: + instance: [api, nginx, bot] + steps: + - name: Checkout code + uses: actions/checkout@v6 + - name: Login to Docker Hub + uses: docker/login-action@v4 + with: + username: grachevnr + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v4 + - name: Build and push + uses: docker/build-push-action@v7 + with: + context: "server/${{ matrix.instance }}" + push: true + tags: "grachevnr/eat_log_${{ matrix.instance }}:latest" + + to-server: + needs: to-docker-hub + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v6 + - name: Poweroff old services + uses: appleboy/ssh-action@v1 + with: + host: ${{ secrets.SERVER_HOST }} + username: ${{ secrets.SERVER_USERNAME }} + password: ${{ secrets.SERVER_PASSWORD }} + script: | + mkdir -p ~/eatlog + cd ~/eatlog + docker compose down || true + - name: Copy docker-compose to server + uses: appleboy/scp-action@v1 + with: + host: ${{ secrets.SERVER_HOST }} + username: ${{ secrets.SERVER_USERNAME }} + password: ${{ secrets.SERVER_PASSWORD }} + source: "./server/docker-compose.yaml" + target: "~/eatlog/" + strip_components: 1 + - name: Create .env on server + uses: appleboy/ssh-action@v1 + env: + DB_HOST: ${{ secrets.DB_HOST }} + DB_PORT: ${{ secrets.DB_PORT }} + DB_NAME: ${{ secrets.DB_NAME }} + DB_USER: ${{ secrets.DB_USER }} + DB_PASSWORD: ${{ secrets.DB_PASSWORD }} + BOT_TOKEN: ${{ secrets.BOT_TOKEN }} + with: + host: ${{ secrets.SERVER_HOST }} + username: ${{ secrets.SERVER_USERNAME }} + password: ${{ secrets.SERVER_PASSWORD }} + envs: DB_HOST,DB_PORT,DB_NAME,DB_USER,DB_PASSWORD,BOT_TOKEN + script: | + cat > ~/eatlog/.env <