-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
21 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,10 +1,19 @@ | ||
--- | ||
name: CI/CD | ||
|
||
permissions: | ||
packages: write | ||
contents: write | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
|
||
env: | ||
ECR_REGISTRY: ${{ secrets.ECR_REGISTRY }} | ||
ECR_REPOSITORY: ${{ github.event.repository.name }} | ||
IMAGE_TAG: ${{ github.sha }} | ||
|
||
jobs: | ||
lint: | ||
name: Linting | ||
|
@@ -37,20 +46,24 @@ jobs: | |
|
||
- name: Build, tag, and push image to Amazon ECR | ||
id: build-image | ||
env: | ||
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | ||
ECR_REPOSITORY: ${{ github.event.repository.name }} | ||
IMAGE_TAG: ${{ github.sha }} | ||
run: | | ||
docker build --target prod --tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . | ||
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | ||
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_ENV | ||
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT | ||
deploy_to_server: | ||
name: Deploy to EC2 | ||
needs: push_to_registry | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Create .env files with secrets | ||
run: | | ||
echo "${{ secrets.ENV_FILE_LAVALINK }}">> application.env | ||
echo "${{ secrets.ENV_FILE_BOT }}">> bot.env | ||
echo "IMAGE=${{ env.image }}">> .env | ||
echo "IMAGE=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG">> .env | ||
- name: SCP docker compose and lavalink config to server | ||
uses: appleboy/[email protected] | ||
|
@@ -65,12 +78,12 @@ jobs: | |
|
||
- name: SSH into EC2 instance and deploy | ||
uses: appleboy/[email protected] | ||
with: | ||
env: | ||
host: ${{ secrets.EC2_HOST }} | ||
username: ${{ secrets.EC2_USERNAME }} | ||
key: ${{ secrets.EC2_SSH_KEY }} | ||
script: | | ||
aws ecr get-login-password | docker login -u ${{ secrets.EC2_USERNAME }} --password-stdin 730519783440.dkr.ecr.eu-central-1.amazonaws.com | ||
aws ecr get-login-password | docker login -u $username --password-stdin $ECR_REGISTRY | ||
cd ~/.deploy/djs/ | ||
docker compose -f compose-prod-aws.yml pull | ||
docker compose -f compose-prod-aws.yml up -d |