Skip to content

Commit

Permalink
Deploy to digital-ocean via its registry
Browse files Browse the repository at this point in the history
  • Loading branch information
acorello committed Oct 31, 2023
1 parent 57a1e68 commit baecf73
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 36 deletions.
29 changes: 8 additions & 21 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,13 @@ jobs:
OUT_DIR: ${{ github.workspace }}/_OUTPUT
runs-on: ubuntu-22.04
steps:
- name: Checkoug
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go toolchain
uses: actions/setup-go@v4
- name: Docker Registry Login
uses: docker/login-action@v3
with:
go-version-file: 'go.mod'
- name: Make
run: make build.all
- name: Create Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
_opstools/octoact_create_release \
-repo-owner ${{ github.repository_owner }} \
-repo Contacts.app \
-release-name "Release ${{ github.ref_type }} ${{ github.ref_name }}" \
-assets-dir ${{ env.OUT_DIR }}
- name: Upload Artefact
uses: actions/upload-artifact@v3
with:
if-no-files-found: error
name: release_files
path: ${{ env.OUT_DIR }}
registry: 'registry.digitalocean.com'
username: ${{ secrets.DIGITALOCEAN_TOKEN }}
password: ${{ secrets.DIGITALOCEAN_TOKEN }}
- name: Build
run: make deployed
28 changes: 17 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
OUT_DIR?=_tmp/built
ARTEFACT_NAME?=contacts-app

$(OUT_DIR):
@mkdir -p $(OUT_DIR)
ARTEFACT_PATH?=contacts-app
IMAGE_NAME=contacts-app
IMAGE_TAGGED_NAME=contacts-app:latest
CONTAINER_REGISTRY=registry.digitalocean.com/acorello
IMAGE_REPOSITORY_TAGGED_NAME=$(CONTAINER_REGISTRY)/$(IMAGE_TAGGED_NAME)

.PHONY: executable
executable: ARTEFACT_PATH=$(OUT_DIR)/$(ARTEFACT_NAME)
executable: $(OUT_DIR)
executable:
@echo "Building" $(ARTEFACT_PATH)
@go build -trimpath -o $(ARTEFACT_PATH)

.PHONY: docker.image
docker.image:
@echo "Building docker image: " $(ARTEFACT_PATH)
@docker build --tag $(ARTEFACT_NAME) --file _docker/Dockerfile .
.PHONY: container.image
container.image:
@echo "Building image: " $(IMAGE_NAME)
@docker build \
--tag $(IMAGE_TAGGED_NAME) \
--tag $(IMAGE_REPOSITORY_TAGGED_NAME) \
--file _docker/Dockerfile .

.PHONY: deployed
deployed: container.image
@docker push $(IMAGE_REPOSITORY_TAGGED_NAME)
7 changes: 3 additions & 4 deletions _docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ WORKDIR /home
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN ARTEFACT_NAME=contacts.app OUT_DIR=/home make executable
RUN make executable ARTEFACT_PATH=/home/app

FROM alpine:3
WORKDIR /home
COPY --from=builder /home/contacts.app .
COPY --from=builder /home/app /home/app
EXPOSE 8080
ENTRYPOINT [ "/home/contacts.app" ]
ENTRYPOINT [ "/home/app" ]

0 comments on commit baecf73

Please sign in to comment.