diff --git a/.container/Containerfile b/.container/Containerfile new file mode 100644 index 0000000..0218397 --- /dev/null +++ b/.container/Containerfile @@ -0,0 +1,16 @@ +# Compilation +FROM docker.io/library/golang:1.20.6-alpine as build +WORKDIR /app + +COPY . . + +RUN go build -ldflags "-s -w" package-search-api.go + +# Runtime +FROM docker.io/library/debian:bullseye-slim + +## Get binary +COPY --from=build /app/package-search-api /usr/local/bin/package-search-api + +## Start the app +CMD ["package-search-api"] diff --git a/.github/workflows/container.yml b/.github/workflows/container.yml new file mode 100644 index 0000000..340eb72 --- /dev/null +++ b/.github/workflows/container.yml @@ -0,0 +1,22 @@ +name: container image +on: push + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + container-job: + timeout-minutes: 30 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Build the container image + run: docker build --no-cache -t ozkanonur/package-search-api:latest -f .container/Containerfile . + + - name: Push the container image + if: github.event_name != 'pull_request' && github.ref == 'refs/heads/stable' + run: | + docker login --username ${{ secrets.DOCKER_HUB_USERNAME }} --password ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} docker.io + docker push ozkanonur/package-search-api:latest diff --git a/.gitignore b/.gitignore index f9d2f3b..52b76d5 100644 --- a/.gitignore +++ b/.gitignore @@ -21,4 +21,4 @@ go.work # binary -package_search_api \ No newline at end of file +package-search-api \ No newline at end of file