formatting for README.md #23
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
name: Backend_Build_Pipeline | |
on: | |
# on: [push] works too | |
push: | |
branches: master | |
jobs: | |
# this is the name | |
build_and_push: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: "1.20" | |
- name: Install dependencies | |
run: | | |
cd backend | |
go get -v -t ./... | |
- name: Build | |
run: | | |
cd backend | |
go build -v ./... | |
- name: Test | |
run: | | |
cd backend | |
go test -v ./... | |
# not sure why google says to cat .env? | |
- name: Create .env file | |
run: | | |
cd backend | |
touch .env | |
echo "PSQL_CONN=${{ secrets.PSQL_CONN }}" >> .env | |
echo "JWT_KEY=${{secrets.JWT_KEY}}" >> .env | |
echo "SERVER_PORT=:8080" >> .env | |
- name: Login to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Build and push Docker | |
uses: docker/build-push-action@v4 | |
with: | |
context: ./backend | |
file: ./backend/Dockerfile | |
push: true | |
tags: ${{ secrets.DOCKERHUB_USERNAME }}/orbitalbackend:latest | |
secrets: | | |
"PSQL_CONN=${{ secrets.PSQL_CONN }}" | |
#### this wont work because of VPC Security Group issue since GH Actions has too many IP addresses | |
#### https://kamrul.dev/dynamically-add-github-actions-ip-to-aws-security-group/ | |
#### go figure out IAM to dynamically add IP to allow | |
#### use Github runners to pull | |
# Deploy: | |
# needs: build_and_push | |
# runs-on: ubuntu-latest | |
# steps: | |
# - uses: actions/checkout@v2 | |
# - name: Deploy in EC2 | |
# env: | |
# PRIVATE_KEY: ${{ secrets.AWS_PRIVATE_KEY }} | |
# HOSTNAME: ${{ secrets.EC2_USER_HOSTNAME }} | |
# run: | | |
# echo "$PRIVATE_KEY" > private_key && chmod 600 private_key | |
# ssh -o StrictHostKeyChecking=no -i private_key $HOSTNAME ' | |
# sudo docker login | |
# sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/orbitalbackend:latest | |
# sudo docker run -d -p 80:8080 orbitalbackend:latest | |
# ' |