diff --git a/.github/workflows/push-docker-image.yml b/.github/workflows/push-docker-image.yml new file mode 100644 index 0000000..2c2b0c6 --- /dev/null +++ b/.github/workflows/push-docker-image.yml @@ -0,0 +1,41 @@ +name: Build and Push Docker Image + +on: + push: + tags: + - '*' + +jobs: + build-and-push: + runs-on: ubuntu-latest + + steps: + + - name: Checkout code + uses: actions/checkout@v3 + # Setup qemu to generate both arm and x86 images + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + # Setup build + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + platforms: linux/amd64, linux/arm64, darwin/amd64 + context: . + push: true + cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/${{ github.repository }}:cache + cache-to: type=inline + tags: | + ghcr.io/${{ github.repository_owner }}/${{ github.repository }}:${{ github.sha }} + ghcr.io/${{ github.repository_owner }}/${{ github.repository }}:latest diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b1e2aea --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +# Data generated by Postgres +/.pgdata + +# Your secrets +.env \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..05540da --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM golang:1.21.3 + + +WORKDIR /app +COPY go.mod go.sum ./ +RUN go mod download +COPY *.go ./ + +RUN CGO_ENABLED=0 GOOS=linux go build -o /blood-for-life-api + +CMD ["/blood-for-life-api"] \ No newline at end of file diff --git a/README.md b/README.md index bd96744..0709548 100644 --- a/README.md +++ b/README.md @@ -1 +1,9 @@ -# Blood-For-Life-Management-Backend \ No newline at end of file +# Blood-For-Life-Management-Backend + +### Running application locally +- Create `.env` file that contains following variables: + - POSTGRES_USER + - POSTGRES_PASSWORD +- Run `docker build -t ghcr.io/ubcsss/blood-for-life-api ./` +- Run `docker-compose up` + diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..217b4b2 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,15 @@ +version: '3' +services: + app: + image: ghcr.io/ubccsss/blood-for-life-api + ports: + - 1323:1323 + db: + image: postgres:16.2 + ports: + - 5432:5432 + volumes: + - ./.pgdata:/var/lib/postgresql/data + environment: + - POSTGRES_USER=${POSTGRES_USER} + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}